Skip to main content

No project description provided

Project description

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.

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

Project details


Download files

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

Source Distribution

duckdb_utils-0.1.0a3.tar.gz (46.9 kB view details)

Uploaded Source

Built Distribution

duckdb_utils-0.1.0a3-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file duckdb_utils-0.1.0a3.tar.gz.

File metadata

  • Download URL: duckdb_utils-0.1.0a3.tar.gz
  • Upload date:
  • Size: 46.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for duckdb_utils-0.1.0a3.tar.gz
Algorithm Hash digest
SHA256 a147b0accfae63af637c1b64ffe11e3a1af29a798e6d89cd87f29c9facc61712
MD5 0fa42b393f8ee403d02986523e74f4de
BLAKE2b-256 94aab769898e866f5b1e6e0f7e2bd16dd59ed0ab34ca3aba31599c510139e260

See more details on using hashes here.

File details

Details for the file duckdb_utils-0.1.0a3-py3-none-any.whl.

File metadata

File hashes

Hashes for duckdb_utils-0.1.0a3-py3-none-any.whl
Algorithm Hash digest
SHA256 6609da59e872dd87847abe30737d9bc521adebd08b2a9a826f95fda03ae23acc
MD5 19c38a6c4b9ec5bf4cd5f27d42ef1ad2
BLAKE2b-256 e8b2c3e92a47cdc4f40bc40e758aab265d165ff001379e1ba92e62d97af7c764

See more details on using hashes here.

Supported by

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