The CloudEvents Python SDK provides a simple and efficient way to create, parse, and send CloudEvents in Python applications. It supports all CloudEvents versions and various transport bindings. The current version is 2.0.0, with active development and regular releases.
pip install cloudeventsVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to create a CloudEvent with specified attributes and JSON data, then serialize it into HTTP structured mode headers and body. It also shows how to access the event's data (which is bytes in v2.0.0+).
Update all instances of `contenttype` to `datacontenttype` when creating or accessing CloudEvent attributes (e.g., `event.attributes['datacontenttype']`).
If you expect JSON or text data, you must decode `event.data`. For example, `json.loads(event.data.decode('utf-8'))` for JSON, or `event.data.decode('utf-8')` for plain text.Use the provided binding functions like `from_structured`, `to_structured` for HTTP operations, or manually serialize/deserialize using `event.attributes` and `event.data`.
Ensure `time` is a string formatted as `YYYY-MM-DDTHH:MM:SSZ` or with milliseconds (`YYYY-MM-DDTHH:MM:SS.ffffffZ`). Use `datetime.datetime.now(datetime.timezone.utc).isoformat(timespec='milliseconds').replace('+00:00', 'Z')` for reliable generation.Install the library using `pip install cloudevents`.
No dependency data recorded yet.