Skip to main content

Python client for UmaDB event store

Project description

UmaDB Python Client

Official Python client for UmaDB, 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, api_key: str | 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.2.0.tar.gz (46.3 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.2.0-cp310-abi3-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.10+Windows x86-64

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

Uploaded CPython 3.10+Windows x86

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

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

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

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

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

Uploaded CPython 3.10+macOS 11.0+ ARM64

umadb-0.2.0-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.2.0.tar.gz.

File metadata

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

File hashes

Hashes for umadb-0.2.0.tar.gz
Algorithm Hash digest
SHA256 20a1065987d05dadce6cd53467163fef1b5cfa41f59106b5a4effbe1930ad2d2
MD5 31655cdb81b0e4101173a88ee00486b7
BLAKE2b-256 becda3fb6f9696b39c5d93a1a03ccb4f762ff2c7cf059b1eaa98eb5ea8c1d5ea

See more details on using hashes here.

File details

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

File metadata

  • Download URL: umadb-0.2.0-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.2.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 1e232d56f7679709a71e15865d2fcc32f507670d5557ccc78d74d8d21182faeb
MD5 cf6c5b8cf6aa733be15de8b182d3d15f
BLAKE2b-256 b39e738205ea66c3d3a185488b7b1a52c07a4e1be93954e17cd562f061032952

See more details on using hashes here.

File details

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

File metadata

  • Download URL: umadb-0.2.0-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.2.0-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 c9e35a1eb26617da426e634798233b8568525673ee10ad4e76c6b9eb17918207
MD5 eff1f6af052e0129b4c71fd673b993cb
BLAKE2b-256 a1e2ef5774d1d119109d6be8290eccbb193d90a15ee2d061627caadd721cb66b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.2.0-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 daf20b084d77df1bc5b60d17097000a774fb1d5d10d01535da70a9e0618e273d
MD5 7c82a1d5a27eec0b4a879cf4a78b0454
BLAKE2b-256 ca809230cde4a25394a699a792e093edff6f3554ae31bbfaeeb1b44f8d736d4d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.2.0-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 964bbff82ce943611ff732554d366c0e86a477c2c56d7a137d86c11e7100288a
MD5 1774b2fe307327790e59405486de70c6
BLAKE2b-256 f2e5af2073a7353a5a90a9f02f4b484b71ebf86f03259232310477b673b30e5f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.2.0-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7c2ffe6a80d3e1446f1767457adfaa9da339c06060ae8d76277d21e9d03365f5
MD5 9aa86a0195bb3c4268ce5402df25cb87
BLAKE2b-256 c95d61f047657592fd1bcabd511d914b0667ed1ca51d279d1c400aa1b2c69738

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.2.0-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 fb06e93b937660d87bab0ba5d2cad30c0b0460a16e86bbc7ba2c5c86c90a3fcd
MD5 2427c8a777ab52f87e39eb7b35d1efdc
BLAKE2b-256 ada90b5efd1b191a1905fc1849cf05a23154b8f631ab15c90e7de6e94d7c1eb1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.2.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d6ce658a1399f5eec610d719e1d4336e95d12f3e02d202c641fed40b85d9c227
MD5 a12756f73732aa7ebe0d29ead5b86135
BLAKE2b-256 fe7c3ae02f8c03a3559e1c87ed150056ea8e0ffe40211c5f95131ee79bc08e64

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 1bec983fe32fbc731436163a776f558bedbe5dbcb1cf631f50a3129865c88e0e
MD5 01469e51d8e641032fba19b225d36fc1
BLAKE2b-256 e3bab38906c2076b9727a98e7ec98a74d34c70676f20b0812ae07160106b6072

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