Metadata-Version: 2.4
Name: umadb
Version: 0.8.2
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Programming Language :: Rust
Classifier: Topic :: Database
Summary: Python client for UmaDB event store
Keywords: event-store,grpc,client,database
Home-Page: https://umadb.io
Author-email: John Bywater <john.bywater@appropriatesoftware.net>
License: MIT OR Apache-2.0
Requires-Python: >=3.11
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Homepage, https://umadb.io
Project-URL: Repository, https://github.com/umadb-io/umadb

# UmaDB Python Client

The Python package `umadb` provides a Rust-powered [UmaDB](https://umadb.io/) server, and a synchronous Python client
for reading and appending events via the [gRPC API](https://umadb.io/grpc-api.html).

It is adapted into the Python [eventsourcing](https://eventsourcing.readthedocs.io/en/stable/topics/dcb.html)
library via the [eventsourcing-umadb](https://pypi.org/project/eventsourcing-umadb/) package.

## Installation

To install with pip, create and activate a virtual environment:

```bash
pip install umadb
```

To add `umadb` to your project managed with `uv`:

```bash
uv add umadb
```

To add `umadb` to your project managed with `poetry`:

```bash
poetry add umadb
```

## Running the UmaDB Server

This Python package installs a Python script named `umadb` that starts the UmaDB server.

```bash
umadb
```

Alternatively, you can run the server with Python using the installed package directly.

```bash
python -m umadb
```

Alternatively, you can start the server with `uvx` (no pre-install required).

```bash
uvx umadb
```

Similarly, you can start the server with `pipx` (no pre-install required).

```bash
pipx run umadb
```

### Server options

The server supports the following command-line options:

- `--listen`
- `--db-path`
- `--tls-cert`
- `--tls-key`
- `--api-key`
- `--read-method`
- `--page-cache-max-pages`
- `--page-cache-max-mb`
- `--zero-fill-pages`

### Environment variables

If command-line options are not provided, the script reads these environment variables:

- `UMADB_LISTEN`
- `UMADB_DB_PATH`
- `UMADB_TLS_CERT`
- `UMADB_TLS_KEY`
- `UMADB_API_KEY`
- `UMADB_READ_METHOD`
- `UMADB_PAGE_CACHE_MAX_PAGES`
- `UMADB_PAGE_CACHE_MAX_MB`
- `UMADB_ZERO_FILL_PAGES`

Boolean environment variable values accepted for `UMADB_ZERO_FILL_PAGES` are:
`1`/`0`, `true`/`false`, `yes`/`no`, and `on`/`off` (case-insensitive).

Option precedence is:

1. Explicit command-line argument
2. Environment variable
3. Built-in default

### Example

```bash
UMADB_LISTEN=0.0.0.0:50051 UMADB_DB_PATH=./uma.db umadb
```

## Connecting to UmaDB

Use the `Client` class as the main entry point for connecting to an UmaDB server.

```python
class Client(
    url: str,
    ca_path: str | None = None,
    tls_domain: str | None = None,
    api_key: str | None = None,
    batch_size: int | None = None,
):
    ...
```

### Parameters

| Name         | Type        | Description                                                                                                                                         |
|--------------|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|
| `url`        | `str`       | Required connection string. If the argument starts with `https` or `grpcs`, a secure TLS channel is created; otherwise an insecure channel is used. |
| `ca_path`    | `str\|None` | Optional path to a PEM-encoded root/CA certificate for TLS connections (useful for self-signed servers).                                            |
| `tls_domain` | `str\|None` | Optional override of the domain name used for TLS certificate verification and SNI.                                                                 |
| `api_key`    | `str\|None` | Optional API key used for authenticating with the server.                                                                                           |
| `batch_size` | `int\|None` | Optional hint for how many events to buffer per batch when reading. The server may cap this; a sensible default is used if unset.                  |

### Connection Examples

```python
from umadb import Client

# Insecure (no TLS)
client = Client("http://localhost:50051")

# Secure with TLS (system CAs)
client = Client("https://example.com:50051")

# Secure with TLS using self-signed CA
client = Client(
    url="https://localhost:50051",
    ca_path="server.pem",
)

# TLS + API key
client = Client(
    url="https://example.com:50051",
    ca_path="server.pem",
    api_key="umadb:example-api-key-4f7c2b1d9e5f4a038c1a",
)

# TLS + API key + batch size hint
client = Client(
    url="https://example.com:50051",
    ca_path="server.pem",
    api_key="umadb:example-api-key-4f7c2b1d9e5f4a038c1a",
    batch_size=1000,
)
```

## Appending Events

The `Client.append()` method writes new events to an UmaDB server.

```python
def append(
    self,
    events: list[Event],
    condition: AppendCondition | None = None,
    tracking_info: TrackingInfo | None = None,
) -> int:
    ...
```

The `Client.append()` method can be used to append new `Event` instances to UmaDB atomically, with an optional append
condition, and optional tracking information. Events are written in order.

Conditional appends with event UUIDs are idempotent. The server does not enforce uniqueness of events IDs.

### Parameters

| Name            | Type                    | Description                                                                        |
|-----------------|-------------------------|------------------------------------------------------------------------------------|
| `events`        | `list[Event]`           | The list of events to append. Each includes an event type, tags, and data payload. |
| `condition`     | `AppendCondition\|None` | Optional append condition to ensure no conflicting writes occur.                   |
| `tracking_info` | `TrackingInfo\|None`    | Optional tracking information – for event-processing components only.              |

### Return Value

Returns the sequence number (`int`) of the last successfully appended event from this operation. This
value can be used to wait for downstream event-processing components in a CQRS system to become up-to-date.

### Example

```python
import uuid

from umadb import AppendCondition, Client, Event, IntegrityError, Query, QueryItem

client = Client("http://localhost:50051")

# Define a consistency boundary (same query you use while reading)
cb = Query(items=[QueryItem(types=["example"], tags=["tag1", "tag2"])])

# Read to build decision model
read_resp = client.read(query=cb)
for r in read_resp:
    print(f"Existing event at {r.position}: {r.event}")

last_known = read_resp.head()
print("Last known position:", last_known)

# Produce a new event with a UUID (for idempotent retries) and some metadata
ev = Event(
    event_type="example",
    tags=["tag1", "tag2"],
    data=b"Hello, world!",
    uuid=uuid.uuid4(),
    metadata={"source": "readme", "correlation_id": str(uuid.uuid4())},
)

# Append with an optimistic condition: fail if conflicting events exist after last_known
cond = AppendCondition(fail_if_events_match=cb, after=last_known)
position1 = client.append([ev], condition=cond)
print("Appended at:", position1)

# Conflicting append should raise an error (e.g. ValueError)
try:
    client.append(
        [
            Event(
                event_type="example",
                tags=["tag1", "tag2"],
                data=b"Hello, world!",
                uuid=uuid.uuid4(),
            )
        ],
        condition=cond,
    )
except IntegrityError as e:
    print("Conflicting event was rejected:", e)

# Idempotent retry with same event UUID and condition should return same commit position
position2 = client.append([ev], condition=cond)
assert position1 == position2
print("Idempotent retry returned position:", position2)
```

## Reading Events

The `Client.read()` method returns recorded events from an UmaDB server.

```python
def read(
    self,
    query: Query | None = None,
    backwards: bool = False,
    after: int | None = None,
    limit: int | None = None,
) -> ReadResponse:
    ...
```
The `Client.read()` method can be used both for constructing decision models in a domain layer, and for projecting events into
materialized views in CQRS. An optional `Query` can be provided to select by tags and types.

### Parameters

| Name        | Type          | Description                                                                                                                                         |
|-------------|---------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `query`     | `Query\|None` | Optional structured query to filter events (by tags, event types, etc).          |
| `backwards` | `bool`        | If `True` events will be read backwards.                                           |
| `after`     | `int\|None`   | Read events after this sequence number, or before if `backwards` is `True`. |
| `limit`     | `int\|None`   | Optional cap on the number of events to retrieve.                                                                                                      |

### Return Value

Returns an iterable "read response" from which SequencedEvent instances can be obtained.

The response's `head()` method will return a sequence number that is "safe" for use as an `after` value in append
conditions, according to these rules:

* Read everything: `head()` returns the position of the last recorded event in the database.
* Read forwards using an `after` value: `head()` returns `None`.
* Read forwards with a `limit`: `head()` returns the position of the last recorded event received from the server.
* Read backwards with a `limit`: `head()` returns `None`.
* Read backwards using an `after` value: `head()` returns the position before the given value.

### Example

```python
from umadb import Client, Query, QueryItem

client = Client("http://localhost:50051")

# Filter by type(s) and tag(s)
q = Query(items=[QueryItem(types=["example"], tags=["tag1", "tag2"])])

resp = client.read(query=q, backwards=False, after=None, limit=None)
for item in resp:
    print(f"Got event at position {item.position}: {item.event}")

last_known = resp.head()
print("Last known position:", last_known)
```

## Subscriptions

The `Client.subscribe()` method returns recorded events from an UmaDB server,
keeping the stream open to deliver future events as they arrive.


```python
def subscribe(
    self,
    query: Query | None = None,
    after: int | None = None,
) -> Subscription:
    ...
```
The `Client.subscribe()` method can be used for projecting events into
materialized views in CQRS. An optional `query` can be provided to select
by tags and types.

### Parameters

| Name    | Type          | Description                                                                                           |
|---------|---------------|-------------------------------------------------------------------------------------------------------|
| `query` | `Query\|None` | Optional structured query to filter events (by tags, event types, etc).                               |
| `after` | `int\|None`   | Read events *after* this sequence number. Only events with a larger sequence number will be returned. |

### Return Value

Returns an iterable "subscription" instance from which `SequencedEvent` instances can be obtained.

### Example

```python
from umadb import Client, Query, QueryItem

client = Client("http://localhost:50051")

# Filter by type(s) and tag(s)
q = Query(items=[QueryItem(types=["example"], tags=["tag1", "tag2"])])

# Subscribe to all events
for se in client.subscribe():
    print("New event:", se.position, se.event)
    # Break for demo purposes
    break
```

## Getting Head Position

The `Client.head()` method returns the position of the last event recorded in an UmaDB server.

```python
def head(self) -> int | None: ...
```

The `Client.head()` method can be used for counting the number of recorded events in the database, or for determining the position
of the last recorded event when subscribing only to new events.

### Return Value

Returns the position (`int`) of the last recorded event in the event store, or `None` if no events have been recorded yet.


## Getting Tracking Info

The `Client.get_tracking_info()` method returns the last recorded position in an upstream sequence of events.

```python
def get_tracking_info(self, source: str) -> int | None: ...
```

The `Client.get_tracking_info()` method can be used when starting or resuming an
event-processing component. The event-processing component will start by requesting new events from the upstream
sequence after this position. The position of an upstream event that has been processed successfully can be recorded
atomically when appending new events generated by processing that event.

### Parameters

| Name        | Type  | Description           |
|-------------|-------|-----------------------|
| `source`    | `str` | Upstream source name. |

Returns the last recorded upstream position (`int`), or `None` if the sequence name is not found.

## Checking Health

The `Client.check_health()` method performs a unary health check against the server using the standard gRPC Health Checking protocol.

```python
def check_health(self, service: str = "") -> ServingStatus: ...
```

The `Client.check_health()` method queries the health status of the server or a specific service.

### Parameters

| Name      | Type  | Description                                                                                                                                           |
|-----------|-------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| `service` | `str` | Optional service name to check (default `""`). Use an empty string for overall server health, or a fully-qualified gRPC service name (e.g. `"umadb.v1.DCB"`). |

### Return Value

Returns the current `ServingStatus` of the server or service.

### Example

```python
import umadb

client = umadb.Client("http://localhost:50051")

# Check overall server health
status = client.check_health()
assert status == umadb.ServingStatus.SERVING
print("Overall server health:", status)

# Check health of a specific service
dcb_status = client.check_health("umadb.v1.DCB")
print("DCB service health:", dcb_status)
```


## Watching Health

The `Client.watch_health()` method opens a server-streaming health watch for the given service name.

```python
def watch_health(self, service: str = "") -> HealthWatch: ...
```

The `Client.watch_health()` method opens a stream of health status updates for the server or a specific service.
The server immediately sends the current serving status and then pushes updates whenever the status changes.
The returned `HealthWatch` iterator yields status updates until cancelled or the stream ends.

### Parameters

| Name      | Type  | Description                                                                                                                                           |
|-----------|-------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| `service` | `str` | Optional service name to watch (default `""`). Use an empty string for overall server health, or a fully-qualified gRPC service name (e.g. `"umadb.v1.DCB"`). |

### Return Value

Returns a `HealthWatch` iterator over `ServingStatus` values.

### Example

```python
import umadb

client = umadb.Client("http://localhost:50051")

# Watch overall server health updates
try:
    watch = client.watch_health()
    for status in watch:
        if status == umadb.ServingStatus.SERVING:
            print("Server is ready to handle requests")
        elif status == umadb.ServingStatus.NOT_SERVING:
            print("Server is shutting down")
    else:
        print("Server shutdown gracefully")
except umadb.TransportError:
    print("Lost connection to the server abruptly!")
```

## Event

An `Event` represents a single event either to be appended or already stored in the event log.

| Field        | Type              | Description                                                   |
|--------------|-------------------|---------------------------------------------------------------|
| `event_type` | `str`             | The event’s logical type (e.g. `"UserRegistered"`).           |
| `tags`       | `list[str]`       | Tags assigned to the event (used for filtering and indexing). |
| `data`       | `bytes`           | Binary payload associated with the event.                     |
| `uuid`       | `UUID\|None`       | Unique event ID.                                              |
| `metadata`   | `dict[str, str]`  | Optional string key/value pairs stored alongside the event.   |

Idempotent support for append operations is activated by setting a UUID on appended events.

`event_type` and each tag in `tags` may be up to 65535 bytes long. Appending an
event with a longer type or tag fails with a validation error (`ValueError`).

`metadata` is for information *about* the event (provenance, correlation IDs, schema version, etc.)
rather than the event payload itself. It is stored and returned unchanged, and is not indexed or
matched by queries. It defaults to an empty dict when omitted. Each metadata key and value may be
up to 65535 bytes long; appending an event with a longer key or value fails with a validation error.

Include in:
* Append requests when writing new events to the store.

Included in:
* `SequencedEvent` objects when the server responds to read requests.

Matched by:
* `QueryItem` during `read()` and `append()` operations.


## Append Condition

An `AppendCondition` causes an append request to fail if events match its `Query`, optionally after
a sequence number.

| Field                  | Type        | Description                   |
|------------------------|-------------|-------------------------------|
| `fail_if_events_match` | `Query`     | Query for conflicting events. |
| `after`                | `int\|None` | Sequence number.              |

Include in:
* Append requests to define optimistic concurrent control.

To implement a consistency boundary, command handlers can use the same `Query` used when
reading events as the value of `fail_if_events_match`, and the "head" sequence
number received from the read response as the value of `after`.


## Tracking Info

A `TrackingInfo` instance indicates the source and position of an upstream event.

| Field      | Type  | Description               |
|------------|-------|---------------------------|
| `source`   | `str` | Upstream sequence name.   |
| `position` | `int` | Upstream sequence number. |

Include in:
* Append requests when recording the results of processing an upstream event.

To implement exactly-once semantics in event-processing components, pull events from an upstream
source after the last recorded position, then record the upstream positions
of upstream events along with new state that results from processing those events.
By processing event sequentially in this way, each event will be processed at least once. And by
recording tracking information along with new state, the new state will be recorded at most once.
The combination of "at least once" processing and "at most once" recording gives "exactly once"
semantics from the point of view of consumers of the recorded state.


## Query

A `Query` defines criteria for selecting events in the event store.

| Field   | Type              | Description                                |
|---------|-------------------|--------------------------------------------|
| `items` | `list[QueryItem]` | A list of selection criteria (logical OR). |

An `Event` is selected if any `QueryItem` matches or the `items` field is empty.

Include in:
* Read requests to select events returned by the server.
* An `AppendCondition` to select conflicting events.


## Query Item

A `QueryItem` defines a criterion for matching events.

| Field   | Type        | Description                       |
|---------|-------------|-----------------------------------|
| `types` | `list[str]` | List of event types (logical OR). |
| `tags`  | `list[str]` | List of tags (logical AND).       |

A `QueryItem` will match an `Event` if:
* one of its `types` matches the `Event.event_type` or its `types` field is empty; AND
* all of its `tags` match one of the `Event.tags` or its `tags` field is empty.


## Sequenced Event

A `SequencedEvent` represents a recorded `Event` along with its assigned sequence number.

| Field      | Type    | Description          |
|------------|---------|----------------------|
| `position` | `int`   | The sequence number. |
| `event`    | `Event` | The recorded event.  |

Included in:
* Read responses when the server responds to read requests.


## Serving Status

The `ServingStatus` enum represents the health status of the server or a service returned by `check_health()` and `watch_health()`.

| Name              | Description                                                                            |
|-------------------|----------------------------------------------------------------------------------------|
| `UNKNOWN`         | The serving status is unknown.                                                         |
| `SERVING`         | The server is ready to handle requests.                                                |
| `NOT_SERVING`     | The server is not ready to handle requests.                                            |
| `SERVICE_UNKNOWN` | The requested service is not known, used by `watch_health()` only. |


## Health Watch

A `HealthWatch` iterator provides a stream of `ServingStatus` updates.

| Method     | Description                                                                                                        |
|------------|--------------------------------------------------------------------------------------------------------------------|
| `__iter__` | Returns the iterator itself.                                                                                       |
| `__next__` | Returns the next `ServingStatus` update, or raises `StopIteration` when the stream ends.         |
| `cancel()` | Explicitly cancels this individual health watch stream. Iterating after cancellation raises `CancelledByUserError`. |


## Error Handling

The Python client raises Python exceptions on error:

- Server start failure: `ServerStartError`
- Integrity/condition failure: `IntegrityError`
- Streaming response cancelled by server: `CancelledByServerError`
- Streaming response cancelled by client: `CancelledByUserError`
- Transport/connection errors: `TransportError`
- Authentication failures: `AuthenticationError`
- Invalid argument errors: `ValueError`
- Other errors: `RuntimeError`, `OSError`, `CorruptionError`

Your application should catch these as appropriate.

## Complete Example

```python
import uuid

from umadb import AppendCondition, Client, Event, IntegrityError, Query, QueryItem

# Connect to the gRPC server (TLS + API key)
client = Client(
    url="http://localhost:50051",
)

# Define a consistency boundary
cb = Query(items=[QueryItem(types=["example"], tags=["tag1", "tag2"])])

# Read events for a decision model
read_response = client.read(query=cb)
for result in read_response:
    print(f"Got event at position {result.position}: {result.event}")

# Remember the last-known position
last_known_position = read_response.head()
print("Last known position is:", last_known_position)

# Create an event with a UUID to enable idempotent append, and some metadata
event = Event(
    event_type="example",
    tags=["tag1", "tag2"],
    data=b"Hello, world!",
    uuid=uuid.uuid4(),
    metadata={"source": "readme", "correlation_id": str(uuid.uuid4())},
)

# Append event within the consistency boundary
condition = AppendCondition(fail_if_events_match=cb, after=last_known_position)
commit_position1 = client.append([event], condition=condition)
print("Appended event at position:", commit_position1)

# Append conflicting event — expect an error
try:
    conflicting_event = Event(
        event_type="example",
        tags=["tag1", "tag2"],
        data=b"Hello, world!",
        uuid=uuid.uuid4(),  # different UUID
    )
    client.append([conflicting_event], condition=condition)
except IntegrityError as e:
    print("Conflicting event was rejected:", e)

# Idempotent retry — same event ID and condition
print("Retrying to append event at position:", last_known_position)
commit_position2 = client.append([event], condition=condition)
assert commit_position1 == commit_position2
print("Append returned same commit position:", commit_position2)

# Subscribe to all events for a projection
for ev in client.subscribe():
    print(f"Processing event at {ev.position}: {ev.event}")
    if ev.position == commit_position2:
        print("Projection has processed new event!")
        break
```

## Example with Tracking

```python
import uuid

from umadb import (
    AppendCondition,
    Client,
    Event,
    IntegrityError,
    Query,
    QueryItem,
    TrackingInfo,
)

# Connect to the gRPC server (TLS + API key)
client = Client(
    url="http://localhost:50051",
)

# Get last processed upstream event position
last_processed_position = client.get_tracking_info("upstream")

# Pull next unprocessed upstream event...
next_upstream_event_position = 1 + (last_processed_position or 0)

# Construct tracking information from next unprocessed event
tracking_info = TrackingInfo("upstream", next_upstream_event_position)

# Define a consistency boundary
cb = Query(items=[QueryItem(types=["example"], tags=["tag1", "tag2"])])

# Read events for a decision model
read_response = client.read(query=cb)
for result in read_response:
    print(f"Got event at position {result.position}: {result.event}")

# Remember the last-known position
last_known_position = read_response.head()
print("Last known position is:", last_known_position)

# Create an event with a UUID to enable idempotent append
event = Event(
    event_type="example",
    tags=["tag1", "tag2"],
    data=b"Hello, world!",
    uuid=uuid.uuid4(),
)

# Append event within the consistency boundary
condition = AppendCondition(fail_if_events_match=cb, after=last_known_position)
commit_position1 = client.append(
    [event], condition=condition, tracking_info=tracking_info
)
print("Appended event at position:", commit_position1)

# Idempotent retry — same event ID and condition
print("Retrying to append event at position:", last_known_position)
commit_position2 = client.append(
    [event], condition=condition, tracking_info=tracking_info
)
assert commit_position1 == commit_position2
print("Append returned same commit position:", commit_position2)

# Check tracking information
assert tracking_info.position == client.get_tracking_info("upstream")

# Unconditional append with conflicting tracking information — expect an error
try:
    conflicting_event = Event(
        event_type="example",
        tags=["tag1", "tag2"],
        data=b"Hello, world!",
        uuid=uuid.uuid4(),  # different UUID
    )
    client.append([conflicting_event], condition=None, tracking_info=tracking_info)
except IntegrityError as e:
    print("Conflicting event was rejected:", e)
```

## Notes

- Python client is synchronous and blocking; if you need async integration, run client calls in a thread pool or use an async worker that offloads to threads.
- Event data is binary (`bytes`). Use a consistent serialization (e.g., JSON serialized to UTF-8 bytes, protobuf, msgpack) for your domain.
- API keys must match the server configuration.
- For TLS with self-signed certs, pass `ca_path` with your root/CA certificate.


## Testing

The `umadb` package includes helpers for running isolated tests against a temporary UmaDB server. Each helper starts a fresh server on an ephemeral port using a temporary database directory and shuts it down automatically when the test finishes.

### Using `pytest`

When `umadb` is installed, its `pytest` plugin is discovered automatically—no imports or configuration required. Two fixtures are available:

* **`umadb_client`** — yields a connected `Client` instance and closes it on teardown.
* **`umadb_server_url`** — yields the server URI (e.g., `http://127.0.0.1:<port>`) if you want to construct your own `Client`.

```python
from umadb import Client, Event


def test_append_and_read(umadb_client: Client) -> None:
    event = Event(event_type="UserCreated", data=b"user data", tags=["user:123"])
    position = umadb_client.append([event])
    events = list(umadb_client.read())

    assert len(events) == 1
    assert events[0].position == position

```

*(To disable the auto-loaded plugin, run `pytest -p no:umadb`.)*

### Using `unittest` (or plain Python)

The `umadb.testing` module provides context managers with no `pytest` dependency:

* **`umadb_client()`** — starts a temporary server and yields a connected `Client`.
* **`umadb_server_url()`** — starts a temporary server and yields its connection URI.

```python
import unittest
from umadb import Event
from umadb.testing import umadb_client


class TestUmaDb(unittest.TestCase):
    def setUp(self) -> None:
        self.client = self.enterContext(umadb_client())

    def test_append_and_read(self) -> None:
        event = Event(event_type="UserCreated", data=b"user data", tags=["user:123"])
        position = self.client.append([event])
        events = list(self.client.read())

        self.assertEqual(len(events), 1)
        self.assertEqual(events[0].position, position)

```


## License

Licensed under either of:

- Apache License, Version 2.0 ([LICENSE-APACHE](../LICENSE-APACHE))
- MIT license ([LICENSE-MIT](../LICENSE-MIT))

at your option.

