Skip to main content
Version: 0.0.1

Shared Types

abe/types.py centralises all type aliases and protocols that define the Abstract Backend surface. Installing the package from PyPI automatically exposes these types to downstream projects thanks to the bundled py.typed marker.

JSON aliases​

AliasDefinitionNotes
JSONPrimitive`str \int \
JSONValue`JSONPrimitive \JSONDict \
JSONDictdict[str, JSONValue]Canonical representation of JSON objects
JSONListlist[JSONValue]Canonical representation of JSON arrays

Use these when authoring payload structures so static analysers understand the nested JSON semantics.

Event payloads and handlers​

  • WebhookEventPayload = dict[str, Any]
  • SyncEventHandlerFunc = Callable[[WebhookEventPayload], None]
  • AsyncEventHandlerFunc = Callable[[WebhookEventPayload], Awaitable[None]]
  • EventHandlerFunc = SyncEventHandlerFunc | AsyncEventHandlerFunc

These aliases demonstrate how to declare handlers that satisfy EventHandlerProtocol.

Message-queue aliases​

AliasDescription
MessageQueueKeyRouting key/topic identifier (string).
MessageQueuePayloadJSON-compatible dictionary representing the message.
MessageQueueMessageProvider-defined structure for consumed messages (payload plus metadata).
MessageQueueBackendConfigdict[str, str | int | bool] used during initialisation.
ConsumerGroupstr | None naming group-based consumers.

Protocols​

EventHandlerProtocol​

@runtime_checkable
class EventHandlerProtocol(Protocol):
async def handle_event(self, event: WebhookEventPayload) -> None: ...

Any class with an async handle_event method can be treated as an event handler. This is useful when you want to inject class-based processors into higher-level orchestration code.

MessageQueueBackendProtocol​

The structural protocol re-exported as MessageQueueBackend. Providers must implement:

  • async publish(key: MessageQueueKey, payload: MessageQueuePayload) -> None
  • async consume(*, group: ConsumerGroup = None) -> AsyncIterator[MessageQueueMessage]
  • @classmethod from_env(cls) -> MessageQueueBackendProtocol

Best practices​

  • When creating new modules, import aliases from abe.types instead of re-declaring them.
  • Export any additional public types from your provider package’s __all__ to keep MyPy happy.
  • The verification script scripts/ci/verify_type_checking.sh ensures newly added types remain part of the public surfaceβ€”update it if you add more names.