Skip to main content

Minimal Cython-based DuckDB Bindings

Project description

bareduckdb

Simplified, Dynamically Linked DuckDB Python Bindings — Fast, simple, and free-threaded.

Python 3.12+ License: MIT


Overview

bareduckdb provides extensible and easy to build Python bindings to DuckDB using Cython.

  • Simple ~4k lines of code - easy to extend or customize
  • Arrow-first data conversion supporting Polars, PyArrow, and Pandas
  • Support for latest Python features Free threading, subinterpreters, and asyncio
  • Dynamically linked to DuckDB's official library

Installation

From PyPI

pip install bareduckdb

From Source

git clone --recurse-submodules https://github.com/paultiq/bareduckdb.git
cd bareduckdb
uv sync -v # or: pip install -e .

Basic Usage

import bareduckdb

# Connect to in-memory database
conn = bareduckdb.connect()

# Execute query and get Arrow Table
result = conn.execute("SELECT 42 as answer").arrow_table()
print(result)

# Convert to Polars/Pandas/PyArrow
df_polars = conn.execute("SELECT * FROM range(100)").pl()
df_pandas = conn.execute("SELECT * FROM range(100)").df()

Async API

import asyncio
from bareduckdb.aio import connect_async

async def run_query():
    async with await connect_async() as conn:
        result = await conn.execute("SELECT * FROM generate_series(1, 1000)")
        return result

result = asyncio.run(run_query())

Polars Integration

import bareduckdb
import polars as pl

conn = bareduckdb.connect()

# Polars -> DuckDB (Arrow Capsule protocol)
df = pl.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
conn.register("my_table", df)

# DuckDB -> Polars (direct conversion)
result = conn.execute("SELECT * FROM my_table", output_type="polars")

Architecture

Design Principles

  1. Keep it in Python — Business logic lives in Python, not Cython/C++
  2. No GIL interaction from DuckDB threads — All Python operations happen before/after query execution
  3. Semantic Versioning — Strict stability guarantees
  4. Arrow-first — All data types map through Arrow's type system

Why Arrow-First?

By forcing all conversions through Arrow, bareduckdb achieves:

  • Consistent type mappings across Polars/Pandas/PyArrow
  • Reduced code complexity (no per-library conversion paths)
  • Better memory efficiency (zero-copy where possible)
  • Future-proof (Arrow is the lingua franca for columnar data)

Thread Safety & Free-Threading

Free-threading support (Python 3.13+):

  • No global locks in critical paths
  • DuckDB threads never acquire the GIL
  • Safe concurrent query execution in --disable-gil mode
  • Atomic operations for Arrow stream coordination

APIs

bareduckdb provides multiple API layers for different use cases:

1. Core API (bareduckdb.core)

Minimal, no-frills interface for maximum performance.

from bareduckdb.core import Connection
conn = Connection()
result = conn.execute("SELECT 1")

2. Async API (bareduckdb.aio)

Non-blocking operations with async/await.

from bareduckdb.aio import connect_async
conn = await connect_async()
result = await conn.execute("SELECT 1")

3. Compatibility API (bareduckdb.compat)

Familiar interface similar to duckdb-python (with intentional differences).

import bareduckdb
conn = bareduckdb.connect()
result = conn.sql("SELECT 1")  # Eager execution

4. DBAPI 2.0 (bareduckdb.dbapi)

Standard Python database interface for compatibility with tools like SQLAlchemy.

from bareduckdb.dbapi import connect
conn = connect()
cursor = conn.cursor()
cursor.execute("SELECT 1")

Key Differences

Not (Yet?) Supported

  • No lazy DuckDBPyRelation objects
  • No Python UDFs
  • No automatic DataFrame registration (use .register() explicitly)
  • Added Inline Registration: .execute("....query...", data={"name": df})
  • No fsspec integration

Arrow Enhancements

<TBD: Document>

  • Capsule vs Table registration
  • Deadlock detection
  • Cardinality & TopN
  • C++ implementation of Arrow Pushdown

