Package: cumason123-helloworld
Automated PyPI Deployment sampleFor used github action seepypi-release.ymlFor automatically creating tags seepypi_packaging.pyTestPython SDK forCloudEventsStatusThis SDK is still considered a work in progress, therefore things might (and
will) break with every update.This SDK current supports the following versions of CloudEvents:v1.0v0.3Python SDKPackagecloudeventsprovides primitives to work with CloudEvents specification:https://github.com/cloudevents/spec.Parsing upstream structured Event from HTTP request:importiofromcloudevents.sdk.eventimportv1fromcloudevents.sdkimportmarshallerm=marshaller.NewDefaultHTTPMarshaller()event=m.FromRequest(v1.Event(),{"content-type":"application/cloudevents+json"},io.StringIO("""{"specversion": "1.0","datacontenttype": "application/json","type": "word.found.name","id": "96fb5f0b-001e-0108-6dfe-da6e2806f124","time": "2018-10-23T12:28:22.4579346Z","source": "<source-url>"}"""),lambdax:x.read(),)Parsing upstream binary Event from HTTP request:importiofromcloudevents.sdk.eventimportv1fromcloudevents.sdkimportmarshallerm=marshaller.NewDefaultHTTPMarshaller()event=m.FromRequest(v1.Event(),{"ce-specversion":"1.0","content-type":"application/json","ce-type":"word.found.name","ce-id":"96fb5f0b-001e-0108-6dfe-da6e2806f124","ce-time":"2018-10-23T12:28:22.4579346Z","ce-source":"<source-url>",},io.BytesIO(b"this is where your CloudEvent data"),lambdax:x.read(),)Creating a minimal CloudEvent in version 0.1:fromcloudevents.sdk.eventimportv1event=(v1.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:fromcloudevents.sdkimportconvertersfromcloudevents.sdkimportmarshallerfromcloudevents.sdk.convertersimportstructuredfromcloudevents.sdk.eventimportv1event=(v1.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()])headers,body=m.ToRequest(event,converters.TypeStructured,lambdax:x)HOWTOs with various Python HTTP frameworksIn this topic you'd find various example how to integrate an SDK with various HTTP frameworks.Python requestsOne of popular framework isrequests.CloudEvent to requestThe code below shows how integrate both libraries in order to convert a CloudEvent into an HTTP request:defrun_binary(event,url):binary_headers,binary_data=http_marshaller.ToRequest(event,converters.TypeBinary,json.dumps)print("binary CloudEvent")fork,vinbinary_headers.items():print("{0}:{1}\r\n".format(k,v))print(binary_data.getvalue())response=requests.post(url,headers=binary_headers,data=binary_data.getvalue())response.raise_for_status()defrun_structured(event,url):structured_headers,structured_data=http_marshaller.ToRequest(event,converters.TypeStructured,json.dumps)print("structured CloudEvent")print(structured_data.getvalue())response=requests.post(url,headers=structured_headers,data=structured_data.getvalue())response.raise_for_status()Complete example of turning a CloudEvent into a request you can findhere.Request to CloudEventThe code below shows how integrate both libraries in order to create a CloudEvent from an HTTP request:response=requests.get(url)response.raise_for_status()headers=response.headersdata=io.BytesIO(response.content)event=v1.Event()http_marshaller=marshaller.NewDefaultHTTPMarshaller()event=http_marshaller.FromRequest(event,headers,data,json.load)Complete example of turning a CloudEvent into a request you can findhere.SDK versioningThe 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.CommunityThere are bi-weekly calls immediately following theServerless/CloudEvents
callat
9am PT (US Pacific). Which means they will typically start at 10am PT, but
if the other call ends early then the SDK call will start early as well.
See theCloudEvents meeting minutesto determine which week will have the call.Slack: #cloudeventssdk channel underCNCF's Slack workspace.Email:https://lists.cncf.io/g/cncf-cloudevents-sdkContact for additional information: Denis Makogon (@denysmakogonon slack).