Skip to main content

quacklab Python adapter

The quacklab Python adapter integrates quacklab into the DuckDB Python package. quacklab is a research project to integrate optimizer hints into DuckDB. These hints overwrite optimizer decisions like the join order or cardinality estimates:

import quacklab
db = quacklab.connect("imdb.duckdb")
hints = "/*=quack_lab= card(t #42) card(mi #24) */"  # this comment will be embedded in the SQL query
db.sql(f"explain {hints} select count(*) from title t join movie_info mi on t.id = mi.movie_id where t.production_year < 2010")

Repo Layout

The quacklab-patches branch is used to track our changes to upstream DuckDB. It should not be used directly. For the DuckDB versions that we support, dedicated quacklab-[DuckDB release] branches exist, such as quacklab-v1.4-andium. These branches are used to apply our quacklab patches to the specific DuckDB release. Use these branches to build quacklab.

Installation

See the quacklab repository for information on the required software to compile quacklab. In addition to these requirements, the DuckDB Python adapter also needs uv to build the Python package. For quacklab we adhere to the standard build process as far as possible.

The TLDR is

git clone --recurse-submodules https://github.com/rbergm/quacklab-python.git
cd quacklab-python
git fetch --tags
git switch quacklab-v1.5-variegata
cd external/duckdb && git fetch --tags
cd third_party/antlr4
java -jar antlr-4.13.2-complete.jar -Dlanguage=Cpp ../../src/hinting/grammar/HintBlock.g4
cd ../../../..
uv build

Or to explain the individual steps:

  1. Initialize the quacklab submodule: git submodule update --init --recursive (or clone with --recurse-submodules)
  2. Make sure you have tags available in the repository: git fetch --tags. Tags are used for versioning by the DuckDB build process.
  3. Select the package version you want to build by checking out the corresponding branch, e.g., git switch quacklab-v1.4-andium
  4. Make sure you have tags available in the quacklab submodule: cd external/duckdb && git fetch --tags
  5. Currently, you need to manually generate the parser for the hinting grammar. Change into the following directory: external/duckdb/third_party/antlr4 and run the ANTLR generator: java -jar antlr-4.13.2-complete.jar -Dlanguage=Cpp ../../src/hinting/grammar/HintBlock.g4
  6. Back in the main directory, you can start the package build: uv build. This will automatically compile DuckDB/quacklab from source, so this process will take a while.
  7. Install the quacklab wheel into whatever Python environment you want, e.g. using pip install dist/quacklab-<suffix>.whl.

Usage

The Python adapter can be used like the standard DuckDB package. Queries that contain hints are automatically processed by quacklab. Refer to the official DuckDB documentation and quacklab documentation for details.

Release files for quacklab 1.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for quacklab 1.5.0
File Size Uploaded
quacklab-1.5.0.tar.gz 22.8 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for quacklab 1.5.0
File
quacklab-1.5.0-cp314-cp314-manylinux_2_39_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.39+ x86-64 Details
quacklab-1.5.0-cp314-cp314-macosx_26_0_arm64.whl CPython 3.14 CPython 3.14 macOS 26.0+ ARM64 Details
quacklab-1.5.0-cp313-cp313-manylinux_2_39_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.39+ x86-64 Details
quacklab-1.5.0-cp313-cp313-macosx_26_0_arm64.whl CPython 3.13 CPython 3.13 macOS 26.0+ ARM64 Details
quacklab-1.5.0-cp312-cp312-manylinux_2_39_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.39+ x86-64 Details
quacklab-1.5.0-cp312-cp312-macosx_26_0_arm64.whl CPython 3.12 CPython 3.12 macOS 26.0+ ARM64 Details

Total release size: 139.6 MB

Release files / quacklab-1.5.0.tar.gz