Type Mappings

All types convert through Arrow:

  • UUIDs: Returned as strings (Arrow doesn't have native UUID type)
  • Decimals: Arrow Decimal128/Decimal256
  • Timestamps: Arrow Timestamp with timezone preservation
  • Nested Types: Struct/List/Map fully supported

Development

Building from Source

# Clone with submodules (sparse checkout is automatic)
git clone --recurse-submodules https://github.com/paultiq/bareduckdb.git
cd bareduckdb

# Install development dependencies
uv sync

# Build in development mode
pip install -e .

* Note 1: DuckDB submodule version must match the library version. * Note 2: PyArrow version must match the runtime version for Table registration / Pushdown

Disclaimer

For official Python bindings, see: https://github.com/duckdb/duckdb-python

License

bareduckdb is licensed under the MIT License. See LICENSE for details.

All original copyrights are retained by their respective owners, including DuckDB and DuckDB-Python

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

bareduckdb-0.2.142-cp314-cp314t-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl (31.3 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.26+ x86-64manylinux: glibc 2.28+ x86-64

bareduckdb-0.2.142-cp314-cp314t-macosx_11_0_arm64.whl (34.5 MB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

bareduckdb-0.2.142-cp312-abi3-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl (31.2 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.26+ x86-64manylinux: glibc 2.28+ x86-64

bareduckdb-0.2.142-cp312-abi3-macosx_11_0_arm64.whl (34.4 MB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

File details

Details for the file bareduckdb-0.2.142-cp314-cp314t-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for bareduckdb-0.2.142-cp314-cp314t-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ac9cd4d270d20a07cb2c3577a4d49540012f81e9b5d3151dea4903a6fb2db40f
MD5 07e816679f780df3715dcc80cdd1362f
BLAKE2b-256 6f35982ada0d88e0de4a484fab7c8b918d17c97f1c5892eb7b08473c37f25f86

See more details on using hashes here.

Provenance

The following attestation bundles were made for bareduckdb-0.2.142-cp314-cp314t-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build_wheels.yml on iqmo-org/bareduckdb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bareduckdb-0.2.142-cp314-cp314t-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for bareduckdb-0.2.142-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a1d8597bf310bb26fad04f5da8b71cf26d1132fb6afefac88798f45a1aee384e
MD5 eff15cc267e303c17675ceef491121ca
BLAKE2b-256 ccb6a074afdf33cc1592d12230f518e05c1c0a72373b30a875054802f15dfc45

See more details on using hashes here.

Provenance

The following attestation bundles were made for bareduckdb-0.2.142-cp314-cp314t-macosx_11_0_arm64.whl:

Publisher: build_wheels.yml on iqmo-org/bareduckdb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bareduckdb-0.2.142-cp312-abi3-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for bareduckdb-0.2.142-cp312-abi3-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 739b6ab7e8231eef1dc1fe367f13f092d5644f0d91f427018f62ac91a09d3501
MD5 ef4afc4b6fc8b43e965b7f414c9b575e
BLAKE2b-256 45d0dd8db4d8f8013b8cdab06542d7dd6735db03ecf09e67e13af5c4feece76a

See more details on using hashes here.

Provenance

The following attestation bundles were made for bareduckdb-0.2.142-cp312-abi3-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build_wheels.yml on iqmo-org/bareduckdb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bareduckdb-0.2.142-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for bareduckdb-0.2.142-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4d1e1e2366570a48244b621bbca29e87d44c0af6ea4ef5667d683ab5b91ca738
MD5 2837ebeec9866983242123aa68afde97
BLAKE2b-256 e5bea30f02269e5cdcb38acf993577488f706f145f55cd1bea331e31d7fac2eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for bareduckdb-0.2.142-cp312-abi3-macosx_11_0_arm64.whl:

Publisher: build_wheels.yml on iqmo-org/bareduckdb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page