{"id":18936629,"url":"https://github.com/cloudevents/sdk-python","last_synced_at":"2025-05-14T11:08:51.593Z","repository":{"id":41190244,"uuid":"149825820","full_name":"cloudevents/sdk-python","owner":"cloudevents","description":"Python SDK for CloudEvents","archived":false,"fork":false,"pushed_at":"2025-03-03T16:54:39.000Z","size":548,"stargazers_count":304,"open_issues_count":21,"forks_count":58,"subscribers_count":12,"default_branch":"main","last_synced_at":"2025-04-13T00:39:38.630Z","etag":null,"topics":["cloudevents","cloudevents-schema","cloudnative","cncf","events","python","python3","serverless"],"latest_commit_sha":null,"homepage":"https://pypi.org/p/cloudevents/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cloudevents.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-09-21T22:42:33.000Z","updated_at":"2025-04-04T16:50:42.000Z","dependencies_parsed_at":"2024-03-12T20:46:07.523Z","dependency_job_id":"998a320f-699c-4533-8018-5b746392f844","html_url":"https://github.com/cloudevents/sdk-python","commit_stats":{"total_commits":94,"total_committers":25,"mean_commits":3.76,"dds":0.7553191489361702,"last_synced_commit":"c5645d8fcf03432639727b9a7f6508c3059a1673"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudevents%2Fsdk-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudevents%2Fsdk-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudevents%2Fsdk-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudevents%2Fsdk-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cloudevents","download_url":"https://codeload.github.com/cloudevents/sdk-python/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254129482,"owners_count":22019628,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudevents","cloudevents-schema","cloudnative","cncf","events","python","python3","serverless"],"created_at":"2024-11-08T12:08:17.010Z","updated_at":"2025-05-14T11:08:51.549Z","avatar_url":"https://github.com/cloudevents.png","language":"Python","readme":"# Python SDK for [CloudEvents](https://github.com/cloudevents/spec)\n\n[![PyPI version](https://badge.fury.io/py/cloudevents.svg)](https://badge.fury.io/py/cloudevents)\n\n## Status\n\nThis SDK is still considered a work in progress, therefore things might (and\nwill) break with every update.\n\nThis SDK current supports the following versions of CloudEvents:\n\n- v1.0\n- v0.3\n\n## Python SDK\n\nPackage **cloudevents** provides primitives to work with CloudEvents specification:\nhttps://github.com/cloudevents/spec.\n\n### Installing\n\nThe CloudEvents SDK can be installed with pip:\n\n```\npip install cloudevents\n```\n\n## Sending CloudEvents\n\nBelow we will provide samples on how to send cloudevents using the popular\n[`requests`](http://docs.python-requests.org) library.\n\n### Binary HTTP CloudEvent\n\n```python\nfrom cloudevents.http import CloudEvent\nfrom cloudevents.conversion import to_binary\nimport requests\n\n# Create a CloudEvent\n# - The CloudEvent \"id\" is generated if omitted. \"specversion\" defaults to \"1.0\".\nattributes = {\n    \"type\": \"com.example.sampletype1\",\n    \"source\": \"https://example.com/event-producer\",\n}\ndata = {\"message\": \"Hello World!\"}\nevent = CloudEvent(attributes, data)\n\n# Creates the HTTP request representation of the CloudEvent in binary content mode\nheaders, body = to_binary(event)\n\n# POST\nrequests.post(\"\u003csome-url\u003e\", data=body, headers=headers)\n```\n\n### Structured HTTP CloudEvent\n\n```python\nfrom cloudevents.conversion import to_structured\nfrom cloudevents.http import CloudEvent\nimport requests\n\n# Create a CloudEvent\n# - The CloudEvent \"id\" is generated if omitted. \"specversion\" defaults to \"1.0\".\nattributes = {\n    \"type\": \"com.example.sampletype2\",\n    \"source\": \"https://example.com/event-producer\",\n}\ndata = {\"message\": \"Hello World!\"}\nevent = CloudEvent(attributes, data)\n\n# Creates the HTTP request representation of the CloudEvent in structured content mode\nheaders, body = to_structured(event)\n\n# POST\nrequests.post(\"\u003csome-url\u003e\", data=body, headers=headers)\n```\n\nYou can find a complete example of turning a CloudEvent into a HTTP request\n[in the samples' directory](samples/http-json-cloudevents/client.py).\n\n## Receiving CloudEvents\n\nThe code below shows how to consume a cloudevent using the popular python web framework\n[flask](https://flask.palletsprojects.com/en/2.2.x/quickstart/):\n\n```python\nfrom flask import Flask, request\n\nfrom cloudevents.http import from_http\n\napp = Flask(__name__)\n\n\n# create an endpoint at http://localhost:/3000/\n@app.route(\"/\", methods=[\"POST\"])\ndef home():\n    # create a CloudEvent\n    event = from_http(request.headers, request.get_data())\n\n    # you can access cloudevent fields as seen below\n    print(\n        f\"Found {event['id']} from {event['source']} with type \"\n        f\"{event['type']} and specversion {event['specversion']}\"\n    )\n\n    return \"\", 204\n\n\nif __name__ == \"__main__\":\n    app.run(port=3000)\n```\n\nYou can find a complete example of turning a CloudEvent into a HTTP request\n[in the samples' directory](samples/http-json-cloudevents/json_sample_server.py).\n\n## SDK versioning\n\nThe goal of this package is to provide support for all released versions of CloudEvents,\nideally while maintaining the same API. It will use semantic versioning\nwith following rules:\n\n- MAJOR version increments when backwards incompatible changes is introduced.\n- MINOR version increments when backwards compatible feature is introduced\n  INCLUDING support for new CloudEvents version.\n- PATCH version increments when a backwards compatible bug fix is introduced.\n\n## Community\n\n- There are bi-weekly calls immediately following the [Serverless/CloudEvents\n  call](https://github.com/cloudevents/spec#meeting-time) at\n  9am PT (US Pacific). Which means they will typically start at 10am PT, but\n  if the other call ends early then the SDK call will start early as well.\n  See the [CloudEvents meeting minutes](https://docs.google.com/document/d/1OVF68rpuPK5shIHILK9JOqlZBbfe91RNzQ7u_P7YCDE/edit#)\n  to determine which week will have the call.\n- Slack: #cloudeventssdk channel under\n  [CNCF's Slack workspace](https://slack.cncf.io/).\n- Email: https://lists.cncf.io/g/cncf-cloudevents-sdk\n- Contact for additional information: Denis Makogon (`@denysmakogon` on slack).\n\nEach SDK may have its own unique processes, tooling and guidelines, common\ngovernance related material can be found in the\n[CloudEvents `docs`](https://github.com/cloudevents/spec/tree/main/docs)\ndirectory. In particular, in there you will find information concerning\nhow SDK projects are\n[managed](https://github.com/cloudevents/spec/blob/main/docs/GOVERNANCE.md),\n[guidelines](https://github.com/cloudevents/spec/blob/main/docs/SDK-maintainer-guidelines.md)\nfor how PR reviews and approval, and our\n[Code of Conduct](https://github.com/cloudevents/spec/blob/main/docs/GOVERNANCE.md#additional-information)\ninformation.\n\nIf there is a security concern with one of the CloudEvents specifications, or\nwith one of the project's SDKs, please send an email to\n[cncf-cloudevents-security@lists.cncf.io](mailto:cncf-cloudevents-security@lists.cncf.io).\n\n## Additional SDK Resources\n\n- [List of current active maintainers](MAINTAINERS.md)\n- [How to contribute to the project](CONTRIBUTING.md)\n- [SDK's License](LICENSE)\n- [SDK's Release process](RELEASING.md)\n\n## Maintenance\n\nWe use [black][black] and [isort][isort] for autoformatting. We set up a [tox][tox]\nenvironment to reformat the codebase.\n\ne.g.\n\n```bash\npip install tox\ntox -e reformat\n```\n\nFor information on releasing version bumps see [RELEASING.md](RELEASING.md)\n\n[black]: https://black.readthedocs.io/\n[isort]: https://pycqa.github.io/isort/\n[tox]: https://tox.wiki/\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudevents%2Fsdk-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloudevents%2Fsdk-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudevents%2Fsdk-python/lists"}