Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Indroic/HexCore/llms.txt

Use this file to discover all available pages before exploring further.

A Command represents an intent to change state. In CQRS, write-side messages are modelled as commands: each command has a clear name, carries all the data needed to perform the operation, and is dispatched to exactly one handler. HexCore’s Command base class enforces immutability (frozen=True) so command objects cannot be accidentally mutated after construction, making them safe to pass through middleware pipelines and serialize for background queues.
from hexcore.domain.cqrs.commands import Command

Class definition

class Command(BaseModel):
    model_config = ConfigDict(
        frozen=True,
        from_attributes=True,
    )

Fields

command_id
UUID
default:"uuid4()"
A unique identifier auto-generated for every command instance. Useful for idempotency checks, distributed tracing, and deduplication in task queues.
timestamp
datetime
UTC creation time of the command, set automatically via datetime.now(UTC). Useful for auditing and ordering in async systems.

Model configuration

OptionValueEffect
frozenTrueAll fields become read-only after instantiation. Attempts to mutate a field raise a ValidationError. The command is also hashable, enabling use in sets or as dict keys.
from_attributesTrueAllows constructing a command from ORM objects or other attribute-bearing objects via Command.model_validate(obj).

Type aliases

TCommand = TypeVar("TCommand", bound=Command)
TCommandResult = TypeVar("TCommandResult")
TCommand
TypeVar
A type variable bound to Command. Use this when declaring a generic handler to constrain the handler to a specific command subclass.
TCommandResult
TypeVar
An unconstrained type variable for the return value of a command handler. Use None for fire-and-forget commands that produce no meaningful result.

Usage example

from uuid import UUID
from hexcore.domain.cqrs.commands import Command

class CreateOrderCommand(Command):
    customer_id: UUID
    items: list[dict]
    shipping_address: str
Because commands are frozen Pydantic models, they are automatically JSON-serializable via .model_dump() and .model_dump_json(). This makes them straightforward to enqueue in background task systems such as Celery, ARQ, or Dramatiq when decorated with @background_command.

Build docs developers (and LLMs) love