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.1.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.1-py3-none-any.whl (18.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: python_cq-0.16.1.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","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.1.tar.gz
Algorithm Hash digest
SHA256 dd8c3eb7c0f694cf93d59babbd7345cf811ae78d06bd0f63aee07776f09ff3d7
MD5 37779971c5a68c9481e6aa16af368db0
BLAKE2b-256 75d4253f61d02338c01b3bd35f60e98538cfbcc5217cd8519b731e1018664f27

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_cq-0.16.1-py3-none-any.whl
  • Upload date:
  • Size: 18.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4db1443e99b183759510bb8d95d1c36cc644361457951ae513e3bc3e346f761b
MD5 12ba43470d290f746a664e900744d073
BLAKE2b-256 67f24d4ae337ceb3c0a5caef7687a5ea9f1800d4b7371edcc2f65b3d7dedf970

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