CQRS library for async Python projects.
Project description
python-cq
python-cq is a Python package designed to organize your code following CQRS principles. It provides a DIAdapter protocol for dependency injection, with python-injection as the default implementation available via the [injection] extra.
What is CQRS?
CQRS (Command Query Responsibility Segregation) is an architectural pattern that separates read operations from write operations. This separation helps to:
- Clarify intent: each operation has a single, well-defined responsibility
- Improve maintainability: smaller, focused handlers are easier to understand and modify
- Simplify testing: isolated handlers are straightforward to unit test
CQRS is often associated with distributed systems and Event Sourcing, but its benefits extend beyond that. Even in a local or monolithic application, adopting this pattern helps structure your code and makes the boundaries between reading and writing explicit.
Prerequisites
To get the most out of python-cq, familiarity with the following concepts is recommended:
- CQRS and the distinction between Commands, Queries and Events
- Domain Driven Design (DDD), particularly aggregates and bounded contexts
This knowledge will help you design coherent handlers and organize your code effectively.
Message types
python-cq provides three types of messages to model your application's operations:
- Command: represents an intent to change the system's state. A command is handled by exactly one handler and may return a value for convenience.
- Query: represents a request for information. A query is handled by exactly one handler and returns data without side effects.
- Event: represents something that has happened in the system. An event can be handled by zero, one, or many handlers, enabling loose coupling between components.
Installation
Requires Python 3.12 or higher.
Without dependency injection:
pip install python-cq
With python-injection as the DI backend (recommended):
pip install "python-cq[injection]"
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python_cq-0.17.0.tar.gz.
File metadata
- Download URL: python_cq-0.17.0.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.13 {"installer":{"name":"uv","version":"0.11.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa356479d6b64d3d2b66863dab4369c90f30f9fb7ddff5275908185371489627
|
|
| MD5 |
b3daa48b2a70f6e7dcac2a804e7971b8
|
|
| BLAKE2b-256 |
f690e1704f04016585e93bc4c7a8123a2e107dfa0ffcf7524762a78063b2afe1
|
File details
Details for the file python_cq-0.17.0-py3-none-any.whl.
File metadata
- Download URL: python_cq-0.17.0-py3-none-any.whl
- Upload date:
- Size: 18.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.13 {"installer":{"name":"uv","version":"0.11.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a1e97ed330141e19dc7236947f1e519ca7c23d52e4eb818567138e25d958b786
|
|
| MD5 |
ebf2bacbc075583adf765d0ab40aac75
|
|
| BLAKE2b-256 |
e6bebb033441f2213e68544fbe2389d8ba99051234ca2fef33665bcf64a6333e
|