CedarDB driver for Python.
A CedarDB driver for Python, based on psycopg3. It follows it's own Pythonic API design.
Documentation
Installation
uv
uv add cedardb
pipx
pipx install cedardb
Sending a Query
from cedardb import Client
client = Client(host='localhost', dbname='postgres', user='postgres', password='password')
result = client.query('CREATE TABLE metrics (ts TIMESTAMP, user_id INTEGER, message TEXT)')
print(result)
# QueryResponse(original_statement_type='CREATE',
# columns=[],
# row_count=-1,
# duration=0,
# exception=None,
# error_message=None)
print(result.ok)
# True
Selecting data
from cedardb import Client
client = Client(...)
result = client.query("select * from metrics")
print(result)
# QueryResponse(original_statement_type='SELECT',
# columns=['ts', 'user_id', 'message'],
# row_count=3,
# duration=0,
# exception=None,
# error_message=None)
for row in result:
print(row)
# (datetime.datetime(2025, 4, 11, 16, 32, 30, 211770), 1, 'I want pizza!')
# (datetime.datetime(2025, 4, 11, 16, 32, 30, 216277), 2, 'What toppings?')
# (datetime.datetime(2025, 4, 11, 16, 32, 30, 218842), 1, 'Tunna and Onions')
print(row.as_table())
# +----------------------------+---------+------------------+
# | ts | user_id | message |
# +----------------------------+---------+------------------+
# | 2025-04-11 16:32:30.211770 | 1 | I want pizza! |
# | 2025-04-11 16:32:30.216277 | 2 | What toppings? |
# | 2025-04-11 16:32:30.218842 | 1 | Tunna and Onions |
# +----------------------------+---------+------------------+
Bulk insert using pipelining
from cedardb import Client
client = Client(...)
# Create the table to insert the data to
result = client.query('CREATE TABLE if not exists metrics (ts TIMESTAMP, user_id INTEGER, message TEXT)')
# Generate some random rows
rows = [
(datetime.datetime.now(), i, 'somemsg') for i in range(10)
]
# Bulk insert
r = client.insert_many('metrics', rows=rows)
# Check if the insert was successful and print the latest inserted values
if r.ok:
print(
client.query('select * from metrics order by ts desc').as_table()
)
Using a factory
import dataclasses
import datetime
from cedardb import Client
client = Client(...)
@dataclasses.dataclass
class Message:
ts: datetime
user_id: int
message: str
result = client.query("select * from metrics", factory=Message)
for row in result:
print(row)
# Message(ts=datetime.datetime(2025, 4, 11, 16, 32, 30, 211770), user_id=1, message='I want pizza!')
# Message(ts=datetime.datetime(2025, 4, 11, 16, 32, 30, 216277), user_id=2, message='What toppings?')
# Message(ts=datetime.datetime(2025, 4, 11, 16, 32, 30, 218842), user_id=1, message='Tunna and Onions')
Errors
On database errors you can tell .query to raise an exception or get the error
on the SQLResult object (default).
Default
result = client.query('CREATE TABLE metrics (ts TIMESTAMP, user_id INTEGER, message TEXT)')
print(result)
# QueryResponse(original_statement_type='',
# columns=[],
# row_count=-1,
# duration=0,
# exception=DuplicateTable('relation "metrics" already exists'),
# error_message='relation "metrics" already exists')
print(result.ok)
# False
You can now re-raise the exception if needed. Exceptions are psycopg's.
if result.exception:
raise result.exception
# File "/home/surister/PycharmProjects/cedardb-python/cedardb/client.py", line 39, in query
# cur.execute(statement)
# ~~~~~~~~~~~^^^^^^^^^^^
# File "/home/surister/PycharmProjects/cedardb-python/.venv/lib/python3.13/site-packages/psycopg/cursor.py", line 97, in execute
# raise ex.with_traceback(None)
# psycopg.errors.DuplicateTable: relation "metrics" already exists
Raise exception on queries
result = client.query(
'CREATE TABLE metrics (ts TIMESTAMP, user_id INTEGER, message TEXT)',
raise_exception=True
)
# File "/home/surister/PycharmProjects/cedardb-python/cedardb/client.py", line 39, in query
# cur.execute(statement)
# ~~~~~~~~~~~^^^^^^^^^^^
# File "/home/surister/PycharmProjects/cedardb-python/.venv/lib/python3.13/site-packages/psycopg/cursor.py", line 97, in execute
# raise ex.with_traceback(None)
# psycopg.errors.DuplicateTable: relation "metrics" already exists
License
This project is open-source under a MIT license.
Metadata
Release files for cedardb 0.0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cedardb-0.0.8.tar.gz | 8.3 kB | Without provenance | Details for cedardb-0.0.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cedardb-0.0.8-py3-none-any.whl | Python 3 | none | any | Details for cedardb-0.0.8-py3-none-any.whl |
Total release size: 16.1 kB
Release files / cedardb-0.0.8.tar.gz
| Download URL | cedardb-0.0.8.tar.gz |
|---|---|
| Size | 8.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
018ee15bb8f2feb954f766130d506c62c8889e0756916ee5f3c926a44ebd8061
|
|
BLAKE2b-256 checksum How to use checksums |
5ba36ae0382ba75a0a3421745ce92b7888990f60dcfded5e48223e79064602f6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"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":true}
|
Release files / cedardb-0.0.8-py3-none-any.whl
| Download URL | cedardb-0.0.8-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6f8495d046ccde6fac1af2817a2c38b45cd14a1ebc6f9b8e0aac6941d3bb28ad
|
|
BLAKE2b-256 checksum How to use checksums |
c867489f424d1e6b5738b065286213d525a0d3730cbb090e1a9601b9f75b4be3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"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":true}
|
Security for cedardb 0.0.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.