Skip to main content

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

Metadata

Release files for ambient-event-bus-client 2.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ambient-event-bus-client 2.2.0
File Size Uploaded
ambient_event_bus_client-2.2.0.tar.gz 9.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ambient-event-bus-client 2.2.0
File Interpreter ABI Platform
ambient_event_bus_client-2.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 20.0 kB

Release files / ambient_event_bus_client-2.2.0.tar.gz

Download URL ambient_event_bus_client-2.2.0.tar.gz
Size 9.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c5c72d7a53f88db39f87a1b568497296e54ca7d616080d1277550a656eefa4a1
BLAKE2b-256 checksum
How to use checksums
e714c958883a96dbfa506bacb97f6071122201577af9bb7e7e8f675c0aa1dd48
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / ambient_event_bus_client-2.2.0-py3-none-any.whl

Download URL ambient_event_bus_client-2.2.0-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5103914bda36b9b8cc936d4dec2564d69b85d9e6a9175ddbe49c2243e734a8d6
BLAKE2b-256 checksum
How to use checksums
e02019f3f8deedfa52eb7f085d4f3fd8ef237d9e317c2bcc257595d2f72dc2fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release history Release notifications | RSS feed

This release

2.2.0 This release

2 release files

2.1.1

2 release files

2.0.0

2 release files

1.1.4

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.2

2 release files

1.0.1

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page