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

Uploaded CPython 3.10+Windows x86-64

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

Uploaded CPython 3.10+Windows x86

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

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

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

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

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

Uploaded CPython 3.10+macOS 11.0+ ARM64

umadb-0.1.26-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.26.tar.gz.

File metadata

  • Download URL: umadb-0.1.26.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.26.tar.gz
Algorithm Hash digest
SHA256 abf4a36465d433a05ba81ef76b5ae3bbf2a7b874692eb0c82bd9b2a696c887aa
MD5 721e564fc4647f7b39d8b484443c8389
BLAKE2b-256 d1dc56d1ff98f1b8f6cd3020ba58859cceb9939a72f5bf1d100a3bba07c12ea7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: umadb-0.1.26-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.26-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 aacf563313c3c2515bd935d4f830e22a1c73f74c45a1b35da707ebae477a60d1
MD5 4c6426ecdc9bd370e987a8d17955eca1
BLAKE2b-256 507d25adc5854f444f8e0e1f517b8db9b73c2c9d120e8a47f898dd570e040063

See more details on using hashes here.

File details

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

File metadata

  • Download URL: umadb-0.1.26-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.26-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 16550dca817f0eb467a21e69dc6d4b106aef29874cf9747327fca55df91cc187
MD5 9e4b83fe614ab53c3edd8e6cb9873909
BLAKE2b-256 e3ff209efcbabdddc95682f193a876daa233c5a899a4e808d85a740a4bc92637

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.26-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 718b5b84d371fb68e4c441e570de73f65fc993b90598cb006f46d7b5cbe857a3
MD5 9e6b003cd2dc52db11955b3e1281a1a1
BLAKE2b-256 c4ed339d683abbd69dbb2461eb0ea85cb9794c055890e2b9a71c1e596761379b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.26-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 0d741926f7b16cd157ecc1c2917336f4400812a25d97a5bb573c19271357e54c
MD5 84b01cce24d8e8a760aa017d30fc4117
BLAKE2b-256 32849db31bf4886936037663009c66e9644c67a09090a397514b1489a5c10a30

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.26-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 57a84ff87ea76673f4cecd023910b0456626520c97c7a084873285454ba627b7
MD5 b3c51e787b11884e135355a5dbf26749
BLAKE2b-256 a7dd4fee38cd0e10b21c0ffa0490cc89ac739af013d0c843774f508667b7baa3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.26-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 2db8584d6d6df841e9daa3c66a3b94768979052389fd1122dfd134f149db5834
MD5 ac4db508c4c7e1ef71451d9e26b95d5d
BLAKE2b-256 ea7b8eb255bf8abd04c5c8c7bad7070a871801c2020526c6f513680ef17909b0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.26-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 df25ba47a4d5bc7a8c11841891d3df6c6b7b8a8f8acb87180792f69a24ffeeba
MD5 9bf3aed528ddfef4da8ed72e226881fe
BLAKE2b-256 13dbfb20edc984108f2413cb6aedd4a80e0bf5b3d8bbc3b1a62e5b0f60a087a4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.26-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c3db33bce2b4c813634e43687110ff8cb3eb713ae7fd447cdfa46e67e5bf564f
MD5 40ad61daf8c804afd998059a288a9021
BLAKE2b-256 d0f1c2f03b24973eeb83160478f0307cdc47b15e3c3092b86c82172cae56069d

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