PoloDB for Python
Fast, typed Python bindings for PoloDB, an embedded document database with a MongoDB-like API. The database runs in-process and stores its data locally—there is no server to install or manage.
Version 0.2 uses PoloDB Core 5.3, PyO3 0.29, and CPython's stable ABI. Published wheels support CPython 3.10 and newer on Linux, macOS, and Windows.
Installation
uv add polodb-python
The distribution name is polodb-python; uv add polodb refers to a different, obsolete package.
Quick start
from polodb import PoloDB
with PoloDB("app.db") as db:
books = db["books"]
inserted = books.insert_one(
{"title": "The Three-Body Problem", "author": "Liu Cixin", "year": 2008}
)
book = books.find_one({"_id": inserted.inserted_id})
print(book)
recent = (
books.find(
{"year": {"$gte": 2000}},
)
.sort({"year": -1})
.limit(10)
)
Collections can also be accessed as attributes (db.books), though item access is preferable when a name is dynamic or collides with a database attribute.
Collection API
Insert and query
result = books.insert_many(
[
{"title": "1984", "author": "George Orwell", "year": 1949},
{"title": "Animal Farm", "author": "George Orwell", "year": 1945},
]
)
print(result.inserted_ids)
book = books.find_one({"title": "1984"})
all_orwell = books.find({"author": "George Orwell"}, sort={"year": 1})
for book in books.find_iter({"year": {"$lt": 1950}}):
print(book)
find() returns a lazy cursor, so documents are decoded as they are consumed rather than loaded into memory at once. Cursors support chainable skip(), limit(), and sort() methods; the equivalent keyword arguments on find() remain available. An omitted filter means an empty filter.
Update and delete
updated = books.update_one(
{"title": "1984"},
{"$set": {"in_print": True}},
)
print(updated.matched_count, updated.modified_count)
books.update_many(
{"author": "Octavia E. Butler"},
{"$set": {"featured": True}},
upsert=False,
)
deleted = books.delete_many({"in_print": False})
print(deleted.deleted_count)
Aggregation
authors = books.aggregate(
[
{"$match": {"year": {"$gte": 2000}}},
{"$sort": {"year": -1}},
{"$limit": 10},
]
)
Indexes
index_name = books.create_index({"title": 1}, unique=True)
books.drop_index(index_name)
Counts and drops
print(len(books))
print(books.count_documents())
books.drop()
# Equivalent database-level operation:
db.drop_collection("books")
Transactions
Transactions commit when their context exits normally and roll back when an exception escapes:
with db.transaction() as transaction:
accounts = transaction["accounts"]
accounts.update_one({"name": "Ada"}, {"$inc": {"balance": -100}})
accounts.update_one({"name": "Grace"}, {"$inc": {"balance": 100}})
Manual commit() and rollback() are also available.
BSON values
The binding round-trips the common BSON-compatible Python values:
None,bool,int,float,str- nested dictionaries, lists, and tuples
bytesandbytearray- timezone-aware or naive
datetime.datetimevalues (stored with millisecond precision and returned in UTC) - compiled regular expressions
polodb.ObjectId
Generated _id values are returned as ObjectId instances, so they can be passed directly into later filters:
from polodb import ObjectId
identifier = ObjectId() # new value
same_identifier = ObjectId(identifier.hex)
assert identifier == same_identifier
Results and errors
Write operations return typed, immutable result objects:
InsertOneResult.inserted_idInsertManyResult.inserted_idsUpdateResult.matched_countand.modified_countDeleteResult.deleted_count
They also implement Mapping, preserving dictionary-style reads such as result["modified_count"]. Database-operation failures raise PoloDBError; invalid Python values raise standard TypeError or ValueError exceptions.
Migrating from 0.1
Most CRUD code continues to work. Notable improvements and changes in 0.2 are:
- generated IDs are
ObjectIdvalues instead of lossy strings; usestr(id)orid.hexwhen text is required; - write results are typed mapping objects rather than plain dictionaries;
find()returns a lazy, chainable cursor instead of an optional list; call.to_list()when a list is needed;len(collection)andcount_documents()are preferred;collection.len()remains as a compatibility alias;- context managers now close databases and correctly commit or roll back transactions;
- unsupported BSON values raise an exception instead of silently becoming
Noneor panicking the interpreter.
Development
uv sync
uv run maturin develop
uv run pytest
uv run ruff check .
uv run mypy polodb
uv run ty check
cargo fmt --check
cargo clippy --all-targets --all-features -- -D warnings
Releases are built from vX.Y.Z tags. The tag must match both pyproject.toml and Cargo.toml. PyPI publication uses the repository's PYPI_TOKEN secret.
License
Apache-2.0. See LICENSE.txt.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file polodb_python-0.2.0.tar.gz.
File metadata
- Download URL: polodb_python-0.2.0.tar.gz
- Upload date:
- Size: 63.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1900654008865aa0357a798c60eb06378bf8429f6ed1b3dd7f4ae0890a2425b6
|
|
| MD5 |
597f1a24624e88c0169bee78b27ebb44
|
|
| BLAKE2b-256 |
b3d2fd4da799f8a2fe2b4c7d37179117b6f9a50b71f79b35f4843cd7da7bf26f
|
File details
Details for the file polodb_python-0.2.0-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: polodb_python-0.2.0-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 3.9 MB
- Tags: CPython 3.10+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c38ab5beb01ecf7011f7d3a426a13ad9dd630daf6d54dba2d5bc305da4eb3b1a
|
|
| MD5 |
e989deeab47ffa914ca2e966db810b87
|
|
| BLAKE2b-256 |
2864a207e47f627958c9c54f5a40c30c472818a8cd0e32648463113ff4cd504c
|
File details
Details for the file polodb_python-0.2.0-cp310-abi3-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: polodb_python-0.2.0-cp310-abi3-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 4.7 MB
- Tags: CPython 3.10+, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0898737e042eedc614d2c418884706a7134d96889f4f039d72e29467a6c49115
|
|
| MD5 |
aac3c390ae04650407d84f606095870e
|
|
| BLAKE2b-256 |
d532056dcba34db53bd53eff3064f789ac64cb4cee4739a412fcc03c739e1ea5
|
File details
Details for the file polodb_python-0.2.0-cp310-abi3-manylinux_2_28_aarch64.whl.
File metadata
- Download URL: polodb_python-0.2.0-cp310-abi3-manylinux_2_28_aarch64.whl
- Upload date:
- Size: 4.2 MB
- Tags: CPython 3.10+, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d00590ea75a2596b49ac8588110194f7cbbecabfcf4ce1b2f430656fa068de11
|
|
| MD5 |
eeaff4d874a80e7163ae695b757a749a
|
|
| BLAKE2b-256 |
78f0075ca14beee1a0137e6d30fc1ef1465bbee1b6dcee4c90032b700d546771
|
File details
Details for the file polodb_python-0.2.0-cp310-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: polodb_python-0.2.0-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 3.5 MB
- Tags: CPython 3.10+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2721e5840b8782ed902941cbf56ec31414623be90067fecc57ccfa2bfc4e616d
|
|
| MD5 |
b74f6a9110bb68cf00fe814746b0ce3a
|
|
| BLAKE2b-256 |
879971ce800555aff9dae1e4ba0558dcee65d925b06888e9506cfe679f2b004a
|
File details
Details for the file polodb_python-0.2.0-cp310-abi3-macosx_10_13_x86_64.whl.
File metadata
- Download URL: polodb_python-0.2.0-cp310-abi3-macosx_10_13_x86_64.whl
- Upload date:
- Size: 3.8 MB
- Tags: CPython 3.10+, macOS 10.13+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
466026ced300c8a45851ddfb3a5279515d17202fb5ecb81a75d8987ed5fe5ed3
|
|
| MD5 |
b04a5d216b2d0c8f77ca0013f8b66b39
|
|
| BLAKE2b-256 |
851022ceed8c458e179401261b63aa1efe14a95762277da9d26930deb5e0c71c
|