Skip to main content

A library to interact with the Ambient Labs Event Bus.

Project description

Ambient Event Bus Client

A Python client library for interacting with the Ambient Labs Event Bus.

Installation

pip install ambient-event-bus-client

Quick Start

from ambient_event_bus_client import Client, ClientOptions, MessageCreate

options = ClientOptions(
    event_api_url="http://localhost:8000",
    connection_service_url="http://localhost:8001",
    api_token="your_api_token"
)
client = Client(options)
await client.init_client()  # ensure you are in an async context

# Basic subscription
await client.add_subscription(topic="notifications")

# Subscribe and listen for messages
async for message in client.subscribe():
    print(f"Received: {message}")

# Publish a basic message
message = MessageCreate(topic="notifications", message="Hello, World!")
await client.publish(message)

Advanced Features

Aggregate Filtering

Filter messages by resource type and ID:

# Subscribe to all messages for a specific resource type
await client.add_subscription(
    topic="resource_updates",
    aggregate_type="node"
)

# Subscribe to messages for a specific resource instance  
await client.add_subscription(
    topic="resource_updates",
    aggregate_type="node", 
    aggregate_id=123
)

# Publish messages with aggregate information
message = MessageCreate(
    topic="node_update",
    message="Node status changed",
    aggregate_type="node",
    aggregate_id=123
)
await client.publish(message)

Regex Topic Matching

Use regular expressions for flexible topic matching:

# Match multiple related topics
await client.add_subscription(
    topic="user\\.(login|logout|signup)",
    is_regex=True
)

# Match all user events
await client.add_subscription(
    topic="user\\..*",
    is_regex=True  
)

API Reference

Client Methods

add_subscription(topic, aggregate_type=None, aggregate_id=None, is_regex=False)

Create a new subscription.

Parameters:

  • topic (str): The topic to subscribe to
  • aggregate_type (str, optional): Filter by resource type
  • aggregate_id (int, optional): Filter by specific resource ID (requires aggregate_type)
  • is_regex (bool): Whether to treat topic as a regex pattern (default: False)

Returns: Subscription object

publish(message)

Publish a message to the event bus.

Parameters:

  • message (MessageCreate): The message to publish

Models

MessageCreate

MessageCreate(
    topic: str,
    message: str,
    aggregate_type: Optional[str] = None,
    aggregate_id: Optional[int] = None
)

Development

Running Tests

# Install development dependencies
make install-dev

# Run all tests
make test

# Run unit tests only
make test-unit

# Run end-to-end tests
make test-e2e

# Run tests with coverage
make test-cov

Code Quality

# Run linting
make lint

# Format code
make format

Migration from v1.x

See MIGRATION_GUIDE.md for detailed migration instructions.

Key Breaking Changes in v2.0.0

  • ID fields changed from int to str (UUID format)
  • Topic matching no longer supports glob patterns - use regex with is_regex=True
  • New aggregate filtering capabilities
  • Enhanced validation for aggregate fields

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ambient_event_bus_client-2.1.1.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ambient_event_bus_client-2.1.1-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file ambient_event_bus_client-2.1.1.tar.gz.

File metadata

File hashes

Hashes for ambient_event_bus_client-2.1.1.tar.gz
Algorithm Hash digest
SHA256 c29891bee826783a5fe355ff4ca1a13199fd79a124aec4826bed83e7b86103f8
MD5 8ab93ad3b0d096c0c7da2b12bf54d84f
BLAKE2b-256 0c5fc73e6a549d68928f59fd7684b9142faeafc2fca461e40dd91525e5e5d388

See more details on using hashes here.

File details

Details for the file ambient_event_bus_client-2.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for ambient_event_bus_client-2.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 36ebd689d4f58b7873c62f85647f675e6010683fb9a67a8862e95167c620b93a
MD5 64bf2b350f190f459012721b2e804dff
BLAKE2b-256 7221105b1d29c438d13aee7ab11b2feb19294518f08371c2aecacc3c4f7781a4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page