DuckDB-Engine

0.17.0 · active · verified Fri Apr 10

duckdb-engine is an SQLAlchemy driver for DuckDB, a high-performance analytical in-process SQL database system. It enables Python applications to interact with DuckDB databases using SQLAlchemy's ORM and SQL Expression Language. Currently at `v0.17.0`, it receives frequent updates addressing bug fixes and introducing features like filesystem registration.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create an in-memory DuckDB database using `duckdb-engine` with SQLAlchemy, create a table, insert data, and query it.

from sqlalchemy import create_engine, text

# Connect to an in-memory DuckDB database
engine = create_engine("duckdb:///:memory:")

with engine.connect() as connection:
    # Execute a simple DDL statement
    connection.execute(text("CREATE TABLE users (id INTEGER, name VARCHAR)"))
    connection.commit()

    # Execute an INSERT statement
    connection.execute(text("INSERT INTO users (id, name) VALUES (:id, :name)"), {"id": 1, "name": "Alice"})
    connection.execute(text("INSERT INTO users (id, name) VALUES (:id, :name)"), {"id": 2, "name": "Bob"})
    connection.commit()

    # Execute a SELECT statement and fetch results
    result = connection.execute(text("SELECT id, name FROM users"))
    for row in result:
        print(f"ID: {row.id}, Name: {row.name}")

view raw JSON →