All Projects → cloudevents → sdk-python

cloudevents / sdk-python

Licence: Apache-2.0 license
Python SDK for CloudEvents

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to sdk-python

Toc
⚖️Technical Oversight Committee (TOC)
Stars: ✭ 951 (+538.26%)
Mutual labels:  cncf, cloudnative
Kruise
Automate application management on Kubernetes (project under CNCF)
Stars: ✭ 2,819 (+1791.95%)
Mutual labels:  cncf, cloudnative
Kubernetes-and-Cloud-Native-Associate-KCNA
Useful notes for the KCNA - Kubernetes and Cloud Native Associate
Stars: ✭ 162 (+8.72%)
Mutual labels:  cncf, cloudnative
Eventrouter
A simple introspective kubernetes service that forwards events to a specified sink.
Stars: ✭ 671 (+350.34%)
Mutual labels:  events, cncf
Aws Workshop For Kubernetes
AWS Workshop for Kubernetes
Stars: ✭ 2,450 (+1544.3%)
Mutual labels:  cncf, cloudnative
Kubecon Cloudnativecon Europe 2019
KubeCon-CloudNativeCon-Europe-2019's slides. / 2019欧洲CNCF大会PPT。
Stars: ✭ 62 (-58.39%)
Mutual labels:  cncf, cloudnative
Kubevela
The Modern Application Platform.
Stars: ✭ 2,984 (+1902.68%)
Mutual labels:  cncf, cloudnative
Kubecon North America 2018
KubeCon-CloudNativeCon-North-America-2018's slides. / 2018北美CNCF大会PPT。
Stars: ✭ 150 (+0.67%)
Mutual labels:  cncf, cloudnative
sources-for-knative
VMware-related event sources for Knative.
Stars: ✭ 24 (-83.89%)
Mutual labels:  events, cloudevents
Sdk Javascript
Javascript SDK for CloudEvents
Stars: ✭ 132 (-11.41%)
Mutual labels:  events, cncf
cla
✍CLAs for CNCF
Stars: ✭ 24 (-83.89%)
Mutual labels:  cncf
watermill-sql
SQL Pub/Sub for the Watermill project.
Stars: ✭ 39 (-73.83%)
Mutual labels:  events
wwwtf.berlin
wwwtf, a ~week of events organized for and by the web community
Stars: ✭ 46 (-69.13%)
Mutual labels:  events
wg-networking
📡📶CNCF Networking WG
Stars: ✭ 26 (-82.55%)
Mutual labels:  cncf
transceiver
Channel based event bus with request/reply pattern, using promises. For node & browser.
Stars: ✭ 25 (-83.22%)
Mutual labels:  events
Evilize
Parses Windows event logs files based on SANS Poster
Stars: ✭ 24 (-83.89%)
Mutual labels:  events
event
📆 Strictly typed event emitter with asynciterator support
Stars: ✭ 30 (-79.87%)
Mutual labels:  events
CKA-Exercises
A set of curated exercises to help prepare you for the Certified Kubernetes Administrator Exam by the Cloud Native Computing Foundation
Stars: ✭ 51 (-65.77%)
Mutual labels:  cncf
node-cqrs-saga
Node-cqrs-saga is a node.js module that helps to implement the sagas in cqrs. It can be very useful as domain component if you work with (d)ddd, cqrs, eventdenormalizer, host, etc.
Stars: ✭ 59 (-60.4%)
Mutual labels:  events
sdk-java
Java SDK for Serverless Workflow
Stars: ✭ 48 (-67.79%)
Mutual labels:  cncf

Python SDK for CloudEvents

PyPI version

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 library.

Binary HTTP CloudEvent

from cloudevents.http import CloudEvent, 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

from cloudevents.http import CloudEvent, to_structured
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.

Receiving CloudEvents

The code below shows how to consume a cloudevent using the popular python web framework flask:

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.

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

Each SDK may have its own unique processes, tooling and guidelines, common governance related material can be found in the CloudEvents docs directory. In particular, in there you will find information concerning how SDK projects are managed, guidelines for how PR reviews and approval, and our Code of Conduct information.

Maintenance

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

e.g.

pip install tox
tox -e reformat

For information on releasing version bumps see RELEASING.md

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].