Quack Kernels for Jupyter
quack-kernels provides Jupyter Kernels for DuckDB, enabling users to interact with DuckDB databases directly from Jupyter notebooks using either SQL or Python. It currently stands at version 0.3.9 and is actively maintained with releases tied to DuckDB and Jupyter ecosystem updates.
Warnings
- gotcha DuckDB version compatibility: `quack-kernels` is closely tied to specific `duckdb` versions. Ensure your `duckdb` installation is compatible with the `quack-kernels` version to avoid unexpected behavior or errors.
- gotcha Kernel not appearing in Jupyter: After installation, if the 'DuckDB SQL' or 'DuckDB Python' kernels do not appear in Jupyter, the kernelspecs might not have been installed correctly.
- gotcha In-memory database persistence: When using `duckdb.connect(':memory:')`, the database and all its data are lost if the kernel is restarted or the notebook session ends. This is a common pitfall for data analysis.
- gotcha Misunderstanding kernel purpose (SQL vs. Python): Users sometimes try to run Python code in the 'DuckDB SQL' kernel or raw SQL in the 'DuckDB Python' kernel without magic commands.
Install
-
pip install quack-kernels
Imports
- DuckDBSQLKernel
from quack_kernels.duckdb_sql import DuckDBSQLKernel
- DuckDBPythonKernel
from quack_kernels.duckdb_python import DuckDBPythonKernel
Quickstart
import duckdb
import pandas as pd
# This code runs within a Jupyter notebook using the 'DuckDB Python' kernel.
# The 'quack-kernels' library provides the infrastructure for this.
# Connect to an in-memory DuckDB database
con = duckdb.connect(database=':memory:', read_only=False)
# Create a table and insert data using SQL
con.execute("CREATE TABLE my_data (id INTEGER, name VARCHAR);")
con.execute("INSERT INTO my_data VALUES (1, 'Alice'), (2, 'Bob'), (3, 'Charlie');")
# Query the table and fetch results into a pandas DataFrame
result_df = con.execute("SELECT * FROM my_data WHERE id > 1;").fetchdf()
print("Fetched data from DuckDB (as pandas DataFrame):")
print(result_df)
# Close the connection (important for file-based DBs, optional for :memory:)
con.close()