Skip to main content

Python bindings for Typra, a typed embedded database.

Project description

typra (Python)

CI PyPI

Official CPython bindings for Typra (PyO3 native extension): a typed, embedded database with a Rust core.

Status

You get a durable schema catalog, validation, nested row values (record v2 on insert; v1 segments still replay), and constraints in a single .typra file, plus in-memory databases and snapshot bytes.

Queries and secondary indexes (0.7+): register optional indexes_json on register_collection, then use db.collection("name").where("field", value).and_where(...).limit(n).explain() and all() / all(fields=[...]) for subset rows. A longer on-disk + reopen example lives in the Python user guide — Realistic workflow. SQL text and DB-API layers are still out of scope—see the roadmap.

Resource Link
Repository github.com/eddiethedean/typra
Rust crates typra on crates.io
Full Python guide docs/guide_python.md
Getting started docs/guide_getting_started.md
Migrating 0.4 → 0.5 docs/migration_0.4_to_0.5.md
Migrating 0.5 → 0.6 docs/migration_0.5_to_0.6.md
Migrating 0.6 → 0.7 docs/migration_0.6_to_0.7.md
Rust module layout docs/03_rust_crate_and_module_layout.md
Changelog CHANGELOG.md

Requirements

  • CPython 3.9+
  • Wheels use the stable ABI (cp39-abi3): one wheel per platform, compatible with Python 3.9+ on that platform.

Install

pip install "typra>=0.7.0,<0.8"

Pin the minor range you test against; pre-1.0 releases may still change APIs or the on-disk format between minors.

Quick start

# Setup: module, in-memory DB, and `books` collection (PK `title`).
import typra

db = typra.Database.open_in_memory()
cid, ver = db.register_collection(
    "books",
    '[{"path": ["title"], "type": "string"}]',
    "title",
)
# Example: insert one row, read it back, print package version.
print("registered", cid, ver)
db.insert("books", {"title": "Typra"})
print(db.get("books", "Typra"))
print(typra.__version__)

Output (the version line matches the installed wheel):

registered 1 1
{'title': 'Typra'}
0.7.0

On disk, use Database.open("app.typra") instead; registrations are persisted across process restarts for that path.

Indexed query (sketch)

# Setup: in-memory DB, indexed collection, one row.
import typra

db = typra.Database.open_in_memory()
fields = '[{"path": ["id"], "type": "int64"}, {"path": ["sku"], "type": "string"}]'
indexes = '[{"name": "sku_idx", "path": ["sku"], "kind": "index"}]'
db.register_collection("items", fields, "id", indexes)
db.insert("items", {"id": 1, "sku": "abc"})
# Example: equality query on indexed `sku`.
print(db.collection("items").where("sku", "abc").all())

Output:

[{'id': 1, 'sku': 'abc'}]

See docs/guide_python.md for and_where, limit, explain, and subset projections.

API overview

Member Description
typra.__version__ Package version (matches the Rust workspace release).
Database.open(path: str) Create or open a database file. Raises OSError if the path cannot be opened (e.g. missing parent directory, path is a directory).
db.path() -> str Path used to open the database.
db.register_collection(name, fields_json, primary_field, indexes_json=None) -> tuple[int, int] Register a new collection (schema version 1). Optional indexes_json: JSON array of {"name", "path", "kind"} objects ("unique" or "index" / "non_unique"). Returns (collection_id, schema_version). Names are trimmed; duplicates or bad JSON raise ValueError.
db.collection(name) -> Collection Query handle: where, and_where, limit, explain, all / all(fields=[...]).
db.insert(collection_name, row: dict) -> None Insert or replace the latest row (required fields + optional keys per schema).
db.get(collection_name, pk) -> dict | None Latest row or missing.
Database.open_in_memory() / Database.open_snapshot_bytes(data) / db.snapshot_bytes() In-memory DB and byte snapshots.
db.collection_names() -> list[str] All registered names, sorted alphabetically.

For behavior details (errors, edge cases, development), see the Python user guide.

fields_json (schema descriptor)

register_collection expects fields_json to be a JSON array of objects. Each object describes one field:

  • path: JSON array of strings (path segments), e.g. ["profile", "name"].
  • type: either a primitive name or a composite object.

Primitives: "bool", "int64", "uint64", "float64", "string", "bytes", "uuid", "timestamp".

Composites:

  • Optional: {"optional": <inner>}
  • List: {"list": <inner>}
  • Object: {"object": [ … same shape as top-level field objects … ]}
  • Enum: {"enum": ["a", "b"]} (variants must be strings)
  • constraints (optional): JSON array of constraint objects, e.g. {"min_i64": 0}, {"max_length": 100}, {"email": true}, {"regex": "^[a-z]+$"}.

Example (nested)

# Setup: in-memory DB and a collection whose PK uses an optional int field.
import typra

db = typra.Database.open_in_memory()
db.register_collection(
    "items",
    '[{"path": ["x"], "type": {"optional": "int64"}}]',
    "x",
)
# Example: confirm registration.
print("nested:", db.collection_names())

Output:

nested: ['items']

Example (multiple fields)

# Setup: in-memory DB and a multi-field `books` schema (PK `title`).
import typra

db = typra.Database.open_in_memory()
schema = """[
  {"path": ["title"], "type": "string"},
  {"path": ["year"], "type": "int64"},
  {"path": ["tags"], "type": {"list": "string"}}
]"""
db.register_collection("books", schema, "title")
# Example: confirm registration.
print("multi:", db.collection_names())

Output:

multi: ['books']

