Depeche DB
A library for building event-based systems on top of PostgreSQL
Documentation: https://depeche-py.github.io/depeche-db/
Source code: https://github.com/depeche-py/depeche-db
Depeche DB is modern Python library for building event-based systems
Key features:
- Message store with optimistic concurrency control & strong ordering guarantees
- Subscriptions with "at least once" semantics
- Parallel processing of (partitioned) subscriptions
- No database polling
Requirements
Python 3.9+ SQLAlchemy 1.4 or 2+ PostgreSQL 12+ Psycopg (Version 2 >= 2.9.3 or Version 3 >= 3.1)
Installation
pip install depeche-db
# OR
poetry add depeche-db
# OR
uv add depeche-db
Example
import pydantic, sqlalchemy, uuid, datetime as dt
from depeche_db import (
MessageStore,
StoredMessage,
MessageHandler,
SubscriptionMessage,
)
from depeche_db.tools import PydanticMessageSerializer
DB_DSN = "postgresql://depeche:depeche@localhost:4888/depeche_demo"
db_engine = sqlalchemy.create_engine(DB_DSN)
class MyMessage(pydantic.BaseModel):
content: int
message_id: uuid.UUID = pydantic.Field(default_factory=uuid.uuid4)
sent_at: dt.datetime = pydantic.Field(default_factory=dt.datetime.utcnow)
def get_message_id(self) -> uuid.UUID:
return self.message_id
def get_message_time(self) -> dt.datetime:
return self.sent_at
message_store = MessageStore[MyMessage](
name="example_store",
engine=db_engine,
serializer=PydanticMessageSerializer(MyMessage),
)
message_store.write(stream="aggregate-me-1", message=MyMessage(content=2))
print(list(message_store.read(stream="aggregate-me-1")))
# [StoredMessage(message_id=UUID('...'), stream='aggregate-me-1', version=1, message=MyMessage(content=2, message_id=UUID('...'), sent_at=datetime.datetime(...)), global_position=1)]
class ContentMessagePartitioner:
def get_partition(self, message: StoredMessage[MyMessage]) -> int:
return message.message.content % 10
class MyHandlers(MessageHandler[MyMessage]):
@MessageHandler.register
def handle_message(self, message: SubscriptionMessage[MyMessage]):
print(message)
aggregated_stream = message_store.aggregated_stream(
name="aggregated",
partitioner=ContentMessagePartitioner(),
stream_wildcards=["aggregate-me-%"],
)
subscription = aggregated_stream.subscription(
name="example_subscription",
handlers=MyHandlers(),
)
aggregated_stream.projector.run()
subscription.runner.run()
# MyHandlers.handle_message prints:
# SubscriptionMessage(partition=2, position=0, stored_message=StoredMessage(...))
Contribute
Contributions in the form of issues, questions, feedback and pull requests are welcome. Before investing a lot of time, let me know what you are up to so we can see if your contribution fits the vision of the project.
Metadata
Release files for depeche-db 0.13.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| depeche_db-0.13.1.tar.gz | 332.7 kB | Without provenance | Details for depeche_db-0.13.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| depeche_db-0.13.1-py3-none-any.whl | Python 3 | none | any | Details for depeche_db-0.13.1-py3-none-any.whl |
Total release size: 379.7 kB
Release files / depeche_db-0.13.1.tar.gz
| Download URL | depeche_db-0.13.1.tar.gz |
|---|---|
| Size | 332.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5ccc468e3235600f28dac1e42be45f05b69eefa490d7d4a20e47f9c84eac65b4
|
|
BLAKE2b-256 checksum How to use checksums |
5b6088fec4200bca52c159609184f1313eead417ee51a24535baa67fc1b0d4e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Release files / depeche_db-0.13.1-py3-none-any.whl
| Download URL | depeche_db-0.13.1-py3-none-any.whl |
|---|---|
| Size | 46.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ce7d3a867da0140ffbbe8425df968689d1ceac0c6a12a2cf2a3efcfdf9d26778
|
|
BLAKE2b-256 checksum How to use checksums |
258a09be6dc20c4214b199fb6fa7175218f3094a762c3fcef4809ddb6eec075b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Security for depeche-db 0.13.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.