Skip to main content

Python client for UmaDB event store

Project description

UmaDB Python Client

A Python client for UmaDB event store built using Rust bindings via PyO3 and Maturin.

Installation

From PyPI

First, create and activate a virtual environment. Then:

pip install umadb

Usage

Basic Example

from umadb import Client, Event

# Connect to UmaDB server
client = Client("http://localhost:50051")

# Create and append events
event = Event(
    event_type="UserCreated",
    data=b"user data",
    tags=["user", "creation"],
)
position = client.append([event])
print(f"Event appended at position: {position}")

# Read events
events = client.read()
for seq_event in events:
    print(f"Position {seq_event.position}: {seq_event.event.event_type}")

# Get current head position
head = client.head()
print(f"Current head: {head}")

Using Queries

from umadb import Client, Query, QueryItem

client = Client("http://localhost:50051")

# Create a query to filter events
query_item = QueryItem(
    types=["UserCreated", "UserUpdated"],
    tags=["user"]
)
query = Query(items=[query_item])

# Read filtered events
events = client.read(query=query)
for seq_event in events:
    print(f"Position {seq_event.position}: {seq_event.event.event_type}")

Using Append Conditions

from umadb import Client, Event, Query, QueryItem, AppendCondition

client = Client("http://localhost:50051")

# Create a condition that prevents duplicate events
fail_query_item = QueryItem(types=["UserCreated"], tags=["user:123"])
fail_query = Query(items=[fail_query_item])
condition = AppendCondition(fail_if_events_match=fail_query)

# This will fail if matching events exist
event = Event(
    event_type="UserCreated",
    data=b"user data",
    tags=["user:123"],
)
try:
    position = client.append([event], condition=condition)
except ValueError as e:
    print(f"Append failed: {e}")

TLS/SSL Connection

from umadb import Client

# Connect with TLS using CA certificate
client = Client(
    url="https://secure-server:50051",
    ca_path="/path/to/ca.pem"
)

Reading with Options

from umadb import Client

client = Client("http://localhost:50051", batch_size=100)

# Read backwards from position
events = client.read(start=100, backwards=True, limit=10)

# Subscribe to new events (streaming)
events = client.read(subscribe=True)

API Reference

Client

Client(url: str, ca_path: str | None = None, batch_size: int | None = None)

Creates a new UmaDB client connection.

Methods:

  • read(query=None, start=None, backwards=False, limit=None, subscribe=False): Read events from the store
  • head(): Get the current head position (returns int | None)
  • append(events, condition=None): Append events to the store (returns position as int)

Event

Event(event_type: str, data: bytes, tags: list[str] | None = None, uuid: str | None = None)

Represents an event in the event store.

Properties:

  • event_type: Type of the event (string)
  • data: Binary data (bytes)
  • tags: List of tags (list of strings)
  • uuid: Optional UUID (string)

SequencedEvent

Represents an event with its position in the sequence.

Properties:

  • event: The Event object
  • position: Position in the sequence (int)

Query

Query(items: list[QueryItem] | None = None)

A query for filtering events.

QueryItem

QueryItem(types: list[str] | None = None, tags: list[str] | None = None)

A query item specifying event types and tags to match.

AppendCondition

AppendCondition(fail_if_events_match: Query, after: int | None = None)

Condition for conditional appends.

Development

Building

First, create and activate a virtual environment. Then:

# Install maturin
pip install maturin

# Build and install in development mode
maturin develop -m ./umadb-python/Cargo.toml

# Or build a wheel
maturin build -m ./umadb-python/Cargo.toml --release

Testing

The Python bindings can be tested by running a UmaDB server and executing Python code against it.

License

Licensed under either of:

at your option.

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

umadb-0.1.22.tar.gz (37.7 kB view details)

Uploaded Source

Built Distributions

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

umadb-0.1.22-cp310-abi3-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.10+Windows x86-64

umadb-0.1.22-cp310-abi3-win32.whl (1.4 MB view details)

Uploaded CPython 3.10+Windows x86

umadb-0.1.22-cp310-abi3-musllinux_1_2_x86_64.whl (2.2 MB view details)

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

