Python SDK for CloudEvents
Go to file
Denis Makogon 22b8b89676 Make SDK compliant with CloudEvents SDK spec
Signed-off-by: Denis Makogon <lildee1991@gmail.com>
2018-12-08 09:10:20 -05:00
.github Docs, CI, etc. 2018-11-19 11:52:09 +02:00
cloudevents Make SDK compliant with CloudEvents SDK spec 2018-12-08 09:10:20 -05:00
docs Sphinx docs 2018-11-19 12:07:30 +02:00
etc/docs_conf Sphinx docs 2018-11-19 12:07:30 +02:00
.gitignore Make SDK compliant with CloudEvents SDK spec 2018-12-08 09:10:20 -05:00
LICENSE Initial commit 2018-09-21 18:42:34 -04:00
Makefile Sphinx docs 2018-11-19 12:07:30 +02:00
README.md Make SDK compliant with CloudEvents SDK spec 2018-12-08 09:10:20 -05:00
circle.yml Docs, CI, etc. 2018-11-19 11:52:09 +02:00
release.sh Initial release: CloudEvents Python SDK 0.0.1a0 2018-11-19 11:52:09 +02:00
release_doc.md Initial release: CloudEvents Python SDK 0.0.1a0 2018-11-19 11:52:09 +02:00
requirements.txt Sphinx docs 2018-11-19 12:07:30 +02:00
setup.cfg Initial release: CloudEvents Python SDK 0.0.1a0 2018-11-19 11:52:09 +02:00
setup.py Initial release: CloudEvents Python SDK 0.0.1a0 2018-11-19 11:52:09 +02:00
test-requirements.txt test requirements update 2018-11-19 11:52:09 +02:00
tox.ini Sphinx docs 2018-11-19 12:07:30 +02:00

README.md

Python SDK for CloudEvents

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:

from cloudevents.sdk.event import v02
from cloudevents.sdk import marshaller

data = "<this is where your CloudEvent comes from>"
m = marshaller.NewDefaultHTTPMarshaller(v02.Event)
event = m.FromRequest(
    {"Content-Type": "application/cloudevents+json"}, 
    data, 
    lambda x: x.read()
)

Creating a minimal CloudEvent in version 0.1:

from cloudevents.sdk.event import v01

event = (
    v01.Event().
    SetContentType("application/json").
    SetData('{"name":"john"}').
    SetEventID("my-id").
    SetSource("from-galaxy-far-far-away").
    SetEventTime("tomorrow").
    SetEventType("cloudevent.greet.you")
)

Creating HTTP request from CloudEvent:

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().
    SetContentType("application/json").
    SetData('{"name":"john"}').
    SetEventID("my-id").
    SetSource("from-galaxy-far-far-away").
    SetEventTime("tomorrow").
    SetEventType("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.