Installing
The SDK is available on PyPI, so you can install it using pip:Basic Usage
Importing
The main components are available directly from thesailhouse
package.
Initialising the Client
The package provides aSailhouseClient
class which contains all methods for interacting with the Sailhouse platform.
After generating a token, you can create a client instance:
timeout
: Request timeout in seconds (default: 5.0)
Sending an event
Use thepublish()
method to send data to a topic. The method is async, so you’ll need to use it with await
:
data
argument must be a dictionary that can be serialized to JSON. The method also accepts optional parameters:
scheduled_time
: A datetime object for scheduled message deliverymetadata
: Additional metadata as a dictionary
Receiving events from a pull subscription
Thepull()
method allows you to fetch, and lock for procesing, a single event from a subscription:
get_events()
method accepts several optional parameters:
limit
: Maximum number of events to retrieveoffset
: Number of events to skiptime_window
: Time window for event retrieval (e.g., “1h”, “24h”)
Subscribing to events
The SDK provides a convenient way to continuously process events using thesubscribe()
method:
subscribe()
method accepts several parameters:
handler
: Callback function to process each eventpolling_interval
: Time between polling attempts in seconds (default: 5.0)on_error
: Optional error handler functionexit_on_error
: Whether to exit on error (default: False)
Admin Operations
The admin client provides methods for managing subscriptions programmatically.Registering Push Subscriptions
Rate Limiting and Deduplication
- Rate Limit: Controls delivery frequency using formats like “100/h” (100 per hour), “10/m” (10 per minute)
- Deduplication: Prevents duplicate deliveries within a time window using formats like “5m” (5 minutes), “1h” (1 hour)