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}")

print(f"Last known position: {events.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}")

print(f"Last known position: {events.head()}")

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"
)

API key

from umadb import Client

# Connect with API key
client = Client(
    url="https://secure-server:50051",
    ca_path="/path/to/ca.pem",
    api_key="umadb:example-api-key-4f7c2b1d9e5f4a038c1a"
)

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

Uploaded CPython 3.10+Windows x86-64

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

Uploaded CPython 3.10+Windows x86

umadb-0.1.29-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.29-cp310-abi3-musllinux_1_2_aarch64.whl (2.2 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

umadb-0.1.29-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.29-cp310-abi3-manylinux_2_28_aarch64.whl (2.0 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

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

Uploaded CPython 3.10+macOS 11.0+ ARM64

umadb-0.1.29-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.29.tar.gz.

File metadata

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

File hashes

Hashes for umadb-0.1.29.tar.gz
Algorithm Hash digest
SHA256 70a444bcdd712825bd225932d300412a8b808dff8a3da6a681d28112c428ff1e
MD5 c07822dadd73f7ad572a4df0a4150f0d
BLAKE2b-256 ce2f8f4c85eea48676177394b0077f1138e7b51381107ea535011a00c6cac386

See more details on using hashes here.

File details

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

File metadata

  • Download URL: umadb-0.1.29-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.29-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 39aaaaf33272244a4a4e0c4900bd720414ce6d8f5b2b60e9f92144c2fa6789b6
MD5 18434901923b9ff132dfc9b886d7b194
BLAKE2b-256 6b899e06ca2db52147eb43176a407a54abfff01723a419ab2daf4696c5ef556a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: umadb-0.1.29-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.29-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 652bcb02ed1e3ddda3230c75db4bc646e3371f003347c6251548995a9b40349f
MD5 602494d980b4a6973dcb6b057f2c3bc6
BLAKE2b-256 0bdfd55deee83180c9f0314a6eb84b72ffa8967439a47e380eb1db85c821c1a9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.29-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 13acdba176de5bf0464ff25ceae07536ead1a1db03e3da56d55c3c696034f4d8
MD5 20a689b224de71d94a105f0c8d908a3c
BLAKE2b-256 b44513621d82f03fcf3f66d5722746ccf766995726833167ee56e5faf963f8d3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.29-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 f5f28f222e35ec143346d0e556835e20db3b910025696441422ca9067b295efc
MD5 fe9a2a867ef3da3e4a0f1b702c5adfdd
BLAKE2b-256 6d42d2502e084d7a641f74333db1423a842de2025745a493f0020118b4bc8ed0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.29-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 443472cae30dfe60511e868234ba458fc049d4f6fa59b5b47b850b1a0fc6ff35
MD5 d64b094d2c9ff486f79e2be6368c9a70
BLAKE2b-256 a3ac8ecab95805b684d5117573d9b4fc43e3877003941c85426e12aa17b79409

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.29-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 c20344cd4a8da8cc49ba0477c8e01eb4fbbfb373bb2280f4313ef008dbe42f66
MD5 9171b1a80899bdcc4761d24a075e4ddb
BLAKE2b-256 25b3f2f1137a4f0d41c45bf0c3797a5b80c631941548f19bc88009f7016e5655

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.29-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 72553f754f268e47dec74529ddf059aaed010e569eb348586135fa160adcc4e0
MD5 b48d149760e19148fa990a7282678038
BLAKE2b-256 b32c391c52d8ef9dc95349eabb5f7450c4ac84b7b6659d69ff8066cb3d676467

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.29-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 2910a4a4d20c5c2539ba14816cf25dbd15a8d20f0247066c011e78a12077386e
MD5 339c24ff0e09e0874037d5d22713a259
BLAKE2b-256 fb46c27076932997759f72b86f5e2c266b38c86bcceb6cfe89a20f35541bb421

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