Guides
Library Import and Configuration
Open a Jupyter Notebook and import the relevant libraries.  
#### Connecting to DuckDB Natively {#docs:guides:python:jupyter::connecting-to-duckdb-natively}  
To connect to DuckDB, run:  
```python
import duckdb
import pandas as pd

%load_ext sql
conn = duckdb.connect()
%sql conn --alias duckdb
```  
#### Connecting to DuckDB via SQLAlchemy Using `duckdb_engine` {#docs:guides:python:jupyter::connecting-to-duckdb-via-sqlalchemy-using-duckdb_engine}  
Alternatively, you can connect to DuckDB via SQLAlchemy using `duckdb_engine`. See the [performance and feature differences](https://jupysql.ploomber.io/en/latest/tutorials/duckdb-native-sqlalchemy.html).  
```python
import duckdb
import pandas as pd
# No need to import duckdb_engine
#  jupysql will auto-detect the driver needed based on the connection string!

# Import jupysql Jupyter extension to create SQL cells
%load_ext sql
```  
Set configurations on jupysql to directly output data to Pandas and to simplify the output that is printed to the notebook.  
```python
%config SqlMagic.autopandas = True
%config SqlMagic.feedback = False
%config SqlMagic.displaycon = False
```  
Connect jupysql to DuckDB using a SQLAlchemy-style connection string.
Either connect to a new [in-memory DuckDB](#docs:api:python:dbapi::in-memory-connection), the [default connection](#docs:api:python:dbapi::default-connection) or a file backed database:  
```sql
%sql duckdb:///:memory:
```  
```sql
%sql duckdb:///:default:
```  
```sql
%sql duckdb:///path/to/file.db
```  
> The `%sql` command and `duckdb.sql` share the same [default connection](#docs:api:python:dbapi) if you provide `duckdb:///:default:` as the SQLAlchemy connection string.