Client APIs
Connection Options
Applications can open a new DuckDB connection via the `duckdb.connect()` method.  
#### Using an In-Memory Database {#docs:api:python:overview::using-an-in-memory-database}  
When using DuckDB through `duckdb.sql()`, it operates on an **in-memory** database, i.e., no tables are persisted on disk.
Invoking the `duckdb.connect()` method without arguments returns a connection, which also uses an in-memory database:  
```python
import duckdb

con = duckdb.connect()
con.sql("SELECT 42 AS x").show()
```  
#### Persistent Storage {#docs:api:python:overview::persistent-storage}  
The `duckdb.connect(dbname)` creates a connection to a **persistent** database.
Any data written to that connection will be persisted, and can be reloaded by reconnecting to the same file, both from Python and from other DuckDB clients.  
```python
import duckdb

# create a connection to a file called 'file.db'
con = duckdb.connect("file.db")
# create a table and load data into it
con.sql("CREATE TABLE test (i INTEGER)")
con.sql("INSERT INTO test VALUES (42)")
# query the table
con.table("test").show()
# explicitly close the connection
con.close()
# Note: connections also closed implicitly when they go out of scope
```  
You can also use a context manager to ensure that the connection is closed:  
```python
import duckdb

with duckdb.connect("file.db") as con:
con.sql("CREATE TABLE test (i INTEGER)")
con.sql("INSERT INTO test VALUES (42)")
con.table("test").show()
# the context manager closes the connection automatically
```  
#### Configuration {#docs:api:python:overview::configuration}  
The `duckdb.connect()` accepts a `config` dictionary, where [configuration options](#docs:configuration:overview::configuration-reference) can be specified. For example:  
```python
import duckdb

con = duckdb.connect(config = {'threads': 1})
```  
#### Connection Object and Module {#docs:api:python:overview::connection-object-and-module}  
The connection object and the `duckdb` module can be used interchangeably – they support the same methods. The only difference is that when using the `duckdb` module a global in-memory database is used.  
> If you are developing a package designed for others to use, and use DuckDB in the package, it is recommend that you create connection objects instead of using the methods on the `duckdb` module. That is because the `duckdb` module uses a shared global database – which can cause hard to debug issues if used from within multiple different packages.  
#### Using Connections in Parallel Python Programs {#docs:api:python:overview::using-connections-in-parallel-python-programs}  
The `DuckDBPyConnection` object is not thread-safe. If you would like to write to the same database from multiple threads, create a cursor for each thread with the [`DuckDBPyConnection.cursor()` method](#docs:api:python:reference:index::duckdb.DuckDBPyConnection.cursor).