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 toaggregate_type(str, optional): Filter by resource typeaggregate_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
inttostr(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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ambient_event_bus_client-2.2.0.tar.gz | 9.7 kB | Without provenance | Details for ambient_event_bus_client-2.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ambient_event_bus_client-2.2.0-py3-none-any.whl | Python 3 | none | any | Details for ambient_event_bus_client-2.2.0-py3-none-any.whl |
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
|
Security for ambient-event-bus-client 2.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.