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.

Installation

pip install hakai-api

Requirements

Python 3.6 or higher

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.

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

Development

The business code for this package is in the file hakai_api/Client.py. The ./setup.py file is important for giving details about how to install the package when users do pip install hakai-api.

To build a new PyPi package version push a tag matching the pattern v[0-9]+.[0-9]+.[0-9]+ or v[0-9]+.[0-9]+.[0-9]+rc[0-9]+ to the origin (e.g. v0.4.1 or v0.5.2rc1). Github Actions should take care of packaging and pushing it to Hakai's PyPi repository from there.

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.1.2.tar.gz (3.8 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.1.2-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hakai_api-1.1.2.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for hakai_api-1.1.2.tar.gz
Algorithm Hash digest
SHA256 d7e492e0e48c0e1fdb784b81b29b642acf5fa5abd730b9ee410eb3d50073f1fc
MD5 5d5c038891a3a5a96841a5b088fd925a
BLAKE2b-256 fe0bec633d213acaa43caf1b5e9edd5ea9816e186e9b34d6897e4de6dcdb89ce

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hakai_api-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for hakai_api-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4bf8f9fd92176778c4f873eacf8682f996e2caf91648cbf9ee2436bd72877b55
MD5 05bab9a7ec352d0076aaed9815ab12bd
BLAKE2b-256 1070248ff82cc78d9d95a0c52d670f6452e7584f41eb3fff3b0abcae3ed77d97

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