Skip to main content

CQRS interfaces and base classes with tracing support

Project description

Python CQRS Core Documentation

Welcome to the Python CQRS Core documentation!

Quick Links

Getting Started

Integration Guides

Reference

What is Python CQRS Core?

CQRS (Command Query Responsibility Segregation) interfaces and base classes with built-in tracing and audit support for Python applications.

Installation

pip install python-cqrs-core

Key Features

  • Command/Query Separation: Type-safe CQRS pattern implementation
  • Built-in Observability: Automatic request IDs, correlation IDs, audit fields
  • Immutability: Frozen commands/queries prevent tampering
  • Pagination: Built-in pagination support for queries
  • Type Safety: Full generic type support with type hints
  • Integration-Ready: Works seamlessly with OpenTelemetry, Sentry, Prometheus

Quick Example

from python_cqrs_core import BaseCommand, ICommandHandler

class CreateUserCommand(BaseCommand):
    name: str
    email: str

class CreateUserHandler(ICommandHandler[CreateUserCommand, int]):
    async def handle(self, command: CreateUserCommand) -> int:
        # Automatic tracing fields available:
        logger.info(
            f"[{command.request_id}] Creating user {command.email} "
            f"requested by {command.requested_by}"
        )

        user_id = await self.user_repository.create(
            name=command.name,
            email=command.email
        )

        return user_id

Documentation Structure

Usage Guide

Practical examples and best practices:

  • Commands and command handlers
  • Queries and query handlers
  • Paginated queries
  • Tracing fields (request_id, correlation_id, requested_by, requested_at)
  • Complete examples with logging and monitoring

Why Use BaseQuery/BaseCommand?

Learn about the benefits of using BaseQuery and BaseCommand over plain Pydantic models:

  • Zero-effort observability
  • Production debugging
  • Distributed tracing
  • Audit trail for compliance
  • Performance monitoring
  • When to use vs plain BaseModel

Observability Integration

Comprehensive guide to integrating with modern observability tools:

  • OpenTelemetry integration patterns
  • Sentry error tracking with business context
  • Prometheus metrics with domain fields
  • Audit trail for compliance (SOC 2, HIPAA, PCI DSS)
  • Real-world examples and best practices

API Reference

Complete API documentation:

  • Interfaces: ICommand, ICommandHandler, IQuery, IQueryHandler
  • Base Classes: BaseCommand, BaseQuery, PaginatedQuery
  • Type hints and generics
  • Immutability guarantees

Dependencies

  • pydantic>=2.0.0

License

MIT

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_cqrs_core-0.1.0.tar.gz (6.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_cqrs_core-0.1.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file python_cqrs_core-0.1.0.tar.gz.

File metadata

  • Download URL: python_cqrs_core-0.1.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for python_cqrs_core-0.1.0.tar.gz
Algorithm Hash digest
SHA256 63f38c95212d66d3a05217b55baca0dc6ddade74f7daf8dd7818a52b5a98fb3e
MD5 b377980d3501c453abb0e5b329bd2e1c
BLAKE2b-256 ecc3fd52bb5927d820fd877adb680233bb2728b7a310050bdca7bbe25eb58c93

See more details on using hashes here.

File details

Details for the file python_cqrs_core-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for python_cqrs_core-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 531758b9b2c3aee110bf3abe620855803bba8e9e31403973b6019fd19d1ac084
MD5 7f94e5d76374a334b9a80dcedea7283f
BLAKE2b-256 5e01fa2ca038ca7c2ee6ae86aa5afc8408814f6677a12dbb5a673a0f3fa4150b

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