umadb-0.1.22-cp310-abi3-musllinux_1_2_aarch64.whl (2.0 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

umadb-0.1.22-cp310-abi3-manylinux_2_28_x86_64.whl (2.0 MB view details)

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

umadb-0.1.22-cp310-abi3-manylinux_2_28_aarch64.whl (1.8 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

umadb-0.1.22-cp310-abi3-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

umadb-0.1.22-cp310-abi3-macosx_10_12_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file umadb-0.1.22.tar.gz.

File metadata

  • Download URL: umadb-0.1.22.tar.gz
  • Upload date:
  • Size: 37.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.10.2

File hashes

Hashes for umadb-0.1.22.tar.gz
Algorithm Hash digest
SHA256 b0ba0105d85ac8da647da5a4c2162610771f04c73af4d5a3ff4d67ce5c127951
MD5 d34c4dc3e01e730c1a8f2b22cb280d81
BLAKE2b-256 8d7abef7ebe354841c04486ed15009a9150ea4ff17ad199c059deb91f075cb68

See more details on using hashes here.

File details

Details for the file umadb-0.1.22-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: umadb-0.1.22-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.10.2

File hashes

Hashes for umadb-0.1.22-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 1bc3bcff7b1e3f1ea5e8c892662e897ef2b4bea157d62926388a49e27e78bba3
MD5 a7935b95a8ff16be46d50d06bce6c6f1
BLAKE2b-256 4cb573480aec1aa58eb0e858d6d4613122f7298024b0fe2aefbb6f696f7d1f92

See more details on using hashes here.

File details

Details for the file umadb-0.1.22-cp310-abi3-win32.whl.

File metadata

  • Download URL: umadb-0.1.22-cp310-abi3-win32.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.10+, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.10.2

File hashes

Hashes for umadb-0.1.22-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 ea3467a1973619be0bec65b8fd4838413c58de4bd17dd50caf02af9cc8e27f74
MD5 71f18b52c95804bdeb8bb47915585af3
BLAKE2b-256 14e9ddde655012655fce1a1eeb26a2129a4d126408844fde5a78c097a4ac89aa

See more details on using hashes here.

File details

Details for the file umadb-0.1.22-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for umadb-0.1.22-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 7c59b84665389afb580c4a2e420022e36d4e550fe72e11b56592c51053fc49d6
MD5 5b4ab7ead6c3d54b699373c23eb71227
BLAKE2b-256 3f3ec6f132c7fae45ce1511935d5a879dba7da3d46380a2aa069d4f93fa866d8

See more details on using hashes here.

File details

Details for the file umadb-0.1.22-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for umadb-0.1.22-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 a4c750d82abe47d13cc1fbc9f23b935ca1b711b3a528679ca692b6c6bef9af0d
MD5 82ce86e41282fc72a582d6f921abce95
BLAKE2b-256 4fb517f72003c1279b218f9c35441b68e51f031cac88a3908562b72ef8666a25

See more details on using hashes here.

File details

Details for the file umadb-0.1.22-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for umadb-0.1.22-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b4451f9fbce9d402b3aa72f0bb69754f57f0b55c54f73ae56d5f531916b3bf50
MD5 04289d13716c14923cde64787948c028
BLAKE2b-256 f872318db080798dc2af27886c82b0e90f286337f6187af3851df0178f5c60ec

See more details on using hashes here.

File details

Details for the file umadb-0.1.22-cp310-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for umadb-0.1.22-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 122f86ce71bbe809d9470da77ecc3acaf0e52e385b46dfe09cd8235fac44caf3
MD5 9ee5f921a6394a823163aa148432f841
BLAKE2b-256 8a97ca7e858b2b12496796043bbc110eece94137c5a7ee04a7c119f2cc6dec20

See more details on using hashes here.

File details

Details for the file umadb-0.1.22-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for umadb-0.1.22-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d9abc02ff017a5fc5cbe53cc6ccf94d01a29986369873dcd69b36a9a4fc6f12b
MD5 f71fa53b56ab5ba0bbf704b6fd2e5cf4
BLAKE2b-256 1291f49c8883b4f65d182577e3a649d3a371ded01ee7b7cf17c50d1853f3fbb6

See more details on using hashes here.

File details

Details for the file umadb-0.1.22-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for umadb-0.1.22-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 076b96beb257afcdc6f8138b77de10d82782fd307e6d095681c52697e2ee5645
MD5 aa2d91ab74796aea2a2fd0a3eeb54746
BLAKE2b-256 81b2987fa2709231d3af1ec9ccd1d1daf2d17d4df34d1fa563a7f59edd32ce2b

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