Skip to content

Commit 106691e

Browse files
committed
docs(migration): add guidance for using cloudevents.v1 compatibility layer
Signed-off-by: Yurii Serhiichuk <savik.ne@gmail.com>
1 parent 6ad58e4 commit 106691e

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

MIGRATION.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,31 @@ This guide covers the breaking changes and new patterns introduced in v2 of the
99
| Python | 3.7+ | **3.10+** |
1010
| Dependencies | varies (optional `pydantic` extra) | `python-dateutil>=2.8.2` only |
1111

12+
## Intermediate Step: `cloudevents.v1` Compatibility Layer
13+
14+
If you are not ready to migrate to the v2 core API, the `cloudevents.v1` package provides a drop-in compatibility layer that preserves the v1 API under a new namespace. This lets you unpin from the old top-level imports without rewriting your event-handling logic.
15+
16+
Swap the old top-level imports for their `cloudevents.v1.*` equivalents:
17+
18+
| Old import | Compat layer import |
19+
|---|---|
20+
| `from cloudevents.http import CloudEvent` | `from cloudevents.v1.http import CloudEvent` |
21+
| `from cloudevents.http import from_http` | `from cloudevents.v1.http import from_http` |
22+
| `from cloudevents.http import from_json` | `from cloudevents.v1.http import from_json` |
23+
| `from cloudevents.http import from_dict` | `from cloudevents.v1.http import from_dict` |
24+
| `from cloudevents.conversion import to_binary` | `from cloudevents.v1.http import to_binary` |
25+
| `from cloudevents.conversion import to_structured` | `from cloudevents.v1.http import to_structured` |
26+
| `from cloudevents.conversion import to_json` | `from cloudevents.v1.http import to_json` |
27+
| `from cloudevents.conversion import to_dict` | `from cloudevents.v1.conversion import to_dict` |
28+
| `from cloudevents.kafka import KafkaMessage` | `from cloudevents.v1.kafka import KafkaMessage` |
29+
| `from cloudevents.kafka import to_binary` | `from cloudevents.v1.kafka import to_binary` |
30+
| `from cloudevents.kafka import from_binary` | `from cloudevents.v1.kafka import from_binary` |
31+
| `from cloudevents.pydantic import CloudEvent` | `from cloudevents.v1.pydantic import CloudEvent` |
32+
33+
The compat layer behaviour is identical to the old v1 SDK: events are dict-like and mutable, marshallers/unmarshallers are accepted as callables, and `is_binary`/`is_structured` helpers are still available. The compat layer does **not** enforce strict mypy and is not under the v2 validation rules.
34+
35+
When you are ready to move fully to v2, follow the rest of this guide.
36+
1237
## Architectural Changes
1338

1439
v2 is a ground-up rewrite with four fundamental shifts:

0 commit comments

Comments
 (0)