Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

duckdb-utils: CLI tool and Python library for manipulating DuckDB databases

Github PyPI Documentation Status Linkedin Github Sponsors pip installs Tests codecov License

CLI tool and Python library for manipulating DuckDB databases

Inspired by and based on sqlite-utils.

Standard DuckDB ships with more powerful batteries than SQLite does, which may make some of the sqlite-utils CLI offerings unnecessary. The Python API, however that sqlite-utils exposes it's really well-designed and pythonic.

What's worthy of porting and what's not, will be decieded on a per-case basis.

NOTE: Initially, I tried (very hard) to avoid a complete lift-and-shift of the sqlite-utils code and use inheritance and monkey-patching instead, but it's proved trickier than I had hoped. Hence, I had to lift-and-shift some core abstractions (see https://github.com/Florents-Tselai/duckdb-utils/pull/14).

API

from duckdb_utils import Database

db = Database(memory=True)
db.execute(
  """
  CREATE TABLE bar (c1 TEXT, c2 INTEGER);
  INSERT INTO bar (c1, c2) values ('c0', 0);
  INSERT INTO bar (c1, c2) values ('c1', 1);
  INSERT INTO bar (c1, c2) values ('c2', 2);
  """
)

 bar = db.table('bar')

assert bar.exists()
assert not existing_db.table('gsdfgf').exists()

assert bar.count_where() == bar.count == 3

assert (list(bar.rows_where()) ==
        list(bar.rows) ==
        [{'c1': 'c0', 'c2': 0},
         {'c1': 'c1', 'c2': 1},
         {'c1': 'c2', 'c2': 2}])

assert bar.columns == [Column(cid=0, name='c1', type='VARCHAR', notnull=False, default_value=None, is_pk=False),
                       Column(cid=1, name='c2', type='INTEGER', notnull=False, default_value=None, is_pk=False)]

assert bar.columns_dict == {'c1': str, 'c2': int}

assert bar.schema == 'CREATE TABLE bar(c1 VARCHAR, c2 INTEGER);'

assert list(bar.pks_and_rows_where()) == [(0, {'c1': 'c0', 'c2': 0, 'rowid': 0}),
                                          (1, {'c1': 'c1', 'c2': 1, 'rowid': 1}),
                                          (2, {'c1': 'c2', 'c2': 2, 'rowid': 2})]

assert list(db.query("select * from bar")) == [{'c1': 'c0', 'c2': 0}, {'c1': 'c1', 'c2': 1}, {'c1': 'c2', 'c2': 2}]


assert list(db.execute("select * from bar").fetchall()) == [('c0', 0), ('c1', 1), ('c2', 2)]

CLI

Usage: duckdb-utils [OPTIONS] COMMAND [ARGS]...

  Commands for interacting with a DuckDB database

Options:
  --version   Show the version and exit.
  -h, --help  Show this message and exit.

Commands:
  query*
  create-table  Add a table with the specified columns.
  insert        Insert records from FILE into a table, creating the table...
  tables        List the tables in the database
  views         List the views in the database

Release files for duckdb-utils 0.1.0a4

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

Source distribution (sdist)

Source distribution for duckdb-utils 0.1.0a4
File Size Uploaded
duckdb_utils-0.1.0a4.tar.gz 71.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for duckdb-utils 0.1.0a4
File Interpreter ABI Platform
duckdb_utils-0.1.0a4-py3-none-any.whl Python 3 none any Details

Total release size: 113.1 kB

Release files / duckdb_utils-0.1.0a4.tar.gz

Download URL duckdb_utils-0.1.0a4.tar.gz
Size 71.4 kB
Tags Source
SHA-256 checksum
How to use checksums
30e5f5f07424f81d36623aa36daa256106def7f69800c7c076892c3d75f17454
BLAKE2b-256 checksum
How to use checksums
59bf36ff1ac1ad5df11e6740400b7463e9105396a769d480a053fa81132bc42c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.9

Release files / duckdb_utils-0.1.0a4-py3-none-any.whl

Download URL duckdb_utils-0.1.0a4-py3-none-any.whl
Size 41.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
959c1a15e2962850c94ac18b53b187e035878d7b01a12aa1f0e678c916e0d24d
BLAKE2b-256 checksum
How to use checksums
ef412faadc8959bbde28af6d1dfd2c1cfec6bdedbeeedee8f6630c7e7e82f9ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.9
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