Giter Club home page Giter Club logo

sdk-python's Introduction

sdk-python

Python SDK for CDEvents

The SDK can be used to create CDEvents in CloudEvents form, for use with the CloudEvents Python SDK.

Disclaimer ๐Ÿšง

This SDK is work in work in progress, it will be maintained in sync with the specification and it now covers all events from the specification.

Get started

Clone the repo and install the Python SDK as a package:

cd src && pip install .

And import the module in your code

import cdevents

Create your first CDEvent

To create a CDEvent, for instance a pipelineRun queued one:

import cdevents

event = cdevents.new_pipelinerun_queued_event(
    context_id="my-context-id",
    context_source="my/first/cdevent/program",
    context_timestamp=datetime.datetime.now(),
    subject_id="myPipelineRun1",
    custom_data={"hello_message": "hi!"},
    subject_source="subjectSource",
    custom_data_content_type="application/json",
    pipeline_name="myPipeline",
    url="https://example.com/myPipeline",
)

Send your first CDEvent as CloudEvent

To send a CDEvent as CloudEvent:

import cdevents

# Create a CloudEvent from the CDEvent
cloudevent = cdevents.to_cloudevent(event)

# 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)

See the CloudEvents docs as well.

References

sdk-python's People

Contributors

ahmadsyafrudin avatar ashitasingamsetty avatar cdevents-bot avatar elmsdata avatar erkist avatar fourandhalf avatar randomnoise avatar tarekbadrshalaan avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

sdk-python's Issues

Create the Python SDK under cdevents/sdk-python

Based on the updated binding document and schema, we shall create the python SDK under cdevents/sdk-python.

This includes investigating if/how the SDK can be generated from the json schema.

Add pydantic to parse incoming events

@erkist outlined, the next enhancement to the Python SDK would be to parse incoming events! Like in the CloudEvents Python SDK, they use Pydantic used for data parsing and validation. Issue is to track changes (for future changelog), conversations outside the pull request and any other feedback/input from the community!

Setup PyPI Token for cdevents-bot

In preparation for releasing the python SDK, and following the release similar to java SDK, we need to setup an account for the cdevents-bot on the PyPI site so we can use github actions to automate the release of the SDK with each release. @afrittoli do you mind following this link to setup an account for the bot and then setup an API token! Similar to the secrets.GH_BOT_TOKEN used in the changelog github action, a new token like secrets.PYPI_BOT_TOKEN could be used. Then I can create the automation and work on creating our first release using github actions. Source of how upload our python package.

Also there is no rush on this, with the CD Con next week, please take all the time you need! I'm still working on a few automation features while my teammate is working on the pydantic enhancements. Hope you have a great start to May!

Github Action pre-commit failing

@erkist current pull request has the pre-commit checks failing. I have been researching the python errors and it appears to be a version change needs to be updated in the .pre-commit-config.yaml file. I will work on making the change and open a pull request soon!

Align with Go SDK & spec

The Go SDK, and the CDEvents specification, has changed since the current iteration of the Python SDK was developed. The Python SDK should be updated to reflect these changes.

Update License file to add copyright owner

Good first issue

In the license file on line 189 the authors haven't been stated, this is a common thing that people miss when adding apache2 licenses.

change text to:

Copyright 2023 The cdevents Authors

Translate to and from json

Expected Behavior

Users often interact with objects in json format.

Would it make sense to update this SDK so that users can easily transform json strings into objects whose types match those defined in the CDEvent spec?

We currently have some code that looks like this

some_json_str = '...' # this could be consumed from kafka or some http service

typed_msg = CDEventMsgFactory.from_json(some_json_str) 
if isinstance(typed_msg, Taskrunstarted):
       # do something...
elif isinstance(typed_msg, Taskrunfinished):
       # do something...
etc...        

Along with verifying that the json is valid, we can also do some additional checks, like checking enum values, as specified in the schema.

We can then also go back to json with something like

new_json_str = CDEventMsgFactory.to_json(typed_msg) 

Actual Behavior

We wrote our own internal libraries, but we think it would be good to share this code, for others to re-use.

Steps to Reproduce the Problem

n/a

Specifications

  • Platform: Any
  • Python Version: Any

Write a README

Write a simple README that shows how to get started with sdk-python and shows some usage examples.

TOML file for packaging Python SDK for public use

As part of the Python lifecycle for packaging a python project, a pyproject.toml is first required that outlines the overall project information and dependencies. This is equivalent to the POM file in a Java project that outlines the artifact information and package capabilities. We can first create the TOML file and then follow the steps to publish the SDK for public consumption.

Automate Github releases and changeling

As we move to automated release for public use, we want to automatically create GitHub release and changelog as pull requests are approved/merged to main.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.