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.25.tar.gz (39.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.1.25-cp310-abi3-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.10+Windows x86-64

umadb-0.1.25-cp310-abi3-win32.whl (1.4 MB view details)

Uploaded CPython 3.10+Windows x86

umadb-0.1.25-cp310-abi3-musllinux_1_2_x86_64.whl (2.2 MB view details)

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

umadb-0.1.25-cp310-abi3-musllinux_1_2_aarch64.whl (2.0 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

umadb-0.1.25-cp310-abi3-manylinux_2_28_x86_64.whl (2.0 MB view details)

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

umadb-0.1.25-cp310-abi3-manylinux_2_28_aarch64.whl (1.8 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

umadb-0.1.25-cp310-abi3-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

umadb-0.1.25-cp310-abi3-macosx_10_12_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for umadb-0.1.25.tar.gz
Algorithm Hash digest
SHA256 df26f85e795eac0bd1ec85c744ea6b270bd1c54145f0fd74af07d8ec380e1d05
MD5 a4692ad8e195d3255062d61443411401
BLAKE2b-256 03a4bb854f34f6a426534aee1b87301499d35d531705d648e8b3cba0098c8318

See more details on using hashes here.

File details

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

File metadata

  • Download URL: umadb-0.1.25-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.7 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.25-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 71ae4d7bbc56cdf20e0fa1999cb7dad1642a155f87cbbe92e1268cf410092f5b
MD5 dd2c05d7e1b5b316a03184e78826da22
BLAKE2b-256 a19eddff6d15a5725b317b79bd89ce0d0c0d65498bb7962febf18670e2114d66

See more details on using hashes here.

File details

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

File metadata

  • Download URL: umadb-0.1.25-cp310-abi3-win32.whl
  • Upload date:
  • Size: 1.4 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.25-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 211aba3a1e0a49d461d07660497a68c024701f520dab32c97cef90c887ee1962
MD5 f4bf3bab221f22543d062ff99b16e719
BLAKE2b-256 3c6a0e0b8cc2eeeb5a4575f4a9e76cea2dfae4dc2733cb8d609e1950b6711b0b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.25-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 05f297f0f3e7e00de75f845ab23aa84b90bf2af497e682c664e892c896fe8251
MD5 ba2f1ed53a3cfecbb462f9bf99bb8602
BLAKE2b-256 d527963a148ed5b558bb8ff3afe16560ca7b6170a535d37cb7bfaf778a532043

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.25-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 7d5c9668eb6c4b44e6b4d6755bc1e9e386c5ea14bcab434a24baea9eefa02cd7
MD5 e057d78249a6dd3cc17e5e4db294e56a
BLAKE2b-256 406fea438c4d2c4918b67a438f13105c5b93d3a54a5697056ef71af66ad01f88

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.25-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a510635a04cc0290c79da73535d7caa5438b777379a31574cdd508d31620d76c
MD5 8a7831a89d735772ababe2567dd38ce5
BLAKE2b-256 c7e34f2dafaa3106b7ef18aea144e946949a55b38b6bb70e0cf0a0aeae9c343e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.25-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 28bbb347d972123fbe6017eb20f17dbc8082ebf78402958e74ad40f34d5bd9cf
MD5 3e43c503edde11f9011a97adfa04bfef
BLAKE2b-256 a72b5218cad075ff812d62aaa3a6b8a35b605396486935d562564f42756146ac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.25-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 85c406fe1eba87602cf6edcae8b1b89e0593282f3578f7ea67dddd714f1e6df5
MD5 537d951530c262df04735df68134e4d8
BLAKE2b-256 16cb156d2488ef0c08e1cbdc85531407ab4796bb78ce0d6eef67af95669c8691

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for umadb-0.1.25-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 de59f02beedfca158b4d482faf151eb19a14cadb4cbe3db593155617fa3d0d0a
MD5 f846cb3234bd602599bcbda0ab6e2e14
BLAKE2b-256 8f35c1746f8f8aa25197ef616d2a5976f3067756a9fddd12dc6df2d3398d189d

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