Package: cloudevents
Python 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.InstallingThe CloudEvents SDK can be installed with pip:pip install cloudeventsSending CloudEventsBelow we will provide samples on how to send cloudevents using the popularrequestslibrary.Binary HTTP CloudEventfromcloudevents.httpimportCloudEventfromcloudevents.conversionimportto_binaryimportrequests# Create a CloudEvent# - The CloudEvent "id" is generated if omitted. "specversion" defaults to "1.0".attributes={"type":"com.example.sampletype1","source":"https://example.com/event-producer",}data={"message":"Hello World!"}event=CloudEvent(attributes,data)# Creates the HTTP request representation of the CloudEvent in binary content modeheaders,body=to_binary(event)# POSTrequests.post("<some-url>",data=body,headers=headers)Structured HTTP CloudEventfromcloudevents.conversionimportto_structuredfromcloudevents.httpimportCloudEventimportrequests# Create a CloudEvent# - The CloudEvent "id" is generated if omitted. "specversion" defaults to "1.0".attributes={"type":"com.example.sampletype2","source":"https://example.com/event-producer",}data={"message":"Hello World!"}event=CloudEvent(attributes,data)# Creates the HTTP request representation of the CloudEvent in structured content modeheaders,body=to_structured(event)# POSTrequests.post("<some-url>",data=body,headers=headers)You can find a complete example of turning a CloudEvent into a HTTP requestin the samples' directory.Receiving CloudEventsThe code below shows how to consume a cloudevent using the popular python web frameworkflask:fromflaskimportFlask,requestfromcloudevents.httpimportfrom_httpapp=Flask(__name__)# create an endpoint at http://localhost:/3000/@app.route("/",methods=["POST"])defhome():# create a CloudEventevent=from_http(request.headers,request.get_data())# you can access cloudevent fields as seen belowprint(f"Found{event['id']}from{event['source']}with type "f"{event['type']}and specversion{event['specversion']}")return"",204if__name__=="__main__":app.run(port=3000)You can find a complete example of turning a CloudEvent into a HTTP requestin the samples' directory.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).Each SDK may have its own unique processes, tooling and guidelines, common
governance related material can be found in theCloudEventsdocsdirectory. In particular, in there you will find information concerning
how SDK projects aremanaged,guidelinesfor how PR reviews and approval, and ourCode of Conductinformation.If there is a security concern with one of the CloudEvents specifications, or
with one of the project's SDKs, please send an email tocncf-cloudevents-security@lists.cncf.io.Additional SDK ResourcesList of current active maintainersHow to contribute to the projectSDK's LicenseSDK's Release processMaintenanceWe useblackandisortfor autoformatting. We set up atoxenvironment to reformat the codebase.e.g.pipinstalltox
tox-ereformatFor information on releasing version bumps seeRELEASING.md