Skip to main content

CQRS library for async Python projects.

Project description

python-cq

PyPI - Version PyPI - Downloads

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_cq-0.16.0.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_cq-0.16.0-py3-none-any.whl (18.7 kB view details)

Uploaded Python 3

File details

Details for the file python_cq-0.16.0.tar.gz.

File metadata

  • Download URL: python_cq-0.16.0.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","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

Hashes for python_cq-0.16.0.tar.gz
Algorithm Hash digest
SHA256 d1e04784d2696f76a85cc281500a39c62f24c417464b1aba3d29aeef82ea455f
MD5 37db249c8e6c7e64eaa64f302321dd65
BLAKE2b-256 4972225f2e864f2adf0593f833bf8997e085c77c5d44661ec856d33e04cf153e

See more details on using hashes here.

File details

Details for the file python_cq-0.16.0-py3-none-any.whl.

File metadata

  • Download URL: python_cq-0.16.0-py3-none-any.whl
  • Upload date:
  • Size: 18.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","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

Hashes for python_cq-0.16.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ea0f936663abdd529c65db6c8e583c1f0d206a91e54a6945153cfd95419fc44e
MD5 67f2e6d4da975b5f9b5c85c2b246cad1
BLAKE2b-256 4e69977959374e2b717d9feda6128fa420b81ecfcb90a60c6465e0c1793174c1

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