Skip to main content

prismdb (Python)

A pure-Python client for PrismDB, speaking the binary wire protocol directly over a TCP (or TLS) socket. No native extension, no build toolchain — it runs anywhere CPython does.

Implements docs/specs/wire-protocol.md. The byte layouts are kept in lockstep with the Rust prism-protocol crate and the reference Node SDK.

Install

pip install prismdb

Requires Python ≥ 3.8. No dependencies.

Quick start

from prismdb import Client, Q, U

db = Client.connect(host="127.0.0.1", port=4444, username="admin", password="admin")
with db:
    # SQL
    db.sql("CREATE TABLE users (id BIGINT PRIMARY KEY, name TEXT, age BIGINT)")
    db.sql("INSERT INTO users VALUES (1,'alice',30),(2,'bob',25)")
    res = db.sql("SELECT name, age FROM users WHERE age >= 30 ORDER BY age")
    print(res.rows)  # [{'name': 'alice', 'age': 30}]

    # Key/value
    db.kv.put("sessions", "sid-1", "payload")
    v = db.kv.get("sessions", "sid-1")          # bytes | None

    # Documents, with query operators
    db.doc.insert_one("people", {"name": "carol", "age": 41, "city": "NYC"})
    adults = db.doc.find("people", Q.and_(Q.eq("city", "NYC"), Q.gt("age", 30)))

    # A transaction is atomic across all three models
    db.begin()
    db.sql("INSERT INTO users VALUES (3,'dave',50)")
    db.kv.put("sessions", "sid-2", "tx")
    db.commit()                                  # or db.abort()

Client is a context manager; leaving the with block closes the connection.

API

Client.connect(host="127.0.0.1", port=4444, *, username=None, password=None, database=None, tls=None, ...)

Performs the Hello/Auth handshake. Omit username to skip authentication (only useful against a server that doesn't require it). Pass tls=True (or an ssl.SSLContext) for TLS. On a multi-database server, pass database= to select it at connect; otherwise run db.sql("USE <name>") yourself.

SQL — db.sql(text, params=None, *, return_rows=True)

Returns a SqlResult with .columns, .rows (list of dicts keyed by column name), .raw (cells in column order), and .affected_rows (int).

KV — db.kv

get(ns, key) -> bytes | None, put(ns, key, value), delete(ns, key). Keys and values are str (UTF-8) or bytes.

Documents — db.doc

insert_one / insert_many (return the assigned ObjectIds), find / find_one, count, update_one / update_many, delete_one / delete_many. Build filters with Q and updates with U:

Q.all()
Q.eq("f", v); Q.ne; Q.gt; Q.lt; Q.gte; Q.lte
Q.in_("f", [a, b]); Q.nin("f", [a, b])
Q.exists("f", True)
Q.and_(a, b); Q.or_(a, b); Q.not_(a)

db.doc.update_one("people", Q.eq("name", "carol"), [
    U.set("city", "Boston"),
    U.inc("age", 1),
    U.unset("temp"),
])

Transactions — db.begin(mode="read_write"), db.commit(idempotency_key=0), db.abort()

One Client is one server session, so calls between begin() and commit() run in that transaction. commit(idempotency_key=...) makes a retried commit safe.

Value mapping

Python → wire: None→Null, bool→Bool, int→Int64, float→Double, str→Str, bytes→Binary, datetime→Timestamp, ObjectId→ObjectId. Use int32(n), float64(n), timestamp(us) to force a type. On decode, Int64 and Timestamp come back as int.

Develop

python -m unittest discover -s tests   # unit tests (no server needed)

# end-to-end against a running server:
prismd run ./data 127.0.0.1:4444
PRISM_HOST=127.0.0.1 PRISM_PORT=4444 python examples/quickstart.py

Status / limitations

  • Streamed (multi-frame) SQL/document results are not yet reassembled (the current server replies in a single frame).
  • KV range/scan are follow-ups.
  • The client is synchronous; one Client owns one connection. Use a Client per thread, or one per concurrent transaction.

Metadata

Release files for prismdb 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for prismdb 0.2.0
File Size Uploaded
prismdb-0.2.0.tar.gz 19.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for prismdb 0.2.0
File Interpreter ABI Platform
prismdb-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 39.1 kB

Release files / prismdb-0.2.0.tar.gz

Download URL prismdb-0.2.0.tar.gz
Size 19.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ba0e2883709d01440704aa2594d676501af5e9323557580e4279ce3d9531e91f
BLAKE2b-256 checksum
How to use checksums
5209d0ebef36e58dd8ccac05a69f959b0334459ec6607c791ab6f269c4156d9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 9, 2026.

Transparency log

Release files / prismdb-0.2.0-py3-none-any.whl

Download URL prismdb-0.2.0-py3-none-any.whl
Size 19.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
da2d2144c571128de0549b573e8e628b988a4bb20d7ddfe516f6be96eca1516e
BLAKE2b-256 checksum
How to use checksums
e096308d8e8a21e365dea4ed7b5e606f48fcbd51ec9e9b03ec7510f01c3f3238
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 9, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release 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