DOS Python HTTP Client

This module exposes a single class ga4gh.dos.client.Client, which exposes the HTTP methods of the Data Object Service as named Python functions.

This makes it easy to access resources that are described following these schemas, and uses bravado to dynamically generate the client functions following the OpenAPI schema.

It currently assumes that the service also hosts the swagger.json, in a style similar to the demonstration server, ga4gh.dos.server.

class ga4gh.dos.client.Client(url, config={'validate_requests': True, 'validate_responses': True}, http_client=None, request_headers=None)[source]

This class is the instantiated to create a new connection to a DOS. It connects to the service to download the swagger.json and returns a client in the DataObjectService namespace.

from ga4gh.dos.client import Client
client = Client("http://localhost:8000/ga4gh/dos/v1")

models = client.models
c = client.client

# Will return a Data Object by identifier
c.GetDataObject(data_object_id="abc").result()

# To access models in the Data Object Service namespace:
ListDataObjectRequest = models.get_model('ListDataObjectsRequest')

# And then instantiate a request with our own query:
my_request = ListDataObjectsRequest(alias="doi:10.0.1.1/1234")

# Finally, send the request to the service and evaluate the response.
c.ListDataObjects(body=my_request).result()

The class accepts a configuration dictionary that maps directly to the bravado configuration.

For more information on configuring the client, see bravado documentation.

classmethod config(url, http_client=None, request_headers=None)[source]

Accepts an optionally configured requests client with authentication details set.

Parameters:
  • url – The URL of the service to connect to
  • http_client – The http_client to use, defaults to RequestsClient()
  • request_headers – The headers to set on each request.
Returns:

ga4gh.dos.client.validate_int64(test)[source]

Accepts an int64 and checks for numerality. Throws a Swagger Validation exception when failing the test.

Parameters:test
Returns:
Raises:SwaggerValidationError