- Notifications
You must be signed in to change notification settings - Fork61
cloudevents/sdk-python
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Python SDK forCloudEvents
This SDK is still considered a work in progress, therefore things might (andwill) break with every update.
This SDK current supports the following versions of CloudEvents:
- v1.0
- v0.3
Packagecloudevents provides primitives to work with CloudEvents specification:https://github.com/cloudevents/spec.
The CloudEvents SDK can be installed with pip:
pip install cloudeventsBelow we will provide samples on how to send cloudevents using the popularrequests library.
fromcloudevents.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)
fromcloudevents.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.
The 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.
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 versioningwith following rules:
- MAJOR version increments when backwards incompatible changes is introduced.
- MINOR version increments when backwards compatible feature is introducedINCLUDING support for new CloudEvents version.
- PATCH version increments when a backwards compatible bug fix is introduced.
- There are bi-weekly calls immediately following theServerless/CloudEventscall at9am PT (US Pacific). Which means they will typically start at 10am PT, butif 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-sdk
- Contact for additional information: Denis Makogon (
@denysmakogonon slack).
Each SDK may have its own unique processes, tooling and guidelines, commongovernance related material can be found in theCloudEventsdocsdirectory. In particular, in there you will find information concerninghow 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, orwith one of the project's SDKs, please send an email tocncf-cloudevents-security@lists.cncf.io.
- List of current active maintainers
- How to contribute to the project
- SDK's License
- SDK's Release process
We useblack andisort for autoformatting. We set up atoxenvironment to reformat the codebase.
e.g.
pip install toxtox -e reformat
For information on releasing version bumps seeRELEASING.md
About
Python SDK for CloudEvents
Topics
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.