A client library for accessing Stage Events
Project description
stage-events-client
Python client for sending structured-mode CloudEvents 1.0.2 to the Stage Events API.
The package provides Pydantic models for the supported workflow events and synchronous and asynchronous clients built on HTTPX.
Requirements
- Python 3.10 or newer
- A Stage Events API endpoint
- A bearer token when authentication is enabled
Installation
python -m pip install stage-events-client
The command-line interface dependencies are optional. Enable the CLI explicitly when installing the package:
python -m pip install 'stage-events-client[cli]'
Command-line interface
The send-stage-event executable provides one command for every supported
CloudEvent model:
send-stage-event --help
send-stage-event submitted --help
Pass the complete destination URL as the command argument. There is no separate base URL or endpoint-path setting:
send-stage-event submitted \
https://events.example.com/hooks/cloud-events \
--source workflows:example-process:submit \
--subject workflows:2f660c57:example-workflow \
--data '{"namespace":"workflows","time":"2026-07-18T12:00:00Z"}' \
--x-kafka-topic workflows.2f660c57.submitted \
--token your-bearer-token
The available commands are calendar, submitted, dismissed, prepared,
completed, failed, piped, staged, and ordered. Each command validates
--data against its corresponding Pydantic model before sending the request.
--data accepts inline JSON, a JSON file prefixed with @, or - to read from
standard input:
send-stage-event prepared https://events.example.com/cloud-events \
--source workflows:example-process:prepare \
--subject workflows:2f660c57:example-workflow \
--data @prepared-data.json
cat submitted-data.json | send-stage-event submitted \
https://events.example.com/cloud-events \
--source workflows:example-process:submit \
--subject workflows:2f660c57:example-workflow \
--data -
The partition key defaults to the subject. Override it with --partition-key
when required. The --x-kafka-topic option is optional.
The bearer token can be supplied through --token or the
STAGE_EVENTS_TOKEN environment variable. Run a command with --help for TLS,
timeout, and all other options.
Quick start
Create a client, construct an event, and send it with the required Kafka topic:
from datetime import datetime, timezone
from uuid import uuid4
from stage_events_client import AuthenticatedClient
from stage_events_client.api.default import send_cloud_event
from stage_events_client.models import SubmittedCloudEvent, SubmittedData
client = AuthenticatedClient(
base_url="https://events.example.com",
token="your-bearer-token",
)
subject = "workflows:2f660c57:example-workflow"
event = SubmittedCloudEvent(
source="workflows:example-process:submit",
subject=subject,
partitionkey=subject,
specversion="1.0",
id=str(uuid4()),
data=SubmittedData(
namespace="workflows",
time=datetime.now(timezone.utc),
),
)
with client:
result = send_cloud_event.sync(
client=client,
body=event,
x_kafka_topic="workflows.2f660c57.submitted",
)
print(result)
Use Client instead when the API does not require authentication:
from stage_events_client import Client
client = Client(base_url="https://events.example.com")
Detailed responses
sync returns the parsed response body. Use sync_detailed when the status,
headers, or raw response body are also needed:
response = send_cloud_event.sync_detailed(
client=client,
body=event,
x_kafka_topic="workflows.2f660c57.submitted",
)
print(response.status_code)
print(response.headers)
print(response.content)
print(response.parsed)
A successful 200 response is parsed as a string. Documented 400 responses
are parsed into the corresponding problem-details model. An undocumented status
returns None unless raise_on_unexpected_status=True is set on the client, in
which case stage_events_client.errors.UnexpectedStatus is raised.
Async usage
Each endpoint has equivalent asyncio and asyncio_detailed functions:
import asyncio
async def main() -> None:
async with client:
result = await send_cloud_event.asyncio(
client=client,
body=event,
x_kafka_topic="workflows.2f660c57.submitted",
)
print(result)
asyncio.run(main())
Do not use the same client instance in synchronous and asynchronous context managers at the same time.
Supported events
The request body can be any of the following models from
stage_events_client.models:
| Event type | Model |
|---|---|
calendar-event |
CalendarCloudEvent |
submitted |
SubmittedCloudEvent |
dismissed |
DismissedCloudEvent |
prepared |
PreparedCloudEvent |
completed |
CompletedCloudEvent |
failed |
FailedCloudEvent |
piped |
PipedCloudEvent |
staged |
StagedCloudEvent |
ordered |
OrderedCloudEvent |
The models validate event-specific payloads, timezone-aware timestamps,
semantic versions, and GeoJSON structures where applicable. Additional standard
CloudEvent attributes such as id and specversion are preserved by the
models.
Event addressing
The API expects these values:
source: three colon-separated components, normally{namespace}:{process-id}:{step-name}.subject: three colon-separated components, normally{namespace}:{workflow-uid}:{workflow-name}.partitionkey: usually the same value assubject.x_kafka_topic: a topic in the form{namespace}.{workflow-uid}.{event-suffix}, such asworkflows.2f660c57.submitted.
Calendar topics use a duration followed by .calendar, for example
workflows.2f660c57.10m.calendar.
Client configuration
Both Client and AuthenticatedClient accept shared headers, cookies, timeout,
TLS verification, redirect handling, and additional HTTPX options:
import httpx
from stage_events_client import AuthenticatedClient
client = AuthenticatedClient(
base_url="https://events.example.com",
token="your-bearer-token",
headers={"X-Correlation-ID": "request-id"},
timeout=httpx.Timeout(30.0),
verify_ssl="/path/to/ca-bundle.pem",
follow_redirects=True,
httpx_args={"proxy": "http://proxy.example.com:8080"},
raise_on_unexpected_status=True,
)
TLS certificate verification is enabled by default. Setting verify_ssl=False
disables server certificate validation and should only be used in controlled
development environments.
Clients can be copied with updated settings:
client = client.with_headers({"X-Correlation-ID": "new-request-id"})
client = client.with_cookies({"session": "value"})
client = client.with_timeout(httpx.Timeout(10.0))
An existing httpx.Client or httpx.AsyncClient can also be supplied with
set_httpx_client or set_async_httpx_client. Doing so overrides the generated
client configuration, so the HTTPX instance must define its own base URL and
other required settings.
Development
Install Hatch and run the unit tests:
hatch run test:test
Other useful checks are:
hatch run test:cov
hatch run types:check
hatch run dev:check
hatch run dev:lint
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
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 stage_events_client-1.0.1.tar.gz.
File metadata
- Download URL: stage_events_client-1.0.1.tar.gz
- Upload date:
- Size: 86.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cc0d583cc92f31db95c1fc086158bc8747a1ca735a9dacde6e9374df33270bc
|
|
| MD5 |
c30508c5a254dd4775e16c29914914b9
|
|
| BLAKE2b-256 |
bdee638e6695c2ef7fa32f9b8117d4c4e8bbfef80005d61939494664976a9e03
|
Provenance
The following attestation bundles were made for stage_events_client-1.0.1.tar.gz:
Publisher:
package.yaml on Terradue/schemas
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stage_events_client-1.0.1.tar.gz -
Subject digest:
1cc0d583cc92f31db95c1fc086158bc8747a1ca735a9dacde6e9374df33270bc - Sigstore transparency entry: 2206840041
- Sigstore integration time:
-
Permalink:
Terradue/schemas@46ff5f99aff7176c59679f29a9866b051c621d5a -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/Terradue
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
package.yaml@46ff5f99aff7176c59679f29a9866b051c621d5a -
Trigger Event:
push
-
Statement type:
File details
Details for the file stage_events_client-1.0.1-py3-none-any.whl.
File metadata
- Download URL: stage_events_client-1.0.1-py3-none-any.whl
- Upload date:
- Size: 30.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91385a276ec698e6ab4acd39397e18720289fc9adf226a8708dc7335a8bc677e
|
|
| MD5 |
2600e1b217b3c111a47adc38f8bcbd52
|
|
| BLAKE2b-256 |
ebd758bf9e2f32c3b7d0ece8a1292f4515805839db0d9b4acdcff678070bc6ee
|
Provenance
The following attestation bundles were made for stage_events_client-1.0.1-py3-none-any.whl:
Publisher:
package.yaml on Terradue/schemas
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stage_events_client-1.0.1-py3-none-any.whl -
Subject digest:
91385a276ec698e6ab4acd39397e18720289fc9adf226a8708dc7335a8bc677e - Sigstore transparency entry: 2206840076
- Sigstore integration time:
-
Permalink:
Terradue/schemas@46ff5f99aff7176c59679f29a9866b051c621d5a -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/Terradue
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
package.yaml@46ff5f99aff7176c59679f29a9866b051c621d5a -
Trigger Event:
push
-
Statement type: