Skip to main content

Get Hakai database resources using http calls

Project description

Hakai Api Python Client

This project exports a single Python class that can be used to make HTTP requests to the Hakai API resource server. The exported Client class extends the functionality of the Python requests library to supply Hakai OAuth2 credentials with url requests.

PyPI tests License: MIT

Table of Contents

Installation

Quickstart

Methods

API endpoints

Advanced usage

Contributing

Installation

Python 3.8 or higher is required. Install with pip:

pip install hakai-api

Quickstart

from hakai_api import Client

# Get the api request client
client = Client()  # Follow stdout prompts to get an API token

# Make a data request for chlorophyll data
url = '%s/%s' % (client.api_root, 'eims/views/output/chlorophyll?limit=50')
response = client.get(url)

print(url)  # https://hecate.hakai.org/api/eims/views/output/chlorophyll...
print(response.json())
# [{'action': '', 'event_pk': 7064, 'rn': '1', 'date': '2012-05-17', 'work_area': 'CALVERT'...

Methods

This library exports a single client name Client. Instantiating this class produces a requests.Session client from the Python requests library. The Hakai API Python Client inherits directly from requests.Session thus all methods available on that parent class are available. For details see the requests documentation.

The hakai_api Client class also contains a property api_root which is useful for constructing urls to access data from the API. The above Quickstart example demonstrates using this property to construct a url to access project names.

API endpoints

For details about the API, including available endpoints where data can be requested from, see the Hakai API documentation.

Advanced usage

You can specify which API to access when instantiating the Client. By default, the API uses https://hecate.hakai.org/api as the API root. It may be useful to use this library to access a locally running API instance or to access the Goose API for testing purposes. If you are always going to be accessing data from a locally running API instance, you are better off using the requests.py library directly since Authorization is not required for local requests.

from hakai_api import Client

# Get a client for a locally running API instance
client = Client("http://localhost:8666")
print(client.api_root)  # http://localhost:8666

You can also pass in the credentials string retrieved from the hakai API login page while initiating the Client class.

from hakai_api import Client

# Pass a credentials token as the Client Class is initiated
client = Client(credentials="CREDENTIAL_TOKEN")

Finally, you can set credentials for the client class using the HAKAI_API_CREDENTIALS environment variable. This is useful for e.g. setting credentials in a docker container. The value of the environment variable should be the credentials token retrieved from the Hakai API login page.

Contributing

See CONTRIBUTING

License

See LICENSE

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

hakai_api-1.5.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

hakai_api-1.5.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file hakai_api-1.5.0.tar.gz.

File metadata

  • Download URL: hakai_api-1.5.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.9.16 Linux/5.15.0-1037-azure

File hashes

Hashes for hakai_api-1.5.0.tar.gz
Algorithm Hash digest
SHA256 542d6de2e002f440d1613405c1be2cc85b4ac9f940889e41833eadff84409af3
MD5 1c00a3dedf5b75849bd76c166a169176
BLAKE2b-256 41ddf1d1554e32009e6d26c0e99ff951ae6453bad5fa9856ad678a330525c9e1

See more details on using hashes here.

File details

Details for the file hakai_api-1.5.0-py3-none-any.whl.

File metadata

  • Download URL: hakai_api-1.5.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.9.16 Linux/5.15.0-1037-azure

File hashes

Hashes for hakai_api-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 59a2936e6ba0a98f6b967820e0a49a579744ced12bc1a223432531993149e446
MD5 f0a4a60127973f28f57234408b1ba462
BLAKE2b-256 a3fd2668eba4a82790b311ccdc2446ec3849d4ec61d288719438e14734cd7599

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