Skip to content

Query Fetcher Port

query_fetcher_port

Outbound port for asynchronously fetching query results.

Defines the QueryFetcherPort ABC for dispatching query messages
and returning their results. Supports CQRS-style architectures where
queries are processed independently of commands.

Responsibilities
  • Abstract query dispatch from transport details.
Non-Responsibilities
  • Define caching or projection logic.
  • Guarantee consistency between read and write models.

QueryFetcherPort

Bases: OutboundPort

ABC for dispatching query messages asynchronously.

Delivery semantics are decoupled from this contract.

Example
fetcher = MyQueryFetcher[OrderQueryPayload, list[dict[str, object]]]()
orders = await fetcher.fetch(GetOrdersByStatus(status="pending"))
Source code in src/forging_blocks/application/ports/outbound/query_fetcher_port.py
class QueryFetcherPort[QueryPayloadType, QueryFetcherResult](
    OutboundPort,
):
    """ABC for dispatching query messages asynchronously.

    Delivery semantics are decoupled from this contract.

    Example:
        ```python
        fetcher = MyQueryFetcher[OrderQueryPayload, list[dict[str, object]]]()
        orders = await fetcher.fetch(GetOrdersByStatus(status="pending"))
        ```
    """

    @abstractmethod
    async def fetch(self, query: Query[QueryPayloadType]) -> QueryFetcherResult:
        """Fetch the result of a query.

        Args:
            query: The query instance.

        Returns:
            Any result returned by the underlying query handler.

        """
        ...

fetch(query: Query[QueryPayloadType]) -> QueryFetcherResult abstractmethod async

Fetch the result of a query.

Parameters:

Name Type Description Default
query Query[QueryPayloadType]

The query instance.

required

Returns:

Type Description
QueryFetcherResult

Any result returned by the underlying query handler.

Source code in src/forging_blocks/application/ports/outbound/query_fetcher_port.py
@abstractmethod
async def fetch(self, query: Query[QueryPayloadType]) -> QueryFetcherResult:
    """Fetch the result of a query.

    Args:
        query: The query instance.

    Returns:
        Any result returned by the underlying query handler.

    """
    ...