gRPC client for EventStore DB
Project description
esdb-py
EventStoreDB Python gRPC client
NOTE: This project is still work in progress
Implemented parts
- secure connection
- basic auth
- other connection options
- multi-node gossip
- keepalive
- async client
- streams
- append
- batch append
- delete
- read
- tombstone
- filtering
- exception handling
- subscriptions
- users
- tbd
Setting things up
- Install poetry
- Create virtualenv (i.e. using pyenv):
pyenv install 3.10.5
pyenv virtualenv 3.10.5 esdb-py
pyenv local esdb-py
- Install deps with
poetry install
- Start eventstore in docker:
make run-esdb
- Run the tests:
pytest tests
Usage:
import datetime
import uuid
from esdb.client.client import ESClient
# For insecure connection without basic auth:
# client = ESClient("localhost:2113", tls=False)
with open("certs/ca/ca.crt", "rb") as fh:
root_cert = fh.read()
client = ESClient("localhost:2111", root_certificates=root_cert, username="admin", password="changeit")
stream = f"test-{str(uuid.uuid4())}"
for i in range(10):
append_result = client.streams.append(
stream=stream,
event_type="test_event",
data={"i": i, "ts": datetime.datetime.utcnow().isoformat()},
)
print("Forwards!")
for result in client.streams.read(stream=stream, count=10):
print(result.data)
print("Backwards!")
for result in client.streams.read(stream=stream, count=10, backwards=True):
print(result.data)
print("Forwards start from middle!")
for result in client.streams.read(stream=stream, count=10, revision=5):
print(result.data)
print("Backwards start from middle!")
for result in client.streams.read(stream=stream, count=10, backwards=True, revision=5):
print(result.data)
Async example:
import asyncio
from esdb.client.client import AsyncESClient
async def append():
client = AsyncESClient("localhost:2113")
result = await client.streams.append("stream", "type", {"x": 1})
assert result.commit_position > 0
async for event in client.streams.read("stream", count=10):
print(event)
asyncio.run(append())
Subscriptions:
from esdb.client.client import ESClient
client = ESClient("localhost:2113", tls=False)
stream = "stream-name"
group = "group-name"
# emit some events to the same stream
for _ in range(10):
client.streams.append(stream, "foobar", b"data")
# create a subscription
client.subscriptions.create_stream_subscription(stream=stream, group_name=group)
# Read from subscription
# This will block and wait for messages
subscription = client.subscriptions.subscribe_to_stream(stream, group)
for event in subscription:
# ... do work with the event ...
# ack the event
subscription.ack([event])
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
esdb-0.1.0.tar.gz
(62.6 kB
view details)
Built Distribution
esdb-0.1.0-py3-none-any.whl
(78.5 kB
view details)
File details
Details for the file esdb-0.1.0.tar.gz
.
File metadata
- Download URL: esdb-0.1.0.tar.gz
- Upload date:
- Size: 62.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.14 CPython/3.10.5 Darwin/21.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9329e48fc804f9fb71a4c632533098eb6d52e836ddddb06ae0ae48397184585 |
|
MD5 | 4a028fa0ef4d86f938c9ff47cf52a84a |
|
BLAKE2b-256 | 4e96c30cf815fb75ca99a5d801e898d1077867add0edcaf3aa4bb2773f464bd9 |
File details
Details for the file esdb-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: esdb-0.1.0-py3-none-any.whl
- Upload date:
- Size: 78.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.14 CPython/3.10.5 Darwin/21.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 958a72b6c614a4c1cbadbd8d4236e5aea0bfdba019456a01be1cbc8914ec4d70 |
|
MD5 | a743b917c62de0c46a68e26776afa917 |
|
BLAKE2b-256 | 1445fc00f70ff26c2e7900041d89330930e0bde02b73b737cfb2f16f1fea93ad |