Skip to main content

duckdb-assistant: Generate & Execute DuckDB SQL

This repository provides a Python class and associated methods to generate and execute DuckDB SQL.

DuckDB is an open-source, low-footprint, in-process query processing engine which provides access to several data stores and structures like Parquet, CSV, JSON and data located in conventional Relational Database Management Systems (RDBMS). This package uses the duckdb Python package along with methods to call a Large Language Model (LLM) from Google Gemini to generate code in a convenient and conversational manner.

A wiki of this repo has been generated using DeepWiki and is available here: Ask DeepWiki

Refer this doc for more details on how this project will evolve.

Installation

  1. Clone this repository
  2. To install locally in editable mode, refer here

Run the following command for a pip installation of the package from PyPi.

[!WARNING] This package is not yet registered on PyPi. The following command shall be valid once it's made available.

pip install --upgrade duckdb-assistant

Usage - quick example

To initialise the DuckDBAssistant class:

from duckdb_assistant import DuckDBAssistant

dda = DuckDBAssistant()

Then, to generate a query in natural language,

duckdb_query = dda.generate("Create an empty customer table.")
print(duckdb_query)

Result:

>>> duckdb_query = dda.generate("Create an empty customer table.")
>>> print(duckdb_query)
CREATE TABLE IF NOT EXISTS customer (
    customer_id INTEGER PRIMARY KEY,
    first_name VARCHAR,
    last_name VARCHAR,
    email VARCHAR,
    phone VARCHAR,
    address VARCHAR,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

Then, you execute the generated query either through a DuckDB connection or through the inbuilt duckdb Python connection object as follows:

dda.dd.execute(duckdb_query)

which is another way of running

import duckdb as dd
dd.execute(duckdb_query)

Or, you can choose to call the execute and sql methods available with the class that directly call duckdb's execute and sql methods after generation.

dda.execute("Create an empty customer table.")

dda.sql("Print Hello World through SQL")

Result:

>>> dda.execute("Create an empty customer table.")
<_duckdb.DuckDBPyConnection object at 0x10c194af0>
>>> 
>>> dda.sql("Print Hello World through SQL")
┌───────────────┐
│ 'Hello World' │
│    varchar    │
├───────────────┤
│ Hello World   │
└───────────────┘

>>> 

Documentation

Refer this page for a list of all available methods and attributes.

Generative AI usage

Core functions (described in Documentation) use Large Language Models (LLM, starting with Gemini 3.6 Flash) from the Google Gemini family. While you are free to modify the code to accommodate other LLMs, these are at present the only LLMs supported. Read this important note regarding functions that make use of Generative AI.

IMPORTANT: All outputs returned from Generative AI tools such as LLMs should be carefully reviewed prior to actual use. Quality of Generative AI outputs are determined by the Large Language Model in use and may be incorrect. Always review the same.

Add the following environmental variable to a .env file supplying variables to your environment. Get your Gemini API key from Google AI Studio.

GEMINI_API_KEY = <your_key>

An example env file (sample.env) is provided for this purpose. Rename this to .env and use.

Convenience: tasks.json

This repository contains a tasks.json meant for use in Visual Studio Code which helps clean up temporary files and stands up a virtual environment for quick development and exploration. Remove this file if you do not want to have Visual Studio Code run the tasks in tasks.json.

Change Log

  • Version: 0.0.1 (30JUL2026)
    • Initial push to GitHub

Refer CHANGELOG.md for other changes.

Contact

Download files

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

Source Distribution

duckdb_assistant-0.0.1.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

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

duckdb_assistant-0.0.1-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file duckdb_assistant-0.0.1.tar.gz.

File metadata

  • Download URL: duckdb_assistant-0.0.1.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.5

File hashes

Hashes for duckdb_assistant-0.0.1.tar.gz
Algorithm Hash digest
SHA256 28becf566d0ae99556fcd4cf855fb16b0220bc155e2d0713f1afef463832a65f
MD5 c6c6800b54fe6e243557aead0dd9f7f3
BLAKE2b-256 aaf5de683e014cc0dee118caa6ff793fd48bdd3dab3d3103120962d260247ae3

See more details on using hashes here.

File details

Details for the file duckdb_assistant-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for duckdb_assistant-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1707128a9db98fcc1a1329874470a4108ba00a19a041136e5ff01e207d95593e
MD5 05453089e711daefc3498a2118754233
BLAKE2b-256 a42b2302807e1ff3af8900f3b094913ebde6eddadc53373d7abb472d26a78837

See more details on using hashes here.

Supported by

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