cloudevents


Namecloudevents JSON
Version 1.10.1 PyPI version JSON
download
home_pagehttps://github.com/cloudevents/sdk-python
SummaryCloudEvents Python SDK
upload_time2023-10-30 05:46:04
maintainer
docs_urlNone
authorThe Cloud Events Contributors
requires_python
licensehttps://www.apache.org/licenses/LICENSE-2.0
keywords cloudevents eventing serverless
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # Python SDK for [CloudEvents](https://github.com/cloudevents/spec)

[![PyPI version](https://badge.fury.io/py/cloudevents.svg)](https://badge.fury.io/py/cloudevents)

## Status

This 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.0
- v0.3

## Python SDK

Package **cloudevents** provides primitives to work with CloudEvents specification:
https://github.com/cloudevents/spec.

### Installing

The CloudEvents SDK can be installed with pip:

```
pip install cloudevents
```

## Sending CloudEvents

Below we will provide samples on how to send cloudevents using the popular
[`requests`](http://docs.python-requests.org) library.

### Binary HTTP CloudEvent

```python
from cloudevents.http import CloudEvent
from cloudevents.conversion import to_binary
import requests

# 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 mode
headers, body = to_binary(event)

# POST
requests.post("<some-url>", data=body, headers=headers)
```

### Structured HTTP CloudEvent

```python
from cloudevents.conversion import to_structured
from cloudevents.http import CloudEvent
import requests

# 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 mode
headers, body = to_structured(event)

# POST
requests.post("<some-url>", data=body, headers=headers)
```

You can find a complete example of turning a CloudEvent into a HTTP request
[in the samples' directory](samples/http-json-cloudevents/client.py).

## Receiving CloudEvents

The code below shows how to consume a cloudevent using the popular python web framework
[flask](https://flask.palletsprojects.com/en/2.2.x/quickstart/):

```python
from flask import Flask, request

from cloudevents.http import from_http

app = Flask(__name__)


# create an endpoint at http://localhost:/3000/
@app.route("/", methods=["POST"])
def home():
    # create a CloudEvent
    event = from_http(request.headers, request.get_data())

    # you can access cloudevent fields as seen below
    print(
        f"Found {event['id']} from {event['source']} with type "
        f"{event['type']} and specversion {event['specversion']}"
    )

    return "", 204


if __name__ == "__main__":
    app.run(port=3000)
```

You can find a complete example of turning a CloudEvent into a HTTP request
[in the samples' directory](samples/http-json-cloudevents/json_sample_server.py).

## SDK versioning

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.

## Community

- There are bi-weekly calls immediately following the [Serverless/CloudEvents
  call](https://github.com/cloudevents/spec#meeting-time) at
  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 the [CloudEvents meeting minutes](https://docs.google.com/document/d/1OVF68rpuPK5shIHILK9JOqlZBbfe91RNzQ7u_P7YCDE/edit#)
  to determine which week will have the call.
- Slack: #cloudeventssdk channel under
  [CNCF's Slack workspace](https://slack.cncf.io/).
- Email: https://lists.cncf.io/g/cncf-cloudevents-sdk
- Contact for additional information: Denis Makogon (`@denysmakogon` on slack).

Each SDK may have its own unique processes, tooling and guidelines, common
governance related material can be found in the
[CloudEvents `docs`](https://github.com/cloudevents/spec/tree/main/docs)
directory. In particular, in there you will find information concerning
how SDK projects are
[managed](https://github.com/cloudevents/spec/blob/main/docs/GOVERNANCE.md),
[guidelines](https://github.com/cloudevents/spec/blob/main/docs/SDK-maintainer-guidelines.md)
for how PR reviews and approval, and our
[Code of Conduct](https://github.com/cloudevents/spec/blob/main/docs/GOVERNANCE.md#additional-information)
information.

If there is a security concern with one of the CloudEvents specifications, or
with one of the project's SDKs, please send an email to
[cncf-cloudevents-security@lists.cncf.io](mailto:cncf-cloudevents-security@lists.cncf.io).

## Additional SDK Resources

- [List of current active maintainers](MAINTAINERS.md)
- [How to contribute to the project](CONTRIBUTING.md)
- [SDK's License](LICENSE)
- [SDK's Release process](RELEASING.md)

## Maintenance

We use [black][black] and [isort][isort] for autoformatting. We set up a [tox][tox]
environment to reformat the codebase.

e.g.

```bash
pip install tox
tox -e reformat
```

For information on releasing version bumps see [RELEASING.md](RELEASING.md)

[black]: https://black.readthedocs.io/
[isort]: https://pycqa.github.io/isort/
[tox]: https://tox.wiki/

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/cloudevents/sdk-python",
    "name": "cloudevents",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "CloudEvents Eventing Serverless",
    "author": "The Cloud Events Contributors",
    "author_email": "cncfcloudevents@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/bf/2f/c606ce74c9ec25ffa6c8dcdff3e4a9fd6db562d546430e98c739345b8189/cloudevents-1.10.1.tar.gz",
    "platform": null,
    "description": "# 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(\"<some-url>\", 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(\"<some-url>\", 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",
    "bugtrack_url": null,
    "license": "https://www.apache.org/licenses/LICENSE-2.0",
    "summary": "CloudEvents Python SDK",
    "version": "1.10.1",
    "project_urls": {
        "Homepage": "https://github.com/cloudevents/sdk-python"
    },
    "split_keywords": [
        "cloudevents",
        "eventing",
        "serverless"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2f68f2baa380844c108a9f7788a139200839b067d1b185c5b0e4bee04d20768f",
                "md5": "edc2df8a16ffcab1cea73960e398252a",
                "sha256": "832f1e3cca0887ab8f993cd2c0645a2155e73792f740d86f7b4bc8620a10d50e"
            },
            "downloads": -1,
            "filename": "cloudevents-1.10.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "edc2df8a16ffcab1cea73960e398252a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 55047,
            "upload_time": "2023-10-30T05:46:02",
            "upload_time_iso_8601": "2023-10-30T05:46:02.869886Z",
            "url": "https://files.pythonhosted.org/packages/2f/68/f2baa380844c108a9f7788a139200839b067d1b185c5b0e4bee04d20768f/cloudevents-1.10.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bf2fc606ce74c9ec25ffa6c8dcdff3e4a9fd6db562d546430e98c739345b8189",
                "md5": "c75791c7fa72f2c1789315c1eb4c8e21",
                "sha256": "984d90aa114deeb1c37ceecf78f9dc9d56f5866cf10b45142a23c84d22621ac9"
            },
            "downloads": -1,
            "filename": "cloudevents-1.10.1.tar.gz",
            "has_sig": false,
            "md5_digest": "c75791c7fa72f2c1789315c1eb4c8e21",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 33480,
            "upload_time": "2023-10-30T05:46:04",
            "upload_time_iso_8601": "2023-10-30T05:46:04.627681Z",
            "url": "https://files.pythonhosted.org/packages/bf/2f/c606ce74c9ec25ffa6c8dcdff3e4a9fd6db562d546430e98c739345b8189/cloudevents-1.10.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-30 05:46:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "cloudevents",
    "github_project": "sdk-python",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "tox": true,
    "lcname": "cloudevents"
}
        
Elapsed time: 0.15714s