cloudevents-pydantic
This is an implementation of the CloudEvents spec using Pydantic V2 for high performance during validation and serialization.
It is meant to support natively FastAPI and FastStream (WIP)
How to use
pip install cloudevents-pydantic
from cloudevents_pydantic.bindings.http import HTTPHandler
from cloudevents_pydantic.events import CloudEvent
handler = HTTPHandler()
minimal_attributes = {
"type": "com.example.string",
"source": "https://example.com/event-producer",
}
# `CloudEvent` is a Pydantic model to handle validation and serialization
# `event_factory` is a helper method to autogenerate some of the mandatory
# such as id, time, specversion
event = CloudEvent.event_factory(**minimal_attributes)
# Single event HTTP serialization
headers, single_event_as_json = handler.to_json(event)
# Batch of events HTTP serialization
headers, batch_of_events_as_json = handler.to_json_batch([event])
# Parsing a JSON string for a single event
parsed_event = handler.from_json(single_event_as_json)
# Parsing a JSON string for a single event
parsed_event_list = handler.from_json(batch_of_events_as_json)
Refer to the docs for more advanced use cases and for details on how to create custom events.
Performance
Using pydantic gives a great performance boost if compared to the official SDK. (there's obviously some performance issue in the official serialization using pydantic)
These results come from a Macbook Pro M4 Pro on python 3.13. Feel free to run the benchmark.py
script yourself.
==== 1M iterations benchmark ====
Timings for HTTP JSON deserialization:
This package: 2.3955996250006137
Official SDK using pydantic model: 11.389213957998436
Official SDK using http model: 10.174893917006557
Timings for HTTP JSON serialization:
This package: 3.497491959002218
Official SDK using pydantic model: 31.92037604199868
Official SDK using http model: 6.780242209002608
Supported specification features
| Core Specification | v1.0 |
|---|---|
| CloudEvents Core | ✅ |
| Event Formats | v1.0 |
|---|---|
| AVRO Event Format | ❌ |
| JSON Event Format | ✅ |
| Protocol Bindings | v1.0 |
|---|---|
| HTTP Protocol Binding | ✅ |
| Kafka Protocol Binding | ❌ |
| Content Modes | v1.0 |
|---|---|
| HTTP Binary | ✅ |
| HTTP Structured | ✅ |
| HTTP Batch | ✅ |
| Kafka Binary | ❌ |
| Kafka Structured | ❌ |
| Kafka Batch | ❌ |
Commands for development
All the common commands used during development can be run using make targets:
make dev-dependencies: Install dev requirementsmake fix: Run code style and lint automatic fixes (where possible)make test: Run test suite against system python versionmake check: Run tests against all available python versions, code style and lint checksmake type,make format,make lint,make bandit: Run the relevant checkmake docs: Render the mkdocs website locally
Metadata
Release files for cloudevents-pydantic 0.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 | |
|---|---|---|---|
| cloudevents_pydantic-0.2.0.tar.gz | 12.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cloudevents_pydantic-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 36.0 kB
Release files / cloudevents_pydantic-0.2.0.tar.gz
| Download URL | cloudevents_pydantic-0.2.0.tar.gz |
|---|---|
| Size | 12.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
472a0973e6605057de1b9cc167fe4781cc0670d4169b26094aa6a6363b93373a
|
|
BLAKE2b-256 checksum How to use checksums |
1dbaf0fe53e7042c07683ca1c958ad3bea1e574b351c195713b4c86d211f0dd5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 12, 2025.
Transparency logRelease files / cloudevents_pydantic-0.2.0-py3-none-any.whl
| Download URL | cloudevents_pydantic-0.2.0-py3-none-any.whl |
|---|---|
| Size | 23.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
43a87f15d156767976d29afd2efe2bf7240d19d8a47d3394b543ab61cd04b822
|
|
BLAKE2b-256 checksum How to use checksums |
1821e23fa589874794e44ffd510493b0e67295521749de5cd912aec5f34d6efc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 12, 2025.
Transparency log