OpenAPI Data Connector
OpenAPI Connection Object
class edge.api.OpenAPIConnection(name, title, host, specs_url)
A connector generating a REStful API from OpenAPI 3 specifications.
Create a new OpenAPI3 connector.
Parameters:
- name (Str) — Connection name, must be unique
- title (Str) — Title as displayed in the Data App
- host (Str) — URL for the API host, including the http/https scheme
- specs_url (Str) — URL for the OpenAPI3 specification, including the http/https scheme.
Example
# Create a connector
[1]: conn = OpenAPIConnector('petstore', 'Petstore Demo',
... host="http://petstore3.swagger.io",
... specs_url="https://petstore3.swagger.io/api/v3/openapi.json")
# Generate a client allowing API access.
# This may take a few seconds as it needs to generate source code.
[2]: client = conn.generate_new_client()
# Use the client to query the API
[3]: pets = client.pet.findPetsByStatus()
Properties
OpenAPIConnection.kind
OpenAPIConnection.uid
OpenAPIConnection.name
OpenAPIConnection.title
OpenAPIConnection.host
OpenAPIConnection.specs_url
Methods
Reference
kind
Connection kind, for discrimination
uid
Connection unique ID
name
Connection name, for internal use
title
Title for display
host
Host for which we are generating an API
specs_url
URL which points to the OpenAPI3 JSON spec file.
to_dict()
Translates the connection as a dictionary, for serialization.
Returns:
Dict
Connection contents in dictionary form.
test()
Test the connection to the external data source
Note that the timeout should default to a short value, so a connection failure could also mean the network is slow or lagging.
Parameters:
- timeout (int) — The time in seconds to wait before reporting a connection as failed.
Returns
ConnectionStatus
ConnectionStatus (one of VALID_CONNECTION, BAD_CREDENTIALS, or NO_CONNECTION)
generate_new_client()
Get a client allowing access to the remote API.
The remote API is available via methods on the returned object and its attributes. You can explore it by using e.g. IPython completion, or by using dir().
This method will generate Python files with the API binding, and cache them on disk. This is a fairly expensive process, so once a client is generated, you should try to use it for as long as possible. All files are cleaned up when the object becomes unreachable (or Python exits).