Anlyon Relay Python SDK
Official Python SDK for the Anlyon Relay API - Type-safe message scheduling and delivery.
Installation
pip install anlyon-relay
Quick Start
Synchronous Client
from anlyon_relay import Client, PublishMessageRequest
# Create a client
client = Client(api_key="your-api-key")
# Publish a message
result = client.messages.publish(
PublishMessageRequest(
url="https://example.com/webhook",
body={"hello": "world"}
)
)
print(f"Message ID: {result.data.message_id}")
# Close when done
client.close()
Asynchronous Client
import asyncio
from anlyon_relay import AsyncClient, PublishMessageRequest
async def main():
async with AsyncClient(api_key="your-api-key") as client:
result = await client.messages.publish(
PublishMessageRequest(
url="https://example.com/webhook",
body={"hello": "world"}
)
)
print(f"Message ID: {result.data.message_id}")
asyncio.run(main())
Features
- Type-safe: Full type hints and Pydantic models
- Sync & Async: Both synchronous and asynchronous clients
- Fluent Builders: Intuitive API for building requests
- Automatic Retries: Exponential backoff with jitter
- Webhook Verification: HMAC-SHA256 signature verification
Usage Examples
Fluent Message Builder
from anlyon_relay import Client
client = Client(api_key="your-api-key")
# Using the fluent builder
result = (
client.messages.create_message()
.to("https://example.com/webhook")
.method("POST")
.header("X-Custom-Header", "value")
.body({"event": "user.created", "user_id": 123})
.in_minutes(5) # Schedule 5 minutes from now
.max_retries(3)
.send()
)
Scheduled Messages
from datetime import datetime
from anlyon_relay import Client, PublishMessageRequest
client = Client(api_key="your-api-key")
# Schedule for a specific time
result = client.messages.publish(
PublishMessageRequest(
url="https://example.com/webhook",
scheduled_for="2024-12-25T00:00:00Z"
)
)
# Or use Unix timestamp
result = client.messages.publish(
PublishMessageRequest(
url="https://example.com/webhook",
execute_at=1735084800 # Unix timestamp in seconds
)
)
Cron Schedules
from anlyon_relay import Client, CreateScheduleRequest
client = Client(api_key="your-api-key")
# Create a schedule
result = client.schedules.create(
CreateScheduleRequest(
name="Daily Report",
cron_expression="0 9 * * *", # Every day at 9 AM
timezone="America/New_York",
url="https://example.com/generate-report"
)
)
# Using the fluent builder
result = (
client.schedules.create_schedule()
.name("Hourly Check")
.hourly()
.to("https://example.com/health-check")
.create()
)
URL Groups (Broadcasting)
from anlyon_relay import Client, CreateUrlGroupRequest, EndpointInput
client = Client(api_key="your-api-key")
# Create a group for broadcasting
result = client.url_groups.create(
CreateUrlGroupRequest(
name="Notification Services",
endpoints=[
EndpointInput(url="https://service1.com/webhook"),
EndpointInput(url="https://service2.com/webhook"),
EndpointInput(url="https://service3.com/webhook"),
]
)
)
# Publish to all endpoints
from anlyon_relay import PublishGroupMessageRequest
client.url_groups.publish(
result.data.id,
PublishGroupMessageRequest(body={"event": "broadcast"})
)
Queues
from anlyon_relay import Client, CreateQueueRequest
client = Client(api_key="your-api-key")
# Create a queue with parallelism
result = client.queues.create(
CreateQueueRequest(
name="email-queue",
parallelism=5 # Process 5 messages at a time
)
)
# Publish to the queue
from anlyon_relay import PublishMessageRequest
client.messages.publish(
PublishMessageRequest(
url="https://example.com/process-email",
queue="email-queue"
)
)
Pagination
from anlyon_relay import Client
client = Client(api_key="your-api-key")
# Iterate through all messages
for message in client.messages.list_all():
print(f"Message: {message.message_id} - {message.status}")
# Or collect to a list
all_messages = client.messages.list_all().to_list()
# Take first 10
first_10 = client.messages.list_all().take(10)
# Find specific message
pending = client.messages.list_all().find(
lambda m: m.status == "pending"
)
Async Pagination
import asyncio
from anlyon_relay import AsyncClient
async def main():
async with AsyncClient(api_key="your-api-key") as client:
async for message in client.messages.list_all():
print(f"Message: {message.message_id}")
# Or collect to list
all_messages = await client.messages.list_all().to_list()
asyncio.run(main())
Webhook Verification
from anlyon_relay import Client, Receiver, ReceiverConfig
# Option 1: Using Client static method
result = Client.verify_webhook_signature(
payload=request_body,
signature_header=request.headers["x-anlyon-signature"],
secret="your-webhook-secret"
)
if result.valid:
# Process the webhook
pass
# Option 2: Using Receiver class
receiver = Receiver(ReceiverConfig(signing_secret="your-webhook-secret"))
try:
receiver.verify_or_throw(
signature=request.headers["x-anlyon-signature"],
body=request_body
)
# Signature is valid, process the webhook
except SignatureVerificationError as e:
# Invalid signature
pass
Error Handling
from anlyon_relay import (
Client,
AnlyonError,
RateLimitError,
ValidationError,
AuthenticationError,
)
client = Client(api_key="your-api-key")
try:
result = client.messages.publish(...)
except RateLimitError as e:
print(f"Rate limited, retry after {e.retry_after} seconds")
except ValidationError as e:
print(f"Validation failed: {e.details}")
except AuthenticationError as e:
print("Invalid API key")
except AnlyonError as e:
print(f"API error: {e.code} - {e.message}")
Custom Configuration
from anlyon_relay import Client, RetryConfig, LoggingConfig, LogLevel
client = Client(
api_key="your-api-key",
base_url="https://api.queue.anlyon.com",
timeout=60.0,
retry=RetryConfig(
max_attempts=5,
initial_delay=0.5,
max_delay=30.0,
backoff_multiplier=2.0,
jitter=True,
),
logging=LoggingConfig(
enabled=True,
level=LogLevel.DEBUG,
redact_sensitive=True,
),
default_headers={"X-Custom-Header": "value"},
)
API Reference
Resources
client.messages- Publish and manage messagesclient.schedules- Create and manage cron schedulesclient.url_groups- Manage URL groups for broadcastingclient.queues- Create and manage message queuesclient.dlq- Dead letter queue operationsclient.analytics- Usage analytics and metricsclient.notifications- Notification managementclient.billing- Billing and usage information
Types
All request and response types are available as Pydantic models with full type hints.
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
anlyon_relay-1.0.1.tar.gz
(41.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file anlyon_relay-1.0.1.tar.gz.
File metadata
- Download URL: anlyon_relay-1.0.1.tar.gz
- Upload date:
- Size: 41.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ed1d3f56d1aa3a9f28e064240d9100c384d7e6d3aec23b9fe16d1f88d199882
|
|
| MD5 |
a09d5ac3e307d68ff47e71c4b3892dee
|
|
| BLAKE2b-256 |
87dbce3a9647b5a8675607793b1b6a3d11c375634cbc32e1305867329918b7f2
|
File details
Details for the file anlyon_relay-1.0.1-py3-none-any.whl.
File metadata
- Download URL: anlyon_relay-1.0.1-py3-none-any.whl
- Upload date:
- Size: 56.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e599ee9fdc1339c75fb8ee1b1a12d742e77611fb7eacbc7af76308ee97f72000
|
|
| MD5 |
e5e70f1deb4c6684a31076a27f05f701
|
|
| BLAKE2b-256 |
e759eabab001d56f0618b7f0ae6c89fb1828d5a6ce64847c55670a5134779aef
|