Originally posted: 2025-01-16. View source code for this page here.

Understanding DuckDB Connection Types in Python

DuckDB offers special connection types in Python:

  • :memory:name - Creates/connects to a named in-memory database that can be shared across connections
  • :default: - Uses the default connection stored in the DuckDB module

Example:

import duckdb
# Create table in default connection
duckdb.execute("CREATE TABLE tbl AS SELECT 42 as value")
# Access same table through explicit default connection
con = duckdb.connect(":default:")
con.sql("SELECT * FROM tbl") # Works!
# Shared named memory connection
con3 = duckdb.connect(":memory:shared_db")
con4 = duckdb.connect(":memory:shared_db") # Same database as con3

See docs here

16 Jan 2024
pythonduckdbdatabase

Configuring Python Path Visibility in VS Code interactive window (Jupyter)

When working with Jupyter notebooks in VS Code, add these settings to your .vscode/settings.json:

{
"jupyter.notebookFileRoot": "${workspaceFolder}",
"python.analysis.extraPaths": [
"${workspaceFolder}"
]
}

Now, the interactive window will run any script as if it's running from the root directory even if it's nested

16 Jan 2024
vscodejupytertips