Package: event-gateway-sdk
Event Gateway Python SDKPython library for interacting with theEvent Gateway.ContentsBackgroundInstallationUsageConstructorAvailable FunctionsContributingBackgroundThis is the Python SDK for interacting with theEvent Gateway, the hub for connecting events to serverless functions.Installationpip install event-gateway-sdkUsageUse theemitcommand to emit aCloudEventpayload to your Event Gateway. The event will be received by any function that is subscribed to your event.fromeventgatewayimportEventGatewayeg=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")Theemit()function takes three arguments:aneventwhich is a valid CloudEvent,apathwhich is the path associated to the function (default:/)aheadersobject that represents the headers sent to the gateway (default:{"Content-type": "application/json"})The function returns a request object. If your event has asyncsubscription attached, thefetchresponse will have the status code and body from the subscription. If not, the response will return a202 Acceptedstatus code with an empty body.ConstructorIn the example above, we created an Event Gateway client using the application URL from thehosted Event Gatewayprovided by Serverless, Inc.You can also use the Event Gateway SDK with your own, self-hosted Event Gateway. Constructor details are listed below.Parametersurl-string- optional, Events API URL, default:http://localhost:4000space-string- optional, space name, default:defaultconfigurationUrl-string- optional, Configuration API URL. By default, it's the same asurlbut with4001portconnectorUrl-string- optional, Connector API URL. By default, it's the same asurlbut with4002portaccessKey-string- optional, access key for hosted Event Gateway. Access key is required for using Configuration API methods on hosted Event GatewayExamplefromeventgatewayimportEventGatewayeg=EventGateway(url="https://mytenant-myapp.slsgateway.com",space="user")Available FunctionscheckConnectionUsed to check the connectivity to the Event Gateway (using the/v1/statusendpoint).ExamplefromeventgatewayimportEventGatewayeg=EventGateway()ifeg.checkConnection():print("Connection succesfull")else:print("Issue while connecting")printConfigUtility to print the current configuration.ExamplefromeventgatewayimportEventGatewayeg=EventGateway()eg.printConfig()createEventTypeFunction to create an event type.ExamplefromeventgatewayimportEventGatewayeventtype={"name":"http.request"}eg=EventGateway()eg.createEventType(eventtype)getEventTypeFunction to get an event type.ExamplefromeventgatewayimportEventGatewayeg=EventGateway()eg.getEventType("user.created")getAllEventTypeFunction to get all event type.ExamplefromeventgatewayimportEventGatewayeg=EventGateway()eg.getAllEventType()createFunctionFunction to create a function trigger.ExamplefromeventgatewayimportEventGatewayfunction={"functionId":"new-user","type":"http","provider":{"url":"http://myapp.com/user/new"}}eg=EventGateway()eg.createFunction(function)getFunctionFunction to get a function.ExamplefromeventgatewayimportEventGatewayeg=EventGateway()eg.getFunction("new-user")getAllFunctionFunction to get all functions.ExamplefromeventgatewayimportEventGatewayeg=EventGateway()eg.getAllFunction()createSubscriptionFunction to subscribe to a function.ExamplefromeventgatewayimportEventGatewaysubscription={"functionId":"new-user","event":"http","method":"POST","path":"/user/new","eventType":"http.request","type":"async"}eg=EventGateway()eg.createSubscription(subscription)getSubscriptionFunction to get a subscription.ExamplefromeventgatewayimportEventGatewayeg=EventGateway()eg.getSubscription("YXN5bmMsaHR0cC5yZXF1ZXN0LG5ldy11c2VyLW9wZW5wYWFzLCUyRmppcmE")getAllSubscriptionFunction to get all subscription.ExamplefromeventgatewayimportEventGatewayeg=EventGateway()eg.getAllSubscription()ContributeTBD