Skip to main content

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
  • bytes and bytearray
  • timezone-aware or naive datetime.datetime values (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_id
  • InsertManyResult.inserted_ids
  • UpdateResult.matched_count and .modified_count
  • DeleteResult.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 ObjectId values instead of lossy strings; use str(id) or id.hex when 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) and count_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 None or 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

polodb_python-0.2.0.tar.gz (63.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

polodb_python-0.2.0-cp310-abi3-win_amd64.whl (3.9 MB view details)

Uploaded CPython 3.10+Windows x86-64

polodb_python-0.2.0-cp310-abi3-manylinux_2_28_x86_64.whl (4.7 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64

polodb_python-0.2.0-cp310-abi3-manylinux_2_28_aarch64.whl (4.2 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

polodb_python-0.2.0-cp310-abi3-macosx_11_0_arm64.whl (3.5 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

polodb_python-0.2.0-cp310-abi3-macosx_10_13_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.10+macOS 10.13+ x86-64

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

Hashes for polodb_python-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1900654008865aa0357a798c60eb06378bf8429f6ed1b3dd7f4ae0890a2425b6
MD5 597f1a24624e88c0169bee78b27ebb44
BLAKE2b-256 b3d2fd4da799f8a2fe2b4c7d37179117b6f9a50b71f79b35f4843cd7da7bf26f

See more details on using hashes here.

File details

Details for the file polodb_python-0.2.0-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for polodb_python-0.2.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c38ab5beb01ecf7011f7d3a426a13ad9dd630daf6d54dba2d5bc305da4eb3b1a
MD5 e989deeab47ffa914ca2e966db810b87
BLAKE2b-256 2864a207e47f627958c9c54f5a40c30c472818a8cd0e32648463113ff4cd504c

See more details on using hashes here.

File details

Details for the file polodb_python-0.2.0-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for polodb_python-0.2.0-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0898737e042eedc614d2c418884706a7134d96889f4f039d72e29467a6c49115
MD5 aac3c390ae04650407d84f606095870e
BLAKE2b-256 d532056dcba34db53bd53eff3064f789ac64cb4cee4739a412fcc03c739e1ea5

See more details on using hashes here.

File details

Details for the file polodb_python-0.2.0-cp310-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for polodb_python-0.2.0-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d00590ea75a2596b49ac8588110194f7cbbecabfcf4ce1b2f430656fa068de11
MD5 eeaff4d874a80e7163ae695b757a749a
BLAKE2b-256 78f0075ca14beee1a0137e6d30fc1ef1465bbee1b6dcee4c90032b700d546771

See more details on using hashes here.

File details

Details for the file polodb_python-0.2.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for polodb_python-0.2.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2721e5840b8782ed902941cbf56ec31414623be90067fecc57ccfa2bfc4e616d
MD5 b74f6a9110bb68cf00fe814746b0ce3a
BLAKE2b-256 879971ce800555aff9dae1e4ba0558dcee65d925b06888e9506cfe679f2b004a

See more details on using hashes here.

File details

Details for the file polodb_python-0.2.0-cp310-abi3-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for polodb_python-0.2.0-cp310-abi3-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 466026ced300c8a45851ddfb3a5279515d17202fb5ecb81a75d8987ed5fe5ed3
MD5 b04a5d216b2d0c8f77ca0013f8b66b39
BLAKE2b-256 851022ceed8c458e179401261b63aa1efe14a95762277da9d26930deb5e0c71c

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.1

6 files

This release

0.2.0 This release

6 files

0.1.18

10 files

0.1.17

4 files

0.1.16

2 files

0.1.13

2 files

0.1.12

6 files

0.1.10

2 files

0.1.9

2 files

0.1.8

3 files

0.1.7

1 file

0.1.6

2 files

0.1.5

3 files

0.1.4

2 files

0.1.3

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page