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.

Download files

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

Source Distribution

prismdb-0.2.0.tar.gz (19.5 kB view details)

Uploaded Source

Built Distribution

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

prismdb-0.2.0-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file prismdb-0.2.0.tar.gz.

File metadata

  • Download URL: prismdb-0.2.0.tar.gz
  • Upload date:
  • Size: 19.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for prismdb-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ba0e2883709d01440704aa2594d676501af5e9323557580e4279ce3d9531e91f
MD5 91df5b97ff949f2550ced6e5ee7e35ba
BLAKE2b-256 5209d0ebef36e58dd8ccac05a69f959b0334459ec6607c791ab6f269c4156d9c

See more details on using hashes here.

Provenance

The following attestation bundles were made for prismdb-0.2.0.tar.gz:

Publisher: pypi-publish.yml on HafizMMoaz/prism-db

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file prismdb-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: prismdb-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 19.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for prismdb-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 da2d2144c571128de0549b573e8e628b988a4bb20d7ddfe516f6be96eca1516e
MD5 1b93dd88689971a39c1098c66cbdd2cf
BLAKE2b-256 e096308d8e8a21e365dea4ed7b5e606f48fcbd51ec9e9b03ec7510f01c3f3238

See more details on using hashes here.

Provenance

The following attestation bundles were made for prismdb-0.2.0-py3-none-any.whl:

Publisher: pypi-publish.yml on HafizMMoaz/prism-db

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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