Download URL quacklab-1.5.0.tar.gz
Size 22.8 MB
Tags Source
SHA-256 checksum
How to use checksums
2c835bf2ec9ff77b85cf96272fba036501e0b9c7d260cd152ce32d1af348a3e3
BLAKE2b-256 checksum
How to use checksums
91b183a14f1dae1feb73c5405c1a7b1a412d4bc17d48d949c40a2564349e51f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / quacklab-1.5.0-cp314-cp314-manylinux_2_39_x86_64.whl

Download URL quacklab-1.5.0-cp314-cp314-manylinux_2_39_x86_64.whl
Size 22.3 MB
Tags CPython 3.14 Linux glibc 2.39+ x86-64
SHA-256 checksum
How to use checksums
964fc63b8ad47a6c01c072c9ca58df1744423f988b73d0f3c976aa5ee672b642
BLAKE2b-256 checksum
How to use checksums
9195707ed248ab083927f9fb04cb144df2f42d44857eebaf1797695400e833af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / quacklab-1.5.0-cp314-cp314-macosx_26_0_arm64.whl

Download URL quacklab-1.5.0-cp314-cp314-macosx_26_0_arm64.whl
Size 16.7 MB
Tags CPython 3.14 macOS 26.0+ ARM64
SHA-256 checksum
How to use checksums
e751db219f03d3661dd5c81c44f79d343e2ac19d718bdad6dc225ed42d6926be
BLAKE2b-256 checksum
How to use checksums
2739711d997eb05fd0f65af84bbfe95f2a1c9d6c2f965d5951bdfeaac0999e44
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / quacklab-1.5.0-cp313-cp313-manylinux_2_39_x86_64.whl

Download URL quacklab-1.5.0-cp313-cp313-manylinux_2_39_x86_64.whl
Size 22.3 MB
Tags CPython 3.13 Linux glibc 2.39+ x86-64
SHA-256 checksum
How to use checksums
cc111c3aa62f98419266833ea642a0f7e2441569448467912e983dab48364df7
BLAKE2b-256 checksum
How to use checksums
f196b1863935f24682fc399ad0e00670fd8ee5c3d6686080be88d252c8192a64
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / quacklab-1.5.0-cp313-cp313-macosx_26_0_arm64.whl

Download URL quacklab-1.5.0-cp313-cp313-macosx_26_0_arm64.whl
Size 16.7 MB
Tags CPython 3.13 macOS 26.0+ ARM64
SHA-256 checksum
How to use checksums
1a48b9219a82259d3bc59d5c265ac7dc4b03a8bb2e60f9432df73b13a92e405f
BLAKE2b-256 checksum
How to use checksums
7e366b3d48a05b5dd8427efb1f41a69197851ff592d299bce9fb4c57ef63d2b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / quacklab-1.5.0-cp312-cp312-manylinux_2_39_x86_64.whl

Download URL quacklab-1.5.0-cp312-cp312-manylinux_2_39_x86_64.whl
Size 22.3 MB
Tags CPython 3.12 Linux glibc 2.39+ x86-64
SHA-256 checksum
How to use checksums
bacb9f0d7c81518e307963a163fd4168673c220e11c5d2a58ef295ace1655a56
BLAKE2b-256 checksum
How to use checksums
1ba250e4fc961a398bddfa5ee1b87ab2b0dfe8f4169766bf2bae9a0f101af9a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / quacklab-1.5.0-cp312-cp312-macosx_26_0_arm64.whl

Download URL quacklab-1.5.0-cp312-cp312-macosx_26_0_arm64.whl
Size 16.7 MB
Tags CPython 3.12 macOS 26.0+ ARM64
SHA-256 checksum
How to use checksums
70ac47e1cdb4af356638c640f4d7698f494a8d62719ac9b0e7b5d86d210b2ae5
BLAKE2b-256 checksum
How to use checksums
6b0d3c0232ea9b3b0de9800e4fbbf847775d058f0bb9656ee9bfddd91726fe6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

1.5.0 This release

7 release files

1.4.2

7 release files

1.4.1

7 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page