Docs, CI, etc.
Signed-off-by: Denis Makogon <lildee1991@gmail.com>
This commit is contained in:
parent
132fe61a8c
commit
9b5152546a
|
@ -0,0 +1,9 @@
|
|||
- Link to issue this resolves
|
||||
|
||||
- What I did
|
||||
|
||||
- How I did it
|
||||
|
||||
- How to verify it
|
||||
|
||||
- One line description for the changelog
|
66
README.md
66
README.md
|
@ -1,2 +1,64 @@
|
|||
# sdk-python
|
||||
Python SDK for CloudEvents
|
||||
# Python SDK for [CloudEvents](https://github.com/cloudevents/spec)
|
||||
|
||||
**NOTE: This SDK is still considered work in progress, things might (and will) break with every update.**
|
||||
|
||||
Package **cloudevents** provides primitives to work with CloudEvents specification: https://github.com/cloudevents/spec.
|
||||
|
||||
Parsing upstream Event from HTTP Request:
|
||||
```python
|
||||
from cloudevents.sdk.event import upstream
|
||||
from cloudevents.sdk import marshaller
|
||||
|
||||
data = "<this is where your CloudEvent comes from>"
|
||||
m = marshaller.NewDefaultHTTPMarshaller(upstream.Event)
|
||||
event = m.FromRequest({"Content-Type": "application/cloudevents+json"}, data)
|
||||
|
||||
```
|
||||
|
||||
Creating a minimal CloudEvent in version 0.1:
|
||||
```python
|
||||
from cloudevents.sdk.event import v01
|
||||
|
||||
event = (
|
||||
v01.Event().
|
||||
WithContentType("application/json").
|
||||
WithData('{"name":"john"}').
|
||||
WithEventID("my-id").
|
||||
WithSource("from-galaxy-far-far-away").
|
||||
WithEventTime("tomorrow").
|
||||
WithEventType("cloudevent.greet.you")
|
||||
)
|
||||
|
||||
```
|
||||
|
||||
Creating HTTP request from CloudEvent:
|
||||
```python
|
||||
from cloudevents.sdk import converters
|
||||
from cloudevents.sdk import marshaller
|
||||
from cloudevents.sdk.converters import structured
|
||||
from cloudevents.sdk.event import v01
|
||||
|
||||
event = (
|
||||
v01.Event().
|
||||
WithContentType("application/json").
|
||||
WithData('{"name":"john"}').
|
||||
WithEventID("my-id").
|
||||
WithSource("from-galaxy-far-far-away").
|
||||
WithEventTime("tomorrow").
|
||||
WithEventType("cloudevent.greet.you")
|
||||
)
|
||||
m = marshaller.NewHTTPMarshaller(
|
||||
[
|
||||
structured.NewJSONHTTPCloudEventConverter(type(event))
|
||||
]
|
||||
)
|
||||
|
||||
headers, body = m.ToRequest(event, converters.TypeStructured, lambda x: x)
|
||||
|
||||
```
|
||||
|
||||
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.
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
version: 2
|
||||
jobs:
|
||||
build:
|
||||
docker:
|
||||
- image: circleci/python:3.7.0
|
||||
working_directory: ~/sdk-python
|
||||
steps:
|
||||
- checkout
|
||||
- restore_cache:
|
||||
key: deps1-{{ .Branch }}-{{ checksum "requirements.txt" }}
|
||||
- setup_remote_docker:
|
||||
docker_layer_caching: true
|
||||
- run:
|
||||
command: |
|
||||
python3 -m venv venv
|
||||
. venv/bin/activate
|
||||
pip install tox
|
||||
pip install -r requirements.txt
|
||||
- save_cache:
|
||||
key: deps1-{{ .Branch }}-{{ checksum "requirements.txt" }}
|
||||
paths:
|
||||
- "venv"
|
||||
- run:
|
||||
command: |
|
||||
. venv/bin/activate
|
||||
tox -epep8
|
||||
- run:
|
||||
command: |
|
||||
. venv/bin/activate
|
||||
tox -epy3.7
|
Loading…
Reference in New Issue