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, 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.1.30.tar.gz (45.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.30-cp310-abi3-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.10+Windows x86-64

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

Uploaded CPython 3.10+Windows x86

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

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

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

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

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

Uploaded CPython 3.10+macOS 11.0+ ARM64

umadb-0.1.30-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.30.tar.gz.

File metadata

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

File hashes

Hashes for umadb-0.1.30.tar.gz
Algorithm Hash digest
SHA256 719f3c7066e2b394bea909a5d0fb6fcbc45970c38eca9be3b8462ef75bbcf750
MD5 a334521762245a482cc1fd0c28e120bd
BLAKE2b-256 855932533b7c79030c5a0f5b2f81819fc68bf54120dd9edc489f31748801323b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: umadb-0.1.30-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.30-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 187cadf7d10f3f9ef01d1ebb83ec246c2a5772de2ff3f119fae84f15c16356ad
MD5 8665056b43343a055dd4ba9c7e9715f6
BLAKE2b-256 384e5765c7682d1669eb2560db602cdc207d3c656543c9ebbc2d61b1fc7064f6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: umadb-0.1.30-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.30-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 4ba797cb736fbe538ace1e36b5c2076b8dd929116421b4eae2be4570e3454125
MD5 73a106f4dcccd2e38eeedadb8e3debe6
BLAKE2b-256 136152e5d31102da3af1a6f6623548ea8c4421834b23c80cf05131bc402ced58

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.30-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 bbd134c1ef6db613c67da3cfd7e11c68424d9b7d8406aec13291ca8e8efbdac1
MD5 035211433fe7fff159252a26faf2875d
BLAKE2b-256 435a5290da73559420511742f0827fc287c10dda87256310be5f4b1de8a28d99

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.30-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 4543b63b7e779d0290975bf5488629cb59b4e263549d06fcb51c36e9963a4a22
MD5 8b0a46573a371932aa2643e46aae2297
BLAKE2b-256 cee835b3aa34d80d017062fffe0c47d96ff847ec6da29a749a0afc3db09262ee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.30-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 85033f783010f8bc87142a3b5ca8b46df969fe28ae5b8eb12e6223b9d931ba0c
MD5 06730791062236c09bc5dac5ab94ee75
BLAKE2b-256 cdf86e042837399c3a18368dbf9e8ff231710def025412be90cb791a94b6f5d7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.30-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 4b0335a38ab735953ab730a2e7fd7550c1b503a5cce4dffa139d825df05f5b85
MD5 d8929e879a77e5601a070a0555b93275
BLAKE2b-256 59d0007af706bac116bd303304bc7edfe3c54067d6aa99125d75afbb1aea04fb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.30-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 734e964394f4510b76c2014f3ea08b278dff43414612c2ba873b54c0c1b91b2e
MD5 6186a3847eb4b21f10765097b1461cdb
BLAKE2b-256 d1a661302614f365859be77383ec16b3cd977445db7dd743e1372646f3b2518e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.30-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 433da8de689fe779247c98c1607596260c3510eb34e0b74957da366c2fcbda88
MD5 c13e2361c64ac7a54b49b23e21a6b136
BLAKE2b-256 f8c787f08ddaddfce5e548bb418c44c98321b5910fad472dfdec21cfb7f2e17c

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