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.28.tar.gz (43.9 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.28-cp310-abi3-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.10+Windows x86-64

umadb-0.1.28-cp310-abi3-win32.whl (1.6 MB view details)

Uploaded CPython 3.10+Windows x86

umadb-0.1.28-cp310-abi3-musllinux_1_2_x86_64.whl (2.4 MB view details)

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

umadb-0.1.28-cp310-abi3-musllinux_1_2_aarch64.whl (2.2 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

umadb-0.1.28-cp310-abi3-manylinux_2_28_x86_64.whl (2.2 MB view details)

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

umadb-0.1.28-cp310-abi3-manylinux_2_28_aarch64.whl (2.0 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

umadb-0.1.28-cp310-abi3-macosx_11_0_arm64.whl (2.0 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

umadb-0.1.28-cp310-abi3-macosx_10_12_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for umadb-0.1.28.tar.gz
Algorithm Hash digest
SHA256 14fefb3487a680881b81bea8ef967c6cffdd0f9e0b4d2594807cc19cb6a465e8
MD5 9036c09481ab135feb48dcc5920ea0f8
BLAKE2b-256 89335ba1a36706e661c4c1d184c75e63c1ace61cfed0ac8994ab0550a929d28a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: umadb-0.1.28-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.9 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.28-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 503db74a1ca214af798177e1911a85183cf22edb0ff43feaf78d549454343fe5
MD5 95381b8493363c4f6351d3720c14ae11
BLAKE2b-256 24d715ad5a346d3c8bf53188d93aae28e3fa01ea1c393d5c5e34748e95888130

See more details on using hashes here.

File details

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

File metadata

  • Download URL: umadb-0.1.28-cp310-abi3-win32.whl
  • Upload date:
  • Size: 1.6 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.28-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 a853234e46971fb16c6f032830cd4a5541c7f3be411710e808010c51b6596a0b
MD5 15b8016a0d9c4bbef460bb429761d781
BLAKE2b-256 4def815ce919174dfb5586119636e03ef3c3170c29957c276411457491ec954f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.28-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f09c15abc9cbd45c05a4bdee44dd550e09413720fe24d9918e121f94847cee5b
MD5 bbe671317fe8860a9753b5ff1c1087aa
BLAKE2b-256 73e13c812bd955d4f5c535a56d9246509f53f760b47b7670fef220a3c5e81bb8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.28-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 88cb9e8e66a3f00f157e4e6601746340060b741977f6d7afc489058e634684d4
MD5 4f212192ad28637bed976949060be8de
BLAKE2b-256 32214d7f5bf4710e65dbeafca4dc687fa93e34a217afcbeca720ff3b6a395295

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.28-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 41faf89813c5478335f2a6f8a46110bf7145165bacfc3146aab2ff9b6a871375
MD5 de6e10d349446570cdb2fb81b19ca981
BLAKE2b-256 f93fa3f1d6b77f4a1a6378a53bd287be48c07e5830b4b6b8ab39560fad7dd8d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.28-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 60676c1a1894596fcff52e3108e2d4fbc5bc7a61d9552e22399cf78871e40a44
MD5 516f5e0bef957faf5311e9c1daddf7c2
BLAKE2b-256 1be0fa30460aa159a3c50aa7c8a4d28fa5609f66beb980377da8af4b6f7d8668

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.28-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f02c705347551d58ba63450f0b60a4c769fa621618064e5cae298f7d69173f6f
MD5 6a24a25d35c6c6b6fa291450930b8bc1
BLAKE2b-256 c308316c119a70aef3e49e549dd4a29b0b32a3971ea1c7851b8c6d276f5cf100

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.28-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 8b43ac214d06617c0b605b90aab92240969b4f7cfd8ce6d6b90663af93303162
MD5 5d008d026167765f9c030114cfe1550d
BLAKE2b-256 314e2763c26dfd201a2ff8e5aa5567084e08d26e728feff5dae9c86cfc431165

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