-
Notifications
You must be signed in to change notification settings - Fork 5
Programmatic API
Origins comes with a set of tailored Cypher queries for effectively utilizing the graph. To improve the usability of these bare queries, Origins comes with an programmatic API written in Python that encapsulates the execution, parsing of results, and structuring of output for downstream consumption.
WIP
Often there is a need or desire to know when something occurs when you are not interacting with the system.
For this reason, Origins has an integrated publish/subscribe event system that provides hooks for subscribing to events as they occur.
For example, a function can be registered to do something whenever a resource is created:
from origins import events
def handler(event, data):
print(data)
events.subscribe('resource.create', handler)All handlers are passed two values, event which is a standard format for representing the event itself and data which contains the event-specific data as a dictionary.
- resource
createdeleteupdateadd_componentremove_componentadd_relationshipremove_relationship
- collection
createdeleteupdateadd_resourceremove_resource
- component
createdeleteupdate
- relationship
createdeleteupdate
The based events API is useful for granular access to the underlying changes that occur in the system, however in many cases users just want to know when one of their objects has been "involved" in something. For this reason, individual objects can be watched. Whenever an event involves the watched object, the registered handler will be called.
from origins import events
def handler(event, data):
print(data)
events.watch('resource.abc123', handler)To increase the accessibility of the event system, the event system supports a URL as the handler. Rather than calling a function and passing in the data, a POST request will be sent to the URL with a JSON-encoded payload of the event and data. This pattern is know as a webhook.
from origins import events
events.subscribe('resource.create', 'http://example.org/webhook/')