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.24.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.24-cp310-abi3-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.10+Windows x86-64

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

Uploaded CPython 3.10+Windows x86

umadb-0.1.24-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.24-cp310-abi3-musllinux_1_2_aarch64.whl (2.0 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

umadb-0.1.24-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.24-cp310-abi3-manylinux_2_28_aarch64.whl (1.8 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

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

Uploaded CPython 3.10+macOS 11.0+ ARM64

umadb-0.1.24-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.24.tar.gz.

File metadata

  • Download URL: umadb-0.1.24.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.24.tar.gz
Algorithm Hash digest
SHA256 3b4e49fbbe086fb9ab3d5372e823afbb4b41f0d14e25f20bc1312b758762199f
MD5 1b2d3dd72ab77bb1d81e4518fc06d108
BLAKE2b-256 8368c1c267bb2d85fb7a09593d734c79a55c382841281b2ae8f5afb35e382037

See more details on using hashes here.

File details

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

File metadata

  • Download URL: umadb-0.1.24-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.24-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 2d731a395e1409130bc1952c46e197467b876acdff986b09e68eece383f727c2
MD5 b7fdcdafaba487dba24e99039df1f328
BLAKE2b-256 45b226baa7e94070e479ecaf2fbccd34cfc995e3871d2c019e547b2d3d94720d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: umadb-0.1.24-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.24-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 200bab3b645f6952205d3c4c6b129b995b157bb3cf87267bd9032dff792afce3
MD5 48fd93ba4fa219b820de0970d9d7d981
BLAKE2b-256 ec8eacffa0984b591804c2c6d94548c4db11d47988143841acceb92209115938

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.24-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 4eb24531aaaea759323efa65e0a7f25c11965088dd048d2ff5ed4fdd293e4499
MD5 ae581ea3e64d3a4691af59e311d4f198
BLAKE2b-256 6efebf22bb79c4be074585ba4d1816a4bd5b9f1e162da3d24589fd9ba1e91804

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.24-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 7d71bee4f12a308a44ca29b69b28c7d21efb5b2151101c7935652eb088733d84
MD5 66f7f3a227a0c9e0227fc9636953c071
BLAKE2b-256 5a767163f0bc4b13be800dc0438e53cff1115f816a9202079fc8517db1280daf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.24-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6ac6ef00c7646d314345925d69f6f0f61391a41ed5a71dd31bf94e6f9ffb1a5c
MD5 6b5ae84d202c9f6fbddf5eb7762307c9
BLAKE2b-256 aa4672977e28be683c4d1479adc1935d54ae8c70c785da83383febd8a8ff853e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.24-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 4fa7bec39a47f2825faedaf1b7bf034d109bd707afb78cf6e0429a26fe16d06b
MD5 17b134c0a9ef1c191e21621610fa4db9
BLAKE2b-256 9fc04b5fb31109f6fe4afc50163082dd3a80796473181b94004a1a87ebad9ccb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.24-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 51c2295945effed55efac2aa4fe54e843f7c4194a34f53f6ce4a8d2f13671d08
MD5 bc0f7841561488dc647f79b1eb40c68c
BLAKE2b-256 ee9fd1c1bebd6051c4852d46d5e3549956a65887cc090e83113010d2f165a663

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.24-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5877b0cf9713225d49e4b421e6ae04beeee06447b1ec594cf13fafce43c6f6d0
MD5 976f7895d78795e9a39252e9928d6caa
BLAKE2b-256 9cb8e6830e3b65730253da40cea59fcbc3a7d0948999c06043333ac92d41c02a

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