mona
Official Python SDK for MonaDB. Sync and async, built on httpx and pydantic.
Note: install the PyPI distribution
mona-previewwhile themonaname is being acquired. The import package is alwaysmona. Do not installmona-previewandmonain the same environment.
Install
pip install mona-preview
From source:
git clone https://github.com/rchowell/mona-python.git
cd mona-python
pip install -e .
Usage
from mona import Client
mo = Client(api_key="mk-...", base_url="https://mona.example.workers.dev")
mo.databases.create(name="beatles")
db = mo.database("beatles")
db.execute("create table beatles;")
db.insert(
"beatles",
{"name": "John"},
{"name": "Paul"},
{"name": "George"},
{"name": "Ringo"},
)
rows = db.fetchall("select * from beatles;")
print(rows)
# [{"name": "John"}, {"name": "Paul"}, {"name": "George"}, {"name": "Ringo"}]
database("name") returns a handle for running SQL. Use insert for rows,
execute for DDL and other statements (one statement or a batch), and
fetchall to read rows back. Chain calls work too:
rows = db.execute("select * from beatles;").fetchall()
Control-plane helpers (create, list, get, delete) stay on
client.databases.
Async
from mona import AsyncClient
async with AsyncClient(api_key="mk-...", base_url="https://mona.example.workers.dev") as mo:
await mo.databases.create(name="beatles")
db = mo.database("beatles")
await db.execute("create table beatles;")
await db.insert(
"beatles",
{"name": "John"},
{"name": "Paul"},
{"name": "George"},
{"name": "Ringo"},
)
rows = await db.fetchall("select * from beatles;")
Configuration
| Argument | Env | Default | Notes |
|---|---|---|---|
api_key |
MONA_API_KEY |
— | Bearer token sent on every request. |
base_url |
MONA_BASE_URL |
— | Worker URL (serves control + data plane). |
query_base_url |
— | base_url |
Override the data-plane host (local dev only). |
timeout |
— | 30.0 |
Per-request timeout in seconds. |
max_retries |
— | 2 |
Retries on connection errors (httpx transport). |
Errors
All errors subclass mona.MonaError. API errors (mona.APIError and its subclasses
AuthenticationError, BadRequestError, NotFoundError, ConflictError) carry
status_code, code, and message.
Development
just test # unit tests only
just lint # ruff
just typecheck # mypy
just build # wheel + sdist
Publishing
GitHub release tags (e.g. v0.1.0-preview) and the PyPI version in src/mona/_version.py
(e.g. 0.1.0) are set independently. Preview tags on GitHub, semver on PyPI.
- Bump
src/mona/_version.py(PyPI version). - Create a GitHub release with a preview tag (e.g.
v0.1.0-preview), or runjust publishlocally withUV_PUBLISH_TOKENset. - On PyPI, add a trusted publisher for
mona-previewpointing atrchowell/mona-python(recommended over long-lived API tokens).
Metadata
Release files for mona-preview 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mona_preview-0.1.1.tar.gz | 61.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mona_preview-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 82.6 kB
Release files / mona_preview-0.1.1.tar.gz
| Download URL | mona_preview-0.1.1.tar.gz |
|---|---|
| Size | 61.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
274a019f095a8409211c2cd980720a030b7a473c19696d3e6275eb6ab541fcb2
|
|
BLAKE2b-256 checksum How to use checksums |
aac47441d619286f84d8d6c6c32ca9bd64e37d3269956d5fbae798423096085c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"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 / mona_preview-0.1.1-py3-none-any.whl
| Download URL | mona_preview-0.1.1-py3-none-any.whl |
|---|---|
| Size | 21.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
808bda454b2d494a52652c0af751dbeff4f0768028af437ecc902a8d6d6e1151
|
|
BLAKE2b-256 checksum How to use checksums |
5342a6ae717c4ca8a2149cd19ef738054f772cb620919be73e57fe1ad6eeaccc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"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}
|