CloudEvents SDK Python
Project description
# Python SDK for [CloudEvents](https://github.com/cloudevents/spec)
**NOTE: This SDK is still considered work in progress, things might (and will) break with every update.**
Package **cloudevents** provides primitives to work with CloudEvents specification: https://github.com/cloudevents/spec.
Parsing upstream Event from HTTP Request:
```python
from cloudevents.sdk.event import upstream
from cloudevents.sdk import marshaller
data = "<this is where your CloudEvent comes from>"
m = marshaller.NewDefaultHTTPMarshaller(upstream.Event)
event = m.FromRequest(
{"Content-Type": "application/cloudevents+json"},
data,
lambda x: x.read()
)
```
Creating a minimal CloudEvent in version 0.1:
```python
from cloudevents.sdk.event import v01
event = (
v01.Event().
WithContentType("application/json").
WithData('{"name":"john"}').
WithEventID("my-id").
WithSource("from-galaxy-far-far-away").
WithEventTime("tomorrow").
WithEventType("cloudevent.greet.you")
)
```
Creating HTTP request from CloudEvent:
```python
from cloudevents.sdk import converters
from cloudevents.sdk import marshaller
from cloudevents.sdk.converters import structured
from cloudevents.sdk.event import v01
event = (
v01.Event().
WithContentType("application/json").
WithData('{"name":"john"}').
WithEventID("my-id").
WithSource("from-galaxy-far-far-away").
WithEventTime("tomorrow").
WithEventType("cloudevent.greet.you")
)
m = marshaller.NewHTTPMarshaller(
[
structured.NewJSONHTTPCloudEventConverter(type(event))
]
)
headers, body = m.ToRequest(event, converters.TypeStructured, lambda x: x)
```
The goal of this package is to provide support for all released versions of CloudEvents, ideally while maintaining
the same API. It will use semantic versioning with following rules:
* MAJOR version increments when backwards incompatible changes is introduced.
* MINOR version increments when backwards compatible feature is introduced INCLUDING support for new CloudEvents version.
* PATCH version increments when a backwards compatible bug fix is introduced.
**NOTE: This SDK is still considered work in progress, things might (and will) break with every update.**
Package **cloudevents** provides primitives to work with CloudEvents specification: https://github.com/cloudevents/spec.
Parsing upstream Event from HTTP Request:
```python
from cloudevents.sdk.event import upstream
from cloudevents.sdk import marshaller
data = "<this is where your CloudEvent comes from>"
m = marshaller.NewDefaultHTTPMarshaller(upstream.Event)
event = m.FromRequest(
{"Content-Type": "application/cloudevents+json"},
data,
lambda x: x.read()
)
```
Creating a minimal CloudEvent in version 0.1:
```python
from cloudevents.sdk.event import v01
event = (
v01.Event().
WithContentType("application/json").
WithData('{"name":"john"}').
WithEventID("my-id").
WithSource("from-galaxy-far-far-away").
WithEventTime("tomorrow").
WithEventType("cloudevent.greet.you")
)
```
Creating HTTP request from CloudEvent:
```python
from cloudevents.sdk import converters
from cloudevents.sdk import marshaller
from cloudevents.sdk.converters import structured
from cloudevents.sdk.event import v01
event = (
v01.Event().
WithContentType("application/json").
WithData('{"name":"john"}').
WithEventID("my-id").
WithSource("from-galaxy-far-far-away").
WithEventTime("tomorrow").
WithEventType("cloudevent.greet.you")
)
m = marshaller.NewHTTPMarshaller(
[
structured.NewJSONHTTPCloudEventConverter(type(event))
]
)
headers, body = m.ToRequest(event, converters.TypeStructured, lambda x: x)
```
The goal of this package is to provide support for all released versions of CloudEvents, ideally while maintaining
the same API. It will use semantic versioning with following rules:
* MAJOR version increments when backwards incompatible changes is introduced.
* MINOR version increments when backwards compatible feature is introduced INCLUDING support for new CloudEvents version.
* PATCH version increments when a backwards compatible bug fix is introduced.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
cloudevents-0.0.1.tar.gz
(188.3 kB
view details)
Built Distribution
File details
Details for the file cloudevents-0.0.1.tar.gz
.
File metadata
- Download URL: cloudevents-0.0.1.tar.gz
- Upload date:
- Size: 188.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21ccf8150fbf8c6eb4849fc4ec7467b045afd43b9880ffbd91b2b25d560217fc |
|
MD5 | a78da4d39a68d7a9a77253be87826cf3 |
|
BLAKE2b-256 | d14a7f03c89f458b82911ae5deea86e0359496e05079a876badaa4a3ab64917f |
Provenance
File details
Details for the file cloudevents-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: cloudevents-0.0.1-py3-none-any.whl
- Upload date:
- Size: 21.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3aec073f32edfce9f31cae94470bebea7cbc9d634cd316df4c4b3617dabce791 |
|
MD5 | 42317151592840256e02ba1525b7326d |
|
BLAKE2b-256 | 13b8080aba2a3bdc874798c4a48a4458ac82f96a8cd9e5770c0473b58fc32ac0 |