Name | cedardb JSON |
Version |
0.0.5
JSON |
| download |
home_page | None |
Summary | Pythonic driver for CedarDB |
upload_time | 2025-08-04 09:28:44 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.11 |
license | Copyright 2025 github.com/surister Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
cedardb
driver
connector
database
psycopg
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# CedarDB driver for Python.



[](https://github.com/surister/cedardb-python/actions/workflows/release.yml)
[](https://github.com/surister/cedardb-python/actions/workflows/tests.yml)
A CedarDB driver for Python, based on psycopg3. It follows it's own Pythonic API design.
# Documentation
## Installation
uv
```shell
uv add cedardb
```
pipx
```shell
pipx install cedardb
```
## Sending a Query
```python
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
```python
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
````python
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
```python
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
```python
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.
```python
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
```python
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.
Raw data
{
"_id": null,
"home_page": null,
"name": "cedardb",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.11",
"maintainer_email": null,
"keywords": "cedardb, driver, connector, database, psycopg",
"author": null,
"author_email": "Ivan <surister98@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/df/22/9dec10b1a01235d1ec7e6c3ab6045feebd5e6c890fd0d6611041d501e68d/cedardb-0.0.5.tar.gz",
"platform": null,
"description": "# CedarDB driver for Python.\n\n\n\n[](https://github.com/surister/cedardb-python/actions/workflows/release.yml)\n[](https://github.com/surister/cedardb-python/actions/workflows/tests.yml)\n\nA CedarDB driver for Python, based on psycopg3. It follows it's own Pythonic API design.\n\n# Documentation\n\n## Installation\n\nuv\n```shell\nuv add cedardb\n```\npipx\n```shell\npipx install cedardb\n```\n\n## Sending a Query\n\n```python\nfrom cedardb import Client\n\nclient = Client(host='localhost', dbname='postgres', user='postgres', password='password')\n\nresult = client.query('CREATE TABLE metrics (ts TIMESTAMP, user_id INTEGER, message TEXT)')\nprint(result)\n# QueryResponse(original_statement_type='CREATE',\n# columns=[],\n# row_count=-1,\n# duration=0,\n# exception=None,\n# error_message=None)\n\nprint(result.ok)\n# True\n```\n\n## Selecting data\n```python\nfrom cedardb import Client\n\nclient = Client(...)\nresult = client.query(\"select * from metrics\")\n\nprint(result)\n# QueryResponse(original_statement_type='SELECT',\n# columns=['ts', 'user_id', 'message'],\n# row_count=3,\n# duration=0,\n# exception=None,\n# error_message=None)\nfor row in result:\n print(row)\n# (datetime.datetime(2025, 4, 11, 16, 32, 30, 211770), 1, 'I want pizza!')\n# (datetime.datetime(2025, 4, 11, 16, 32, 30, 216277), 2, 'What toppings?')\n# (datetime.datetime(2025, 4, 11, 16, 32, 30, 218842), 1, 'Tunna and Onions')\n\nprint(row.as_table())\n# +----------------------------+---------+------------------+\n# | ts | user_id | message |\n# +----------------------------+---------+------------------+\n# | 2025-04-11 16:32:30.211770 | 1 | I want pizza! |\n# | 2025-04-11 16:32:30.216277 | 2 | What toppings? |\n# | 2025-04-11 16:32:30.218842 | 1 | Tunna and Onions |\n# +----------------------------+---------+------------------+\n```\n## Bulk insert using pipelining\n````python\nfrom cedardb import Client\n\nclient = Client(...)\n\n# Create the table to insert the data to\nresult = client.query('CREATE TABLE if not exists metrics (ts TIMESTAMP, user_id INTEGER, message TEXT)')\n\n# Generate some random rows\nrows = [\n (datetime.datetime.now(), i, 'somemsg') for i in range(10)\n]\n\n# Bulk insert\nr = client.insert_many('metrics', rows=rows)\n\n# Check if the insert was successful and print the latest inserted values\nif r.ok:\n print(\n client.query('select * from metrics order by ts desc').as_table()\n )\n````\n\n\n## Using a factory\n```python\nimport dataclasses\nimport datetime\n\nfrom cedardb import Client\n\nclient = Client(...)\n\n@dataclasses.dataclass\nclass Message:\n ts: datetime\n user_id: int\n message: str\n\n\nresult = client.query(\"select * from metrics\", factory=Message)\n\nfor row in result:\n print(row)\n \n# Message(ts=datetime.datetime(2025, 4, 11, 16, 32, 30, 211770), user_id=1, message='I want pizza!')\n# Message(ts=datetime.datetime(2025, 4, 11, 16, 32, 30, 216277), user_id=2, message='What toppings?')\n# Message(ts=datetime.datetime(2025, 4, 11, 16, 32, 30, 218842), user_id=1, message='Tunna and Onions')\n```\n\n## Errors\nOn database errors you can tell `.query` to raise an exception or get the error \non the `SQLResult` object (default).\n\n### Default\n```python\nresult = client.query('CREATE TABLE metrics (ts TIMESTAMP, user_id INTEGER, message TEXT)')\n\nprint(result)\n# QueryResponse(original_statement_type='',\n# columns=[],\n# row_count=-1,\n# duration=0,\n# exception=DuplicateTable('relation \"metrics\" already exists'),\n# error_message='relation \"metrics\" already exists')\nprint(result.ok)\n# False\n```\n\nYou can now re-raise the exception if needed. Exceptions are `psycopg`'s.\n```python\nif result.exception:\n raise result.exception\n# File \"/home/surister/PycharmProjects/cedardb-python/cedardb/client.py\", line 39, in query\n# cur.execute(statement)\n# ~~~~~~~~~~~^^^^^^^^^^^\n# File \"/home/surister/PycharmProjects/cedardb-python/.venv/lib/python3.13/site-packages/psycopg/cursor.py\", line 97, in execute\n# raise ex.with_traceback(None)\n# psycopg.errors.DuplicateTable: relation \"metrics\" already exists\n```\n\n### Raise exception on queries\n\n```python\nresult = client.query(\n 'CREATE TABLE metrics (ts TIMESTAMP, user_id INTEGER, message TEXT)',\n raise_exception=True\n)\n# File \"/home/surister/PycharmProjects/cedardb-python/cedardb/client.py\", line 39, in query\n# cur.execute(statement)\n# ~~~~~~~~~~~^^^^^^^^^^^\n# File \"/home/surister/PycharmProjects/cedardb-python/.venv/lib/python3.13/site-packages/psycopg/cursor.py\", line 97, in execute\n# raise ex.with_traceback(None)\n# psycopg.errors.DuplicateTable: relation \"metrics\" already exists\n```\n\n# License\nThis project is open-source under a MIT license.\n",
"bugtrack_url": null,
"license": "Copyright 2025 github.com/surister Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \u201cSoftware\u201d), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \u201cAS IS\u201d, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
"summary": "Pythonic driver for CedarDB",
"version": "0.0.5",
"project_urls": {
"Changelog": "https://github.com/surister/cedardb-python/releases",
"DOCUMENTATION": "https://github.com/surister/cedardb-python",
"GitHub": "https://github.com/surister/cedardb-python",
"Home Page": "https://github.com/surister/cedardb-python",
"Repository": "https://github.com/surister/cedardb-python.git"
},
"split_keywords": [
"cedardb",
" driver",
" connector",
" database",
" psycopg"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "45e0bdfc2f8f04a88f33033873bea10d954e95fcd954d67bb774e5818fc09359",
"md5": "cf57501cdad60a1aec3afafe6f6e46a0",
"sha256": "10f5c6b3223e5317065ec10ab5dfd4a7031c6ceb56d12dcf3932fc577fa939e4"
},
"downloads": -1,
"filename": "cedardb-0.0.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "cf57501cdad60a1aec3afafe6f6e46a0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11",
"size": 7774,
"upload_time": "2025-08-04T09:28:44",
"upload_time_iso_8601": "2025-08-04T09:28:44.211893Z",
"url": "https://files.pythonhosted.org/packages/45/e0/bdfc2f8f04a88f33033873bea10d954e95fcd954d67bb774e5818fc09359/cedardb-0.0.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "df229dec10b1a01235d1ec7e6c3ab6045feebd5e6c890fd0d6611041d501e68d",
"md5": "54938541fbd75754018842527ac9a1ed",
"sha256": "0333d5a2b56655cd2669c922f2e76e72bd89d862d99b265e7fcf0207bc6e59c2"
},
"downloads": -1,
"filename": "cedardb-0.0.5.tar.gz",
"has_sig": false,
"md5_digest": "54938541fbd75754018842527ac9a1ed",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11",
"size": 8343,
"upload_time": "2025-08-04T09:28:44",
"upload_time_iso_8601": "2025-08-04T09:28:44.914465Z",
"url": "https://files.pythonhosted.org/packages/df/22/9dec10b1a01235d1ec7e6c3ab6045feebd5e6c890fd0d6611041d501e68d/cedardb-0.0.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-04 09:28:44",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "surister",
"github_project": "cedardb-python",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "cedardb"
}