Skip to content
GitHubDiscord

API Reference

High-level protocol for dispatching webhook events.
async def dispatch(event: WebhookEvent) -> None

Deliver an event to all matching active subscriptions.

Parameters
ParameterTypeDescription
`event`WebhookEventEvent to deliver.
async def redeliver(attempt_id: str) -> Any

Redeliver a failed or dead-lettered attempt.

Returns Result[None, WebhookError]. Typed as Any because Result lives in lexigram (not lexigram-contracts).

Parameters
ParameterTypeDescription
`attempt_id`strID of the attempt to redeliver.
Returns
TypeDescription
AnyResult[None, WebhookError]

Storage for webhook delivery attempts and dead-letter queue.
async def record_attempt(attempt: DeliveryAttempt) -> None

Persist a delivery attempt record.

Parameters
ParameterTypeDescription
`attempt`DeliveryAttemptAttempt to record.
async def get_attempts(
    *,
    subscription_id: str | None = None,
    event_id: str | None = None,
    status: DeliveryStatus | None = None,
    limit: int = 100,
    offset: int = 0
) -> list[DeliveryAttempt]

Query delivery attempts matching filters, newest-first.

Parameters
ParameterTypeDescription
`subscription_id`str | NoneFilter by subscription.
`event_id`str | NoneFilter by event.
`status`DeliveryStatus | NoneFilter by delivery status.
`limit`intMaximum results.
`offset`intResults to skip.
Returns
TypeDescription
list[DeliveryAttempt]Matching attempts in newest-first order.
async def get_dead_letters(
    *,
    subscription_id: str | None = None,
    limit: int = 100,
    offset: int = 0
) -> list[DeliveryAttempt]

Return attempts in dead-letter status.

Parameters
ParameterTypeDescription
`subscription_id`str | NoneOptional filter by subscription.
`limit`intMaximum results.
`offset`intResults to skip.
Returns
TypeDescription
list[DeliveryAttempt]Dead-lettered attempts.
async def count_recent_failures(
    subscription_id: str,
    since: datetime
) -> int

Count failed attempts for a subscription since a given time.

Parameters
ParameterTypeDescription
`subscription_id`strSubscription to check.
`since`datetimeCount attempts after this timestamp.
Returns
TypeDescription
intCount of failed attempts.

Storage-agnostic CRUD for webhook subscriptions.
async def create(subscription: WebhookSubscription) -> None

Persist a new subscription.

Parameters
ParameterTypeDescription
`subscription`WebhookSubscriptionSubscription to store.
async def get(subscription_id: str) -> WebhookSubscription | None

Return subscription by ID, or None.

Parameters
ParameterTypeDescription
`subscription_id`strUUID to look up.
Returns
TypeDescription
WebhookSubscription | NoneThe subscription if found, else None.
async def list(
    *,
    active_only: bool = True,
    event_type: str | None = None,
    tenant_id: str | None = None,
    limit: int = 100,
    offset: int = 0
) -> list[WebhookSubscription]

List subscriptions matching filters.

Parameters
ParameterTypeDescription
`active_only`boolOnly return active subscriptions.
`event_type`str | NoneFilter to subscriptions that handle this event type.
`tenant_id`str | NoneFilter by tenant.
`limit`intMaximum results.
`offset`intResults to skip.
Returns
TypeDescription
list[WebhookSubscription]Filtered and paginated subscriptions.
async def update(subscription: WebhookSubscription) -> None

Update an existing subscription.

Parameters
ParameterTypeDescription
`subscription`WebhookSubscriptionUpdated subscription data.
async def delete(subscription_id: str) -> None

Remove a subscription.

Parameters
ParameterTypeDescription
`subscription_id`strUUID to remove.

Record of a single webhook delivery attempt.

Attributes: attempt_id: Unique identifier for this attempt. subscription_id: Target subscription. event_id: The event being delivered. event_type: Event type name. status: Outcome of this attempt. status_code: HTTP response status code (None if connection failed). attempt_number: 1-based attempt counter. attempted_at: When this attempt was made. next_retry_at: Scheduled time for the next retry (None if terminal). error_message: Error details on failure. duration_ms: Round-trip time in milliseconds.


Status of a webhook delivery attempt.

Configuration for the webhook management subsystem.

Attributes: store_backend: Persistence backend. “sql” requires lexigram-webhook[sql]. retry_max_attempts: Maximum delivery attempts before dead-letter. retry_base_delay: Initial retry delay in seconds. retry_max_delay: Maximum retry delay ceiling in seconds. retry_backoff_factor: Exponential backoff multiplier. secret_length: Secret length in bytes (hex-encoded output is 2x). secret_rotation_grace_hours: Hours both old and new secrets are accepted. delivery_timeout_seconds: HTTP request timeout per delivery attempt. disable_after_consecutive_failures: Auto-disable threshold. failure_window_hours: Window for counting consecutive failures. signature_algorithm: HMAC algorithm name. enable_admin: Whether to register the admin contributor. delivery_log_retention_days: Days to retain delivery log (0 = indefinite). signature_header: HTTP header for the HMAC signature. event_type_header: HTTP header for the event type. event_id_header: HTTP header for the event ID. timestamp_header: HTTP header for the delivery timestamp.


An event prepared for webhook delivery.

Attributes: event_id: Unique identifier for deduplication (UUID). event_type: Dot-notation event type (e.g. “user.created”). payload: JSON-serializable event data. occurred_at: When the original event occurred. source: Originating service or module.


Lexigram webhook management module.

Provides subscription CRUD, delivery pipeline, HMAC signature verification, and dead-letter queue management.

Usage

app.use(WebhookModule.configure())
app.use(WebhookModule.configure(WebhookConfig(store_backend="sql")))
def configure(
    cls,
    config: WebhookConfig | None = None
) -> DynamicModule

Configure the webhook module with optional settings.

Parameters
ParameterTypeDescription
`config`WebhookConfig | NoneCustom webhook configuration. Defaults to ``WebhookConfig()``.
Returns
TypeDescription
DynamicModuleDynamicModule ready for registration with the app container.

A registered webhook endpoint subscription.

Attributes: subscription_id: Unique identifier (UUID). url: HTTP(S) endpoint URL to deliver events to. secret: Shared secret for HMAC signature computation. event_types: Set of event type names to deliver. None = all events. active: Whether the subscription is currently active. description: Human-readable label for the subscription. tenant_id: Optional multi-tenant scoping. created_at: When the subscription was created. metadata: Arbitrary key-value context.


Base exception for webhook domain operations.