Skip to content

Commit

Permalink
Release v1.0.0 (#89)
Browse files Browse the repository at this point in the history
* Created CloudEvent class (#36)

CloudEvents is a more pythonic interface for using cloud events.
It is powered by internal marshallers and cloud event base classes.
It performs basic validation on fields, and cloud event type checking.

Signed-off-by: Curtis Mason <cumason@google.com>
Signed-off-by: Dustin Ingram <di@users.noreply.github.com>

* Implemented python properties in base.py (#41)

* Added SetCloudEventVersion

Signed-off-by: Curtis Mason <cumason@google.com>
Signed-off-by: Dustin Ingram <di@users.noreply.github.com>

* began adding python properties

Signed-off-by: Curtis Mason <cumason@google.com>
Signed-off-by: Dustin Ingram <di@users.noreply.github.com>

* added pythonic properties to base class

Signed-off-by: Curtis Mason <cumason@google.com>
Signed-off-by: Dustin Ingram <di@users.noreply.github.com>

* began testing for getters/setters

Signed-off-by: Curtis Mason <cumason@google.com>
Signed-off-by: Dustin Ingram <di@users.noreply.github.com>

* added general setter tests

Signed-off-by: Curtis Mason <cumason@google.com>
Signed-off-by: Dustin Ingram <di@users.noreply.github.com>

* fixed spacing in base.py

Signed-off-by: Curtis Mason <cumason@google.com>
Signed-off-by: Dustin Ingram <di@users.noreply.github.com>

* added __eq__ to option and datacontentencoding property to v03

Signed-off-by: Curtis Mason <cumason@google.com>
Signed-off-by: Dustin Ingram <di@users.noreply.github.com>

* lint fixes

Signed-off-by: Curtis Mason <cumason@google.com>
Signed-off-by: Dustin Ingram <di@users.noreply.github.com>

* testing extensions and old getters

Signed-off-by: Curtis Mason <cumason@google.com>
Signed-off-by: Dustin Ingram <di@users.noreply.github.com>

* removed versions v01 and v02 from test_data_encaps_refs.py

Signed-off-by: Curtis Mason <cumason@google.com>
Signed-off-by: Dustin Ingram <di@users.noreply.github.com>

* fixed inheritance issue in CloudEvent

Signed-off-by: Curtis Mason <cumason@google.com>

* added prefixed_headers dict to test

Signed-off-by: Curtis Mason <cumason@google.com>

* Http structured cloudevents (#47)

* Moved fields out of base & structured support

base._ce_required_fields and base._ce_optional_fields were moved into
event classes v03 and v1.

http_events.CloudEvent class now looks for fieldnames in either headers
or data, and can automatically determine whether this is a binary or
structured event.

Signed-off-by: Curtis Mason <cumason@google.com>

* testing structured

Signed-off-by: Curtis Mason <cumason@google.com>

* added tests for structured events

Signed-off-by: Curtis Mason <cumason@google.com>

* Added test valid structured cloudevents

Signed-off-by: Curtis Mason <cumason@google.com>

* Created default headers arg in CloudEvent

Signed-off-by: Curtis Mason <cumason@google.com>

* Added http_events.py sample code

Signed-off-by: Curtis Mason <cumason@google.com>

* removed ../python-event-requests

Signed-off-by: Curtis Mason <cumason@google.com>

* README.md nit

Signed-off-by: Curtis Mason <cumason@google.com>

* client.py nit

Signed-off-by: Curtis Mason <cumason@google.com>

* comment nits

Signed-off-by: Curtis Mason <cumason@google.com>

* created __getitem__ in CloudEvent

Signed-off-by: Curtis Mason <cumason@google.com>

* sample nits

Signed-off-by: Curtis Mason <cumason@google.com>

* fixed structured empty data issue

Signed-off-by: Curtis Mason <cumason@google.com>

* Added CloudEvent to README

Signed-off-by: Curtis Mason <cumason@google.com>

* added http_msg to CloudEvent

Signed-off-by: Curtis Mason <cumason@google.com>

* implemented ToRequest in CloudEvent

Signed-off-by: Curtis Mason <cumason@google.com>

* testing more specversions

Signed-off-by: Curtis Mason <cumason@google.com>

* Added sample code to README.md

Signed-off-by: Curtis Mason <cumason@google.com>

* modified sample code

Signed-off-by: Curtis Mason <cumason@google.com>

* added datavalidation to changelog

Signed-off-by: Curtis Mason <cumason@google.com>

* updated README

Signed-off-by: Curtis Mason <cumason@google.com>

* README adjustment

Signed-off-by: Curtis Mason <cumason@google.com>

* ruler 80 adjustment on http_events

Signed-off-by: Curtis Mason <cumason@google.com>

* style and renamed ToRequest to to_request

Signed-off-by: Curtis Mason <cumason@google.com>

* lint fix

Signed-off-by: Curtis Mason <cumason@google.com>

* fixed self.binary typo

Signed-off-by: Curtis Mason <cumason@google.com>

* CHANGELOG adjustment

Signed-off-by: Curtis Mason <cumason@google.com>

* rollback CHANGELOG

Signed-off-by: Curtis Mason <cumason@google.com>

* Added documentation to to_request

Signed-off-by: Curtis Mason <cumason@google.com>

* README.md adjustment

Signed-off-by: Curtis Mason <cumason@google.com>

* renamed event_handler to event_version

Signed-off-by: Curtis Mason <cumason@google.com>

* inlined field_name_modifier

Signed-off-by: Curtis Mason <cumason@google.com>

* renamed test body data

Signed-off-by: Curtis Mason <cumason@google.com>

* removed unnecessary headers from test

Signed-off-by: Curtis Mason <cumason@google.com>

* removed field_name_modifier and fixed e.g. in client.py

Signed-off-by: Curtis Mason <cumason@google.com>

* pylint fix

Signed-off-by: Curtis Mason <cumason@google.com>

* Update types and handle data_base64 structured. (#34)

* Update types and handle data_base64 structured.

- Add sane defaults for encoding
  - Unfortunately, defaults for structured and binary need to be *different*
   - Push types through interfaces
- Make it easy to call 'ToRequest' using Marshaller defaults
- Add tests for above

Signed-off-by: Evan Anderson <evan.k.anderson@gmail.com>

* Fix lint warnings due to changes to W503/W504

See https://gitlab.com/pycqa/flake8/-/issues/466 for details.

Signed-off-by: Evan Anderson <evan.k.anderson@gmail.com>

* Adopt di's suggestions.

Signed-off-by: Evan Anderson <evan.k.anderson@gmail.com>

* Fix lint.

Signed-off-by: Evan Anderson <evan.k.anderson@gmail.com>

* Move types to another package.

Signed-off-by: Evan Anderson <evan.k.anderson@gmail.com>

* Adjust CloudEvent class in http_events.py to support binary data as well as JSON.

Signed-off-by: Evan Anderson <evan.k.anderson@gmail.com>

* Apply suggested changes by MacrBoissonneault

Signed-off-by: Evan Anderson <evan.k.anderson@gmail.com>

* Fix samples as well.

Signed-off-by: Evan Anderson <evan.k.anderson@gmail.com>

* Fix lint. Apparently, we can complain about formating issues, but a human has to fix them.

Signed-off-by: Evan Anderson <evan.k.anderson@gmail.com>

* Add test for binary encoding of messages.

Fix usability of binary detection in MarshalJSON to support memoryview.

Signed-off-by: Evan Anderson <evan.k.anderson@gmail.com>

* Fix errors noticed by cumason123

Signed-off-by: Evan Anderson <evan.k.anderson@gmail.com>

* Changelog version deprecation (#48)

* added changelog

Signed-off-by: Curtis Mason <cumason@google.com>

* Created CloudEvent class (#36)

CloudEvents is a more pythonic interface for using cloud events.
It is powered by internal marshallers and cloud event base classes.
It performs basic validation on fields, and cloud event type checking.

Signed-off-by: Curtis Mason <cumason@google.com>
Signed-off-by: Dustin Ingram <di@users.noreply.github.com>
Signed-off-by: Curtis Mason <cumason@google.com>

* Fix tox configuration for CI (#46)

Signed-off-by: Dustin Ingram <di@users.noreply.github.com>
Signed-off-by: Curtis Mason <cumason@google.com>

* Implemented python properties in base.py (#41)

* Added SetCloudEventVersion

Signed-off-by: Curtis Mason <cumason@google.com>
Signed-off-by: Dustin Ingram <di@users.noreply.github.com>

* began adding python properties

Signed-off-by: Curtis Mason <cumason@google.com>
Signed-off-by: Dustin Ingram <di@users.noreply.github.com>

* added pythonic properties to base class

Signed-off-by: Curtis Mason <cumason@google.com>
Signed-off-by: Dustin Ingram <di@users.noreply.github.com>

* began testing for getters/setters

Signed-off-by: Curtis Mason <cumason@google.com>
Signed-off-by: Dustin Ingram <di@users.noreply.github.com>

* added general setter tests

Signed-off-by: Curtis Mason <cumason@google.com>
Signed-off-by: Dustin Ingram <di@users.noreply.github.com>

* fixed spacing in base.py

Signed-off-by: Curtis Mason <cumason@google.com>
Signed-off-by: Dustin Ingram <di@users.noreply.github.com>

* added __eq__ to option and datacontentencoding property to v03

Signed-off-by: Curtis Mason <cumason@google.com>
Signed-off-by: Dustin Ingram <di@users.noreply.github.com>

* lint fixes

Signed-off-by: Curtis Mason <cumason@google.com>
Signed-off-by: Dustin Ingram <di@users.noreply.github.com>

* testing extensions and old getters

Signed-off-by: Curtis Mason <cumason@google.com>
Signed-off-by: Dustin Ingram <di@users.noreply.github.com>

* removed versions v01 and v02 from test_data_encaps_refs.py

Signed-off-by: Curtis Mason <cumason@google.com>
Signed-off-by: Dustin Ingram <di@users.noreply.github.com>

* fixed inheritance issue in CloudEvent

Signed-off-by: Curtis Mason <cumason@google.com>

* added prefixed_headers dict to test

Signed-off-by: Curtis Mason <cumason@google.com>

* CHANGELOG adjustment

Signed-off-by: Curtis Mason <cumason@google.com>

* Update CHANGELOG.md

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
Signed-off-by: Curtis Mason <cumason@google.com>

* Update CHANGELOG.md

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
Signed-off-by: Curtis Mason <cumason@google.com>

* Update CHANGELOG.md

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
Signed-off-by: Curtis Mason <cumason@google.com>

* Update CHANGELOG.md

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
Signed-off-by: Curtis Mason <cumason@google.com>

* Removed irrelevant files from commit diff

Signed-off-by: Curtis Mason <cumason@google.com>

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* Black formatter (#51)

* black and isort added to precommit

Signed-off-by: Curtis Mason <cumason@google.com>

* main renaming

Signed-off-by: Curtis Mason <cumason@google.com>

* fixed tox

Signed-off-by: Curtis Mason <cumason@google.com>

* linting in tox rename

Signed-off-by: Curtis Mason <cumason@google.com>

* fixed tox trailing space

Signed-off-by: Curtis Mason <cumason@google.com>

* added reformat tox env

Signed-off-by: Curtis Mason <cumason@google.com>

* Reformatting files

Signed-off-by: Curtis Mason <cumason@google.com>

* reformatted more files

Signed-off-by: Curtis Mason <cumason@google.com>

* documented tox in README

Signed-off-by: Curtis Mason <cumason@google.com>

* removed -rc flag

Signed-off-by: Curtis Mason <cumason@google.com>

* README and http-cloudevents sample code adjustments to reflect new CloudEvent (#56)

* README and http-cloudevents CloudEvent adjustments

README no longer shows how to use base event classes to create events.
Removed this because users shouldn't be forced to interact with the
marshaller class. Additionally, CloudEvent is a simpler interface
therefore we are encouraging the CloudEvent class usage.
http-cloudevents now has more example usage for the getitem overload.
Similarly README shows how to use getitem overload.

Signed-off-by: Curtis Mason <cumason@google.com>

* lint reformat

Signed-off-by: Curtis Mason <cumason@google.com>

* resolved nits

Signed-off-by: Curtis Mason <cumason@google.com>

* lint fix

Signed-off-by: Curtis Mason <cumason@google.com>

* renamed /mycontext to url

Signed-off-by: Curtis Mason <cumason@google.com>

* renamed here linlk to in the samples directory

Signed-off-by: Curtis Mason <cumason@google.com>

* Separated http methods (#60)

* instantiated http path

Signed-off-by: Curtis Mason <cumason@google.com>

* moved from_http from CloudEvent to http

Signed-off-by: Curtis Mason <cumason@google.com>

* Moved to_http out of CloudEvent

Signed-off-by: Curtis Mason <cumason@google.com>

* moved http library into event.py

Signed-off-by: Curtis Mason <cumason@google.com>

* testing printable cloudevent

Signed-off-by: Curtis Mason <cumason@google.com>

* Adjusted README

Signed-off-by: Curtis Mason <cumason@google.com>

* Created EventClass

Signed-off-by: Curtis Mason <cumason@google.com>

* reformatted event.py

Signed-off-by: Curtis Mason <cumason@google.com>

* from_json definition

Signed-off-by: Curtis Mason <cumason@google.com>

* server print changes

Signed-off-by: Curtis Mason <cumason@google.com>

* Specversion toggling (#57)

* cloudevent now switches specversion types

Signed-off-by: Curtis Mason <cumason@google.com>

* removed duplicate marshall instance

Signed-off-by: Curtis Mason <cumason@google.com>

* resolved grant requests

Signed-off-by: Curtis Mason <cumason@google.com>

* converters now can check headers for fields

Signed-off-by: Curtis Mason <cumason@google.com>

* removed print statement

Signed-off-by: Curtis Mason <cumason@google.com>

* Fixed marshallers looking at headers for specversion

Signed-off-by: Curtis Mason <cumason@google.com>

* lint fixes

Signed-off-by: Curtis Mason <cumason@google.com>

* is_binary static method and structured isinstance rework

Signed-off-by: Curtis Mason <cumason@google.com>

* testing for is_binary and is_structured

Signed-off-by: Curtis Mason <cumason@google.com>

* Image sample code (#65)

* added image example

Signed-off-by: Curtis Mason <cumason@google.com>

* moved size into headers

Signed-off-by: Curtis Mason <cumason@google.com>

* lint fix

Signed-off-by: Curtis Mason <cumason@google.com>

* renamed sample code

Signed-off-by: Curtis Mason <cumason@google.com>

* added test to http-image-cloudevents sample

Signed-off-by: Curtis Mason <cumason@google.com>

* removed unnecessary function

Signed-off-by: Curtis Mason <cumason@google.com>

* Added testing for http-image-cloudevents

Signed-off-by: Curtis Mason <cumason@google.com>

* Data marshall arg fix and better image in sample

Fixed bug where data_marshaller and data_unmarshaller wasn't being
passed into positional arguments. Also used cloudevents logo for the
image in http-image-cloudevents

Signed-off-by: Curtis Mason <cumason@google.com>

* adjusted http-image-cloudevents samples

Signed-off-by: Curtis Mason <cumason@google.com>

* reformat and README changes

Signed-off-by: Curtis Mason <cumason@google.com>

* io bytes casting in data_unmarshaller

Signed-off-by: Curtis Mason <cumason@google.com>

* lint fix

Signed-off-by: Curtis Mason <cumason@google.com>

* removed unusued imports in http-image samples

Signed-off-by: Curtis Mason <cumason@google.com>

* removed samples/http-cloudevents/tmp.png

Signed-off-by: Curtis Mason <cumason@google.com>

* Nits

Signed-off-by: Curtis Mason <cumason@google.com>

* Implemented to_json and from_json (#72)

* added test_to_json test

Signed-off-by: Curtis Mason <cumason@google.com>

* implemented to_json with tests

Signed-off-by: Curtis Mason <cumason@google.com>

* from_json and to_json tests

Signed-off-by: Curtis Mason <cumason@google.com>

* Tests for to_json being able to talk to from_json

Signed-off-by: Curtis Mason <cumason@google.com>

* lint fix

Signed-off-by: Curtis Mason <cumason@google.com>

* added documentation for to_json and from_json

Signed-off-by: Curtis Mason <cumason@google.com>

* lint fix

Signed-off-by: Curtis Mason <cumason@google.com>

* lint fix

Signed-off-by: Curtis Mason <cumason@google.com>

* Fixed top level extensions bug (#71)

* Fixed top level extensions bug

Signed-off-by: Curtis Mason <cumason@google.com>

* lint fix

Signed-off-by: Curtis Mason <cumason@google.com>

* fixed name bug in test_event_extensions

Signed-off-by: Curtis Mason <cumason@google.com>

* fixed broken links in README.md (#75)

Signed-off-by: Curtis Mason <cumason@google.com>

* Fixed marshaller documentation typo's in http (#76)

* Fixed marshaller documentation in http directory

Signed-off-by: Curtis Mason <cumason@google.com>

* adjusted marshaller documentation

Signed-off-by: Curtis Mason <cumason@google.com>

* None data fix (#78)

* fixed none data issue

Signed-off-by: Curtis Mason <cumason@google.com>

* added none data test for marshalling

Signed-off-by: Curtis Mason <cumason@google.com>

* lint fix

Signed-off-by: Curtis Mason <cumason@google.com>

* Samples image test server (#79)

* fixed none data issue

Signed-off-by: Curtis Mason <cumason@google.com>

* added none data test for marshalling

Signed-off-by: Curtis Mason <cumason@google.com>

* lint fix

Signed-off-by: Curtis Mason <cumason@google.com>

* added http server test in image sample

Signed-off-by: Curtis Mason <cumason@google.com>

* Removed print statements from test

Signed-off-by: Curtis Mason <cumason@google.com>

* removed requests from test

Signed-off-by: Curtis Mason <cumason@google.com>

* Top level http (#83)

* Modularized http and made http a top level module

Modularized the http directory by separating related functions into
different scripts. Also removed EventClass and kept a singular
CloudEvent. Finally, CloudEvent.__repr__ was refactored such that it
doesn't depend on external methods.

Signed-off-by: Curtis Mason <cumason@google.com>

* renamed requests.py to http_methods

Signed-off-by: Curtis Mason <cumason@google.com>

* lint fixes

Signed-off-by: Curtis Mason <cumason@google.com>

* http-json-cloudevents testing (#80)

* Added tests to http-json-cloudevents

Signed-off-by: Curtis Mason <cumason@google.com>

* removed outdated python-requests sample code

Signed-off-by: Curtis Mason <cumason@google.com>

* lint fix

Signed-off-by: Curtis Mason <cumason@google.com>

* Added flask to requirements

Signed-off-by: Curtis Mason <cumason@google.com>

* lint fix

Signed-off-by: Curtis Mason <cumason@google.com>

* docs: add README badge (#85)

Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>

* added pypi-release rule (#87)

* added pypi-release rule

Signed-off-by: Curtis Mason <cumason@google.com>

* added RELEASING.md

Signed-off-by: Curtis Mason <cumason@google.com>

* Adjusted RELEASING.md

Signed-off-by: Curtis Mason <cumason@google.com>

* Update .github/workflows/pypi-release.yml

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
Signed-off-by: Curtis Mason <cumason@google.com>

* workflow pypi name changed

Signed-off-by: Curtis Mason <cumason@google.com>

* Update RELEASING.md

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
Signed-off-by: Curtis Mason <cumason@google.com>

* Update RELEASING.md

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
Signed-off-by: Curtis Mason <cumason@google.com>

* Update RELEASING.md

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
Signed-off-by: Curtis Mason <cumason@google.com>

* removed some pbr stuff

Signed-off-by: Curtis Mason <cumason@google.com>

* Removed all pbr stuff

Signed-off-by: Curtis Mason <cumason@google.com>

* README nits

Signed-off-by: Curtis Mason <cumason@google.com>

* RELEASING adjustment in README

Signed-off-by: Curtis Mason <cumason@google.com>

* author update in setup.cfg

Signed-off-by: Curtis Mason <cumason@google.com>

* removed setup.cfg

Signed-off-by: Curtis Mason <cumason@bu.edu>

* Update setup.py

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
Signed-off-by: Curtis Mason <cumason@bu.edu>

* lint fix

Signed-off-by: Curtis Mason <cumason@bu.edu>

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* pypi-release git tags automation (#88)

* added pypi_packaging

Signed-off-by: Curtis Mason <cumason@bu.edu>

* reverted pypi-release

Signed-off-by: Curtis Mason <cumason@bu.edu>

* added pypi_package workflow

Signed-off-by: Curtis Mason <cumason@bu.edu>

* added gitpython dependency

Signed-off-by: Curtis Mason <cumason@bu.edu>

* added git import in createTag function

Signed-off-by: Curtis Mason <cumason@bu.edu>

* Updated RELEASING.md and implemented pypi_config in pypi_packaging.pg

Signed-off-by: Curtis Mason <cumason@bu.edu>
Signed-off-by: Curtis Mason <cumason@google.com>

* Fixed some docs

Signed-off-by: Curtis Mason <cumason@bu.edu>
Signed-off-by: Curtis Mason <cumason@google.com>

* Update .github/workflows/pypi-release.yml

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
Signed-off-by: Curtis Mason <cumason@google.com>

* added __version__

Signed-off-by: Curtis Mason <cumason@google.com>

* lint change

Signed-off-by: Curtis Mason <cumason@google.com>

* reinstalling cloudevents in workflow

Signed-off-by: Curtis Mason <cumason@google.com>

* added cloudevents to publish.txt

Signed-off-by: Curtis Mason <cumason@google.com>

* removed old release_doc

Signed-off-by: Curtis Mason <cumason@google.com>

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

Co-authored-by: Evan Anderson <evan.k.anderson@gmail.com>
Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
Co-authored-by: Grant Timmerman <timmerman@google.com>
  • Loading branch information
4 people authored Aug 11, 2020
1 parent d551dba commit 390134c
Show file tree
Hide file tree
Showing 54 changed files with 2,167 additions and 545 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/pypi-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: PyPI-Release

on:
push:
branches:
- master

jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: "3.x"
- name: Install build dependencies
run: pip install -U setuptools wheel build
- name: Build
run: python -m build .
- name: Publish
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.pypi_password }}
- name: Install GitPython and cloudevents for pypi_packaging
run: pip install -U -r requirements/publish.txt
- name: Create Tag
run: python pypi_packaging.py
4 changes: 4 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[settings]
line_length = 80
multi_line_output = 3
include_trailing_comma = True
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
repos:
- repo: https://github.com/timothycrosley/isort/
rev: 5.0.4
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 19.10b0
hooks:
- id: black
language_version: python3.8
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.0]
### Added
- Added a user friendly CloudEvent class with data validation ([#36])
- CloudEvent structured cloudevent support ([#47])

### Removed
- Removed support for Cloudevents V0.2 and V0.1 ([#43])

## [0.3.0]
### Added
- Added Cloudevents V0.3 and V1 implementations ([#22])
Expand Down Expand Up @@ -66,3 +74,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#23]: https://github.com/cloudevents/sdk-python/pull/23
[#25]: https://github.com/cloudevents/sdk-python/pull/25
[#27]: https://github.com/cloudevents/sdk-python/pull/27
[#36]: https://github.com/cloudevents/sdk-python/pull/36
[#43]: https://github.com/cloudevents/sdk-python/pull/43
[#47]: https://github.com/cloudevents/sdk-python/pull/47
196 changes: 70 additions & 126 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# 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
Expand All @@ -14,159 +16,87 @@ This SDK current supports the following versions of CloudEvents:

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

Parsing upstream structured Event from HTTP request:
## Sending CloudEvents

```python
import io

from cloudevents.sdk.event import v1
from cloudevents.sdk import marshaller

m = marshaller.NewDefaultHTTPMarshaller()

event = m.FromRequest(
v1.Event(),
{"content-type": "application/cloudevents+json"},
io.StringIO(
"""
{
"specversion": "1.0",
"datacontenttype": "application/json",
"type": "word.found.name",
"id": "96fb5f0b-001e-0108-6dfe-da6e2806f124",
"time": "2018-10-23T12:28:22.4579346Z",
"source": "<source-url>"
}
"""
),
lambda x: x.read(),
)
```
Below we will provide samples on how to send cloudevents using the popular
[`requests`](http://docs.python-requests.org) library.

Parsing upstream binary Event from HTTP request:
### Binary HTTP CloudEvent

```python
import io

from cloudevents.sdk.event import v1
from cloudevents.sdk import marshaller

m = marshaller.NewDefaultHTTPMarshaller()

event = m.FromRequest(
v1.Event(),
{
"ce-specversion": "1.0",
"content-type": "application/json",
"ce-type": "word.found.name",
"ce-id": "96fb5f0b-001e-0108-6dfe-da6e2806f124",
"ce-time": "2018-10-23T12:28:22.4579346Z",
"ce-source": "<source-url>",
},
io.BytesIO(b"this is where your CloudEvent data"),
lambda x: x.read(),
)
```
from cloudevents.http import CloudEvent, to_binary_http
import requests

Creating a minimal CloudEvent in version 0.1:

```python
from cloudevents.sdk.event import v1

event = (
v1.Event()
.SetContentType("application/json")
.SetData('{"name":"john"}')
.SetEventID("my-id")
.SetSource("from-galaxy-far-far-away")
.SetEventTime("tomorrow")
.SetEventType("cloudevent.greet.you")
)
# This data defines a binary cloudevent
attributes = {
"type": "com.example.sampletype1",
"source": "https://example.com/event-producer",
}
data = {"message": "Hello World!"}

event = CloudEvent(attributes, data)
headers, body = to_binary_http(event)

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

Creating HTTP request from CloudEvent:
### Structured HTTP CloudEvent

```python
from cloudevents.sdk import converters
from cloudevents.sdk import marshaller
from cloudevents.sdk.converters import structured
from cloudevents.sdk.event import v1

event = (
v1.Event()
.SetContentType("application/json")
.SetData('{"name":"john"}')
.SetEventID("my-id")
.SetSource("from-galaxy-far-far-away")
.SetEventTime("tomorrow")
.SetEventType("cloudevent.greet.you")
)

m = marshaller.NewHTTPMarshaller([structured.NewJSONHTTPCloudEventConverter()])

headers, body = m.ToRequest(event, converters.TypeStructured, lambda x: x)
```
from cloudevents.http import CloudEvent, to_structured_http
import requests

## HOWTOs with various Python HTTP frameworks

In this topic you'd find various example how to integrate an SDK with various HTTP frameworks.
# This data defines a structured cloudevent
attributes = {
"type": "com.example.sampletype2",
"source": "https://example.com/event-producer",
}
data = {"message": "Hello World!"}
event = CloudEvent(attributes, data)
headers, body = to_structured_http(event)

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

One of popular framework is [`requests`](http://docs.python-requests.org/en/master/).
You can find a complete example of turning a CloudEvent into a HTTP request [in the samples directory](samples/http-json-cloudevents/client.py).

#### CloudEvent to request
#### Request to CloudEvent

The code below shows how integrate both libraries in order to convert a CloudEvent into an HTTP request:
The code below shows how to consume a cloudevent using the popular python web framework
[flask](https://flask.palletsprojects.com/en/1.1.x/quickstart/):

```python
def run_binary(event, url):
binary_headers, binary_data = http_marshaller.ToRequest(
event, converters.TypeBinary, json.dumps)

print("binary CloudEvent")
for k, v in binary_headers.items():
print("{0}: {1}\r\n".format(k, v))
print(binary_data.getvalue())
response = requests.post(url,
headers=binary_headers,
data=binary_data.getvalue())
response.raise_for_status()


def run_structured(event, url):
structured_headers, structured_data = http_marshaller.ToRequest(
event, converters.TypeStructured, json.dumps
)
print("structured CloudEvent")
print(structured_data.getvalue())
from flask import Flask, request

response = requests.post(url,
headers=structured_headers,
data=structured_data.getvalue())
response.raise_for_status()
from cloudevents.http import from_http

```
app = Flask(__name__)

Complete example of turning a CloudEvent into a request you can find [here](samples/python-requests/cloudevent_to_request.py).

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

The code below shows how integrate both libraries in order to create a CloudEvent from an HTTP request:
# 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']}"
)

```python
response = requests.get(url)
response.raise_for_status()
headers = response.headers
data = io.BytesIO(response.content)
event = v1.Event()
http_marshaller = marshaller.NewDefaultHTTPMarshaller()
event = http_marshaller.FromRequest(
event, headers, data, json.load)
return "", 204


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

Complete example of turning a CloudEvent into a request you can find [here](samples/python-requests/request_to_cloudevent.py).
You can find a complete example of turning a CloudEvent into a HTTP request [in the samples directory](samples/http-json-cloudevents/server.py).

## SDK versioning

Expand All @@ -189,3 +119,17 @@ the same API. It will use semantic versioning with following rules:
[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).

## Maintenance

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

e.g.

```python
pip install tox
tox -e reformat
```

For information on releasing version bumps see [RELEASING.md](RELEASING.md)
25 changes: 25 additions & 0 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Releasing CloudEvents SDK for Python

This repository is configured to automatically publish the corresponding [PyPI
package](https://pypi.org/project/cloudevents/) and GitHub Tag via GitHub Actions.

To release a new CloudEvents SDK, contributors should bump `__version__` in
[cloudevents](cloudevents/__init__.py) to reflect the new release version. On merge, the action
will automatically build and release to PyPI using
[this PyPI GitHub Action](https://github.com/pypa/gh-action-pypi-publish). This
action gets called on all pushes to master (such as a version branch being merged
into master), but only releases a new version when the version number has changed. Note,
this action assumes pushes to master are version updates. Consequently,
[pypi-release.yml](.github/workflows/pypi-release.yml) will fail if you attempt to
push to master without updating `__version__` in
[cloudevents](cloudevents/__init__.py) so don't forget to do so.

After a version update is merged, the script [pypi_packaging.py](pypi_packaging.py)
will create a GitHub tag for the new cloudevents version using `__version__`.
The script fails if `__version__` and the local pypi version for
cloudevents are out of sync. For this reason, [pypi-release.yml](.github/workflows/pypi-release.yml)
first must upload the new cloudevents pypi package, and then download the recently updated pypi
cloudevents package for [pypi_packaging.py](pypi_packaging.py) not to fail.

View the GitHub workflow [pypi-release.yml](.github/workflows/pypi-release.yml) for
more information.
1 change: 1 addition & 0 deletions cloudevents/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "1.0.0"
23 changes: 23 additions & 0 deletions cloudevents/http/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import json
import typing

from cloudevents.http.event import CloudEvent
from cloudevents.http.http_methods import (
from_http,
to_binary_http,
to_structured_http,
)
from cloudevents.http.json_methods import from_json, to_json
Loading

0 comments on commit 390134c

Please sign in to comment.