No project description provided
Project description
duckdb-utils: CLI tool and Python library for manipulating DuckDB databases
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file duckdb_utils-0.1.0a4.tar.gz
.
File metadata
- Download URL: duckdb_utils-0.1.0a4.tar.gz
- Upload date:
- Size: 71.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30e5f5f07424f81d36623aa36daa256106def7f69800c7c076892c3d75f17454 |
|
MD5 | 68755dd4e588a7cf1a5e4b95fc13afdc |
|
BLAKE2b-256 | 59bf36ff1ac1ad5df11e6740400b7463e9105396a769d480a053fa81132bc42c |
File details
Details for the file duckdb_utils-0.1.0a4-py3-none-any.whl
.
File metadata
- Download URL: duckdb_utils-0.1.0a4-py3-none-any.whl
- Upload date:
- Size: 41.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 959c1a15e2962850c94ac18b53b187e035878d7b01a12aa1f0e678c916e0d24d |
|
MD5 | 165e9917beca88c507b801594e3631e9 |
|
BLAKE2b-256 | ef412faadc8959bbde28af6d1dfd2c1cfec6bdedbeeedee8f6630c7e7e82f9ad |