Skip to content

feat(core): add JSON Batch format and HTTP batched mode - #334

Open
EmiRZx wants to merge 2 commits into
cloudevents:mainfrom
EmiRZx:json-batch-format
Open

EmiRZx wants to merge 2 commits into
cloudevents:mainfrom
EmiRZx:json-batch-format

Conversation

@EmiRZx

@EmiRZx EmiRZx commented Dec 1, 2026

Copy link
Copy Markdown

Related Issue: #130

Type of change:

  • New feature (non-breaking change which adds functionality)

Description:

builds on #299 and its review.

  • formats.base.BatchFormat: runtime-checkable protocol, separate from Format; JSONFormat implements it.
  • JSONFormat.write_batch / read_batch: JSON array of JSON-format events. errors name the failing index and the actual type.
  • All events in a batch must have the same specversion (core spec, "Event batching"); enforced on read and write.
  • HTTP: to_batch / from_batch, plus to_events_batch / from_events_batch defaulting to JSONFormat.
  • from_http raises ValueError pointing to from_batch when the content type is the batch media type.
  • batch writers take Sequence[BaseCloudEvent], so list[CloudEvent] type-checks.

Pre-submission checklist:

  • I have read the CONTRIBUTING.md file.
  • I have signed off my commits using git commit --signoff.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have updated the documentation (README.md, CHANGELOG.md, etc.) as necessary.
  • I have run pre-commit and tox and all checks pass. (no tox config in the repo; ran uv run pytest tests: 589 passed.)
  • This pull request is ready to be reviewed.

EmiRZx and others added 2 commits December 1, 2026 17:56
Add a BatchFormat protocol, JSONFormat.write_batch/read_batch, and the
HTTP to_batch/from_batch helpers with to_events_batch/from_events_batch
wrappers. All events in a batch must have the same specversion.
from_http now points batched messages to from_batch.

Builds on the design and review of cloudevents#299.

Co-authored-by: PlugaruT <plugaru.tudor@protonmail.com>
Signed-off-by: emir <52245396+EmiRZx@users.noreply.github.com>
Signed-off-by: emir <52245396+EmiRZx@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant