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.9.0,<0.10"

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.9.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.9.0.tar.gz (104.3 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.9.0-cp39-abi3-win_arm64.whl (968.9 kB view details)

Uploaded CPython 3.9+Windows ARM64

typra-0.9.0-cp39-abi3-win_amd64.whl (1.0 MB view details)

Uploaded CPython 3.9+Windows x86-64

typra-0.9.0-cp39-abi3-musllinux_1_2_x86_64.whl (1.2 MB view details)

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

typra-0.9.0-cp39-abi3-musllinux_1_2_aarch64.whl (1.1 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ ARM64

typra-0.9.0-cp39-abi3-manylinux_2_28_aarch64.whl (1.3 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.28+ ARM64

typra-0.9.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view details)

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

typra-0.9.0-cp39-abi3-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

typra-0.9.0-cp39-abi3-macosx_10_12_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for typra-0.9.0.tar.gz
Algorithm Hash digest
SHA256 8fadd6ed2c2afae1ac58f8f22edccdae70992455cce7cee4d70a41ebed482884
MD5 f2660f267d0907dcd23a012ec0d3c222
BLAKE2b-256 8625a3a654a6a2c4e565a8f26318d33a793b94349794d4d8aad15f7637706fb3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: typra-0.9.0-cp39-abi3-win_arm64.whl
  • Upload date:
  • Size: 968.9 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.9.0-cp39-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 6399b01f0d72f742889b8f0782d7c15276c63e4c272ef8e3c19e1e75c37ac1e5
MD5 42f6ea38dd826e3a0cad0533b050fa10
BLAKE2b-256 d02bccb00a33793c47c2c5c04d53de98d8b1c2f08d0df839c121c1fe5f803865

See more details on using hashes here.

File details

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

File metadata

  • Download URL: typra-0.9.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.0 MB
  • 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.9.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 2b7359f3c53cb0248140838c8434d206d0d5d775686d4ac637de9792ccb51335
MD5 c7dae4baf15b6d6577468442c8b53ccb
BLAKE2b-256 4e749830212917aae7b44f440285178f7f6e593a09b8d97a0f814fa64e6c2e6b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for typra-0.9.0-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 7681e7fb0e4322fcb62feb4d56cd64114b6f38c3045aef834ff70f709285fe57
MD5 5243cfc131f3aa76d449a063c3cbb6af
BLAKE2b-256 1f1ca49022dbb2c1672ecea54fd85ebe5e963a14eb9e03edaa3e8e6351b75e95

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for typra-0.9.0-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 f6b79d8781018a7fc336b430ae929fb0d41b663e93ba15580b084b20cb563344
MD5 d45459e2e0fd2159e9883e5c99f5d1f8
BLAKE2b-256 0f2b6d0a2df04aef7238b6e8b1a906a3c4c344c4b0094e57fc5baab1e0883413

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for typra-0.9.0-cp39-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 43a1fa6c80908916ca70d89ec77f60fbd785a457d57f10502c01a4f1cbebd26f
MD5 aa81e0dced202cecc2c40589985715dc
BLAKE2b-256 cffb3fe6e97b15a73376384a412ba9dd2a3ca817761c60202c989257472e3e97

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for typra-0.9.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f1e97bf7f33ad397f8d5f680ca25be78225bfd16a5857d6a74e497f087e1a884
MD5 132c6da17373236f5c9327a1ecebe3d7
BLAKE2b-256 23945c2f7dd99f7333374deda9ab8dfb66b3dae86f2a6ac5a07d6fb5f8bb253c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: typra-0.9.0-cp39-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 1.1 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.9.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 26209a2169e1c80d4ce5a071523ce8bb36004559b94548df6f8d55e1e9a5b0ff
MD5 e0bb573dffc1a4ac56fc46d099b62cce
BLAKE2b-256 0e91feca4dbfa116570d84c32341fd4a4854c4750daaa185a81530e8dd0259dd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for typra-0.9.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 0e886756529aa10be56e700bf75571b086bca77159f616d50afafa68bc2fd748
MD5 cea27f7ea7e800007136a2ef54e7f924
BLAKE2b-256 939f3ca0744fb4ded99f20ca94584c2e04953a5333bf827e83c02c30f10ad59c

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