Skip to main content

Event Gateway Python SDK

Project description

Event Gateway Python SDK

Python library for interacting with the Event Gateway.

Contents

Background

This is the Python SDK for interacting with the Event Gateway, the hub for connecting events to serverless functions.

Installation

pip install event-gateway-sdk

Usage

Use the emit command to emit a CloudEvent payload to your Event Gateway. The event will be received by any function that is subscribed to your event.

from eventgateway import EventGateway

eg = EventGateway(url="https://mytenant-myapp.slsgateway.com")
cloudEvent = {
    "eventType": "user.created",
    "cloudEventsVersion": "0.1",
    "source": "/services/users",
    "data": {
        "userId": "foo",
        "userName": "bar"
    }
}
eg.emit(cloudEvent=configData, path="/user/send-mail-user")

The emit() function takes three arguments:

  • an event which is a valid CloudEvent,
  • a path which is the path associated to the function (default: /)
  • a headers object that represents the headers sent to the gateway (default: {"Content-type": "application/json"})

The function returns a request object. If your event has a sync subscription attached, the fetch response will have the status code and body from the subscription. If not, the response will return a 202 Accepted status code with an empty body.

Constructor

In the example above, we created an Event Gateway client using the application URL from the hosted Event Gateway provided by Serverless, Inc.

You can also use the Event Gateway SDK with your own, self-hosted Event Gateway. Constructor details are listed below.

Parameters

  • url - string - optional, Events API URL, default: http://localhost:4000
  • space - string - optional, space name, default: default
  • configurationUrl - string - optional, Configuration API URL. By default, it's the same as url but with 4001 port
  • connectorUrl - string - optional, Connector API URL. By default, it's the same as url but with 4002 port
  • accessKey - string - optional, access key for hosted Event Gateway. Access key is required for using Configuration API methods on hosted Event Gateway

Example

from eventgateway import EventGateway

eg = EventGateway(url="https://mytenant-myapp.slsgateway.com", space="user")

Available Functions

checkConnection

Used to check the connectivity to the Event Gateway (using the /v1/status endpoint).

Example

from eventgateway import EventGateway

eg = EventGateway()
if eg.checkConnection():
    print("Connection succesfull")
else:
    print("Issue while connecting")

printConfig

Utility to print the current configuration.

Example

from eventgateway import EventGateway

eg = EventGateway()
eg.printConfig()

createEventType

Function to create an event type.

Example

from eventgateway import EventGateway

eventtype = {
    "name": "http.request"
}
eg = EventGateway()
eg.createEventType(eventtype)

getEventType

Function to get an event type.

Example

from eventgateway import EventGateway

eg = EventGateway()
eg.getEventType("user.created")

getAllEventType

Function to get all event type.

Example

from eventgateway import EventGateway

eg = EventGateway()
eg.getAllEventType()

createFunction

Function to create a function trigger.

Example

from eventgateway import EventGateway

function = {
    "functionId": "new-user",
    "type": "http",
    "provider":{
        "url": "http://myapp.com/user/new"
    }
}
eg = EventGateway()
eg.createFunction(function)

getFunction

Function to get a function.

Example

from eventgateway import EventGateway

eg = EventGateway()
eg.getFunction("new-user")

getAllFunction

Function to get all functions.

Example

from eventgateway import EventGateway

eg = EventGateway()
eg.getAllFunction()

createSubscription

Function to subscribe to a function.

Example

from eventgateway import EventGateway

subscription = {
    "functionId": "new-user",
    "event": "http",
    "method": "POST",
    "path": "/user/new",
    "eventType": "http.request",
    "type": "async"
}
eg = EventGateway()
eg.createSubscription(subscription)

getSubscription

Function to get a subscription.

Example

from eventgateway import EventGateway

eg = EventGateway()
eg.getSubscription("YXN5bmMsaHR0cC5yZXF1ZXN0LG5ldy11c2VyLW9wZW5wYWFzLCUyRmppcmE")

getAllSubscription

Function to get all subscription.

Example

from eventgateway import EventGateway

eg = EventGateway()
eg.getAllSubscription()

Contribute

TBD

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

event-gateway-sdk-1.2.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

event_gateway_sdk-1.2.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file event-gateway-sdk-1.2.0.tar.gz.

File metadata

  • Download URL: event-gateway-sdk-1.2.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for event-gateway-sdk-1.2.0.tar.gz
Algorithm Hash digest
SHA256 025443adf667054e44a95833c83beb7f2458a9e755002ca3a3d3cde9e9ebe072
MD5 a4997144669949f6fc61e307951d0795
BLAKE2b-256 521df720ac16ffaa2fcd706b149916d1db87ac076e41e0c2f1172c0beabd1eeb

See more details on using hashes here.

File details

Details for the file event_gateway_sdk-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: event_gateway_sdk-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for event_gateway_sdk-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1a486eac53da6ffd6b498349e84137ec780a29b88f04f6f024543f56a285052a
MD5 d95d79b4c9613a313b8ba219a2c5b1e9
BLAKE2b-256 d53d28a27dfe369e6946d8c5312d8f278b7172a886ebfe701ddd4c9df32a7d4c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page