Exceptions

  • ValueError: invalid JSON, wrong shape, unknown type, invalid collection name, duplicate collection name, validation failures, or format/schema errors from the engine when registering.
  • OSError: I/O failures when opening the database file.
  • RuntimeError: reserved for engine “not implemented” paths (unexpected for supported API paths).

Building from source

You need Rust, Python 3.9+, and maturin. From the repo’s python/typra directory:

maturin develop --release
pytest -q

From the repository root, make check-full runs Rust + Python checks, tests, and make verify-doc-examples (validates documented command output). See also python/README.md (workspace layout for contributors).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

typra-0.7.0.tar.gz (84.6 kB view details)

Uploaded Source

Built Distributions

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

typra-0.7.0-cp39-abi3-win_arm64.whl (885.7 kB view details)

Uploaded CPython 3.9+Windows ARM64

typra-0.7.0-cp39-abi3-win_amd64.whl (949.3 kB view details)

Uploaded CPython 3.9+Windows x86-64

typra-0.7.0-cp39-abi3-musllinux_1_2_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ x86-64

typra-0.7.0-cp39-abi3-musllinux_1_2_aarch64.whl (984.7 kB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ ARM64

typra-0.7.0-cp39-abi3-manylinux_2_28_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.28+ ARM64

typra-0.7.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

typra-0.7.0-cp39-abi3-macosx_11_0_arm64.whl (1.0 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

typra-0.7.0-cp39-abi3-macosx_10_12_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file typra-0.7.0.tar.gz.

File metadata

  • Download URL: typra-0.7.0.tar.gz
  • Upload date:
  • Size: 84.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for typra-0.7.0.tar.gz
Algorithm Hash digest
SHA256 2b88270ef16350b24e17f16e52c44863fd9485f90483b9505a6111a649867173
MD5 c914c1d5c8f6329ba43541a4ddc5c950
BLAKE2b-256 442d268dc1c08fde693957cebd76e670a1e84f2b8690e9317e500d6f63259c04

See more details on using hashes here.

File details

Details for the file typra-0.7.0-cp39-abi3-win_arm64.whl.

File metadata

  • Download URL: typra-0.7.0-cp39-abi3-win_arm64.whl
  • Upload date:
  • Size: 885.7 kB
  • Tags: CPython 3.9+, Windows ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.9

File hashes

Hashes for typra-0.7.0-cp39-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 10371ea62700ca0c51f3d0d82ea43b4b0866b92fac7aef0703d45da789114ed9
MD5 7ce2802698dd6679dc5460db791e46de
BLAKE2b-256 050b1da3f3352b5c50852a495e9d2af7096266f41ad1f06e98b46ae0329bb38b

See more details on using hashes here.

File details

Details for the file typra-0.7.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: typra-0.7.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 949.3 kB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.13

File hashes

Hashes for typra-0.7.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 25160b8cfb2dcacc6bfcd99765d81e9ad572dc8f0c1b00616c2492f7707c08cf
MD5 023a737b86412dadedd867346f220097
BLAKE2b-256 defb4bf45266e55995eb2241cdcf696bffc319fa1155d0fbb4cbcbfbaccd9ee5

See more details on using hashes here.

File details

Details for the file typra-0.7.0-cp39-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for typra-0.7.0-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c7d9861215de0e9ce2bda3c65779905ab244988e18260e73cf4bc03c58443970
MD5 1f2ca29e900486bfa2745f8a0fb7bb7f
BLAKE2b-256 56ff8f6f7ec5964ff3889fb164e55575ff52104ac5d495f9ad7957dd71b2bec6

See more details on using hashes here.

File details

Details for the file typra-0.7.0-cp39-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for typra-0.7.0-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 86c51b75a4cd11f7374977c6b8fa95960416fa27663e8ee8764e03dc3aadb743
MD5 564283e823548b074197a5f71b9c5057
BLAKE2b-256 c4e4ff06b1cb1770eb8190af25e557b354bc312270f16f4f321ea2dfa38ed274

See more details on using hashes here.

File details

Details for the file typra-0.7.0-cp39-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for typra-0.7.0-cp39-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 3934112fa58182207ec291ac5af3fe6022fa346de31db526dc692ce9d6fa22ee
MD5 f9cee6bf467f375d2f18aaa59e7636a1
BLAKE2b-256 c3e8ca51b4f585e8fac64317471abb9eefc2129d4cfa457092d142fd04105ab9

See more details on using hashes here.

File details

Details for the file typra-0.7.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for typra-0.7.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e29228c85bd357db7ed38af1544cc2144028e2e5da3d4ffe0a37056705c9d45c
MD5 257d00cc3edfa98f3929ea803c4cf539
BLAKE2b-256 c20b1bcfdf2c8d5f361245b39d7352ea07e7bbdafc6b0d117f82c02ea3a966ec

See more details on using hashes here.

File details

Details for the file typra-0.7.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: typra-0.7.0-cp39-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 1.0 MB
  • Tags: CPython 3.9+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.14.4

File hashes

Hashes for typra-0.7.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d47ead8f38a3248131353b6d8e0a8388d2f2b53a30c9194e1d34650bf82ce293
MD5 66cc523ae7d533cb6dad8f2aa5a63247
BLAKE2b-256 893d7b1063eab3b8fe7a79565afe1905b568b99a78ee1621222673bde9bccfad

See more details on using hashes here.

File details

Details for the file typra-0.7.0-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for typra-0.7.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 184b9345d71f5db11735494cdb261194659f12425afa9da3208b00c568514133
MD5 ae8cd6d07ac1f05cb52544c4a318ccf3
BLAKE2b-256 8e4dc22c9a95705b9f22bd11d78ebcb4df14b0feb4dfa3e32f90c388c9052733

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page