hakai_api 1.4.0__tar.gz → 1.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hakai_api-1.5.0/LICENSE +21 -0
- hakai_api-1.5.0/PKG-INFO +132 -0
- hakai_api-1.5.0/README.md +110 -0
- {hakai_api-1.4.0 → hakai_api-1.5.0}/hakai_api/Client.py +53 -20
- {hakai_api-1.4.0 → hakai_api-1.5.0}/hakai_api/__init__.py +1 -0
- hakai_api-1.5.0/pyproject.toml +26 -0
- hakai_api-1.5.0/setup.py +32 -0
- hakai_api-1.4.0/PKG-INFO +0 -73
- hakai_api-1.4.0/README.md +0 -63
- hakai_api-1.4.0/hakai_api.egg-info/PKG-INFO +0 -73
- hakai_api-1.4.0/hakai_api.egg-info/SOURCES.txt +0 -9
- hakai_api-1.4.0/hakai_api.egg-info/dependency_links.txt +0 -1
- hakai_api-1.4.0/hakai_api.egg-info/requires.txt +0 -3
- hakai_api-1.4.0/hakai_api.egg-info/top_level.txt +0 -1
- hakai_api-1.4.0/setup.cfg +0 -4
- hakai_api-1.4.0/setup.py +0 -21
hakai_api-1.5.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Hakai Institute
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
hakai_api-1.5.0/PKG-INFO
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: hakai-api
|
|
3
|
+
Version: 1.5.0
|
|
4
|
+
Summary: Get Hakai database resources using http calls
|
|
5
|
+
Home-page: https://github.com/HakaiInstitute/hakai-api-client-py
|
|
6
|
+
License: MIT
|
|
7
|
+
Author: Taylor Denouden
|
|
8
|
+
Author-email: taylor.denouden@hakai.org
|
|
9
|
+
Requires-Python: >=3.8,<3.12
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Requires-Dist: pytz (>=2023.3,<2024.0)
|
|
17
|
+
Requires-Dist: requests (>=2.30.0,<3.0.0)
|
|
18
|
+
Requires-Dist: requests-oauthlib (>=1.3.1,<2.0.0)
|
|
19
|
+
Project-URL: Repository, https://github.com/HakaiInstitute/hakai-api-client-py
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# Hakai Api Python Client
|
|
23
|
+
|
|
24
|
+
This project exports a single Python class that can be used to make HTTP requests to the
|
|
25
|
+
Hakai API resource server.
|
|
26
|
+
The exported `Client` class extends the functionality of the
|
|
27
|
+
Python [requests library](https://docs.python-requests.org/en/master/) to supply Hakai
|
|
28
|
+
OAuth2 credentials with url requests.
|
|
29
|
+
|
|
30
|
+
 [](https://github.com/HakaiInstitute/hakai-api-client-py/actions/workflows/test.yaml) [](https://opensource.org/licenses/MIT)
|
|
31
|
+
|
|
32
|
+
<details>
|
|
33
|
+
|
|
34
|
+
<summary>Table of Contents</summary>
|
|
35
|
+
|
|
36
|
+
[Installation](#installation)
|
|
37
|
+
|
|
38
|
+
[Quickstart](#quickstart)
|
|
39
|
+
|
|
40
|
+
[Methods](#methods)
|
|
41
|
+
|
|
42
|
+
[API endpoints](#api-endpoints)
|
|
43
|
+
|
|
44
|
+
[Advanced usage](#advanced-usage)
|
|
45
|
+
|
|
46
|
+
[Contributing](#contributing)
|
|
47
|
+
|
|
48
|
+
</details>
|
|
49
|
+
|
|
50
|
+
# Installation
|
|
51
|
+
|
|
52
|
+
Python 3.8 or higher is required. Install with pip:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install hakai-api
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
# Quickstart
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from hakai_api import Client
|
|
62
|
+
|
|
63
|
+
# Get the api request client
|
|
64
|
+
client = Client() # Follow stdout prompts to get an API token
|
|
65
|
+
|
|
66
|
+
# Make a data request for chlorophyll data
|
|
67
|
+
url = '%s/%s' % (client.api_root, 'eims/views/output/chlorophyll?limit=50')
|
|
68
|
+
response = client.get(url)
|
|
69
|
+
|
|
70
|
+
print(url) # https://hecate.hakai.org/api/eims/views/output/chlorophyll...
|
|
71
|
+
print(response.json())
|
|
72
|
+
# [{'action': '', 'event_pk': 7064, 'rn': '1', 'date': '2012-05-17', 'work_area': 'CALVERT'...
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
# Methods
|
|
76
|
+
|
|
77
|
+
This library exports a single client name `Client`. Instantiating this class produces
|
|
78
|
+
a `requests.Session` client from the Python requests library. The Hakai API Python
|
|
79
|
+
Client inherits directly from `requests.Session` thus all methods available on that
|
|
80
|
+
parent class are available. For details see
|
|
81
|
+
the [requests documentation](http://docs.python-requests.org/).
|
|
82
|
+
|
|
83
|
+
The hakai_api `Client` class also contains a property `api_root` which is useful for
|
|
84
|
+
constructing urls to access data from the API. The
|
|
85
|
+
above [Quickstart example](#quickstart) demonstrates using this property to construct a
|
|
86
|
+
url to access project names.
|
|
87
|
+
|
|
88
|
+
# API endpoints
|
|
89
|
+
|
|
90
|
+
For details about the API, including available endpoints where data can be requested
|
|
91
|
+
from, see the [Hakai API documentation](https://github.com/HakaiInstitute/hakai-api).
|
|
92
|
+
|
|
93
|
+
# Advanced usage
|
|
94
|
+
|
|
95
|
+
You can specify which API to access when instantiating the Client. By default, the API
|
|
96
|
+
uses `https://hecate.hakai.org/api` as the API root. It may be useful to use this
|
|
97
|
+
library to access a locally running API instance or to access the Goose API for testing
|
|
98
|
+
purposes. If you are always going to be accessing data from a locally running API
|
|
99
|
+
instance, you are better off using the requests.py library directly since Authorization
|
|
100
|
+
is not required for local requests.
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from hakai_api import Client
|
|
104
|
+
|
|
105
|
+
# Get a client for a locally running API instance
|
|
106
|
+
client = Client("http://localhost:8666")
|
|
107
|
+
print(client.api_root) # http://localhost:8666
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
You can also pass in the credentials string retrieved from the hakai API login page
|
|
111
|
+
while initiating the Client class.
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
from hakai_api import Client
|
|
115
|
+
|
|
116
|
+
# Pass a credentials token as the Client Class is initiated
|
|
117
|
+
client = Client(credentials="CREDENTIAL_TOKEN")
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Finally, you can set credentials for the client class using the `HAKAI_API_CREDENTIALS`
|
|
121
|
+
environment variable. This is useful for e.g. setting credentials in a docker container.
|
|
122
|
+
The value of the environment variable should be the credentials token retrieved from the
|
|
123
|
+
Hakai API login page.
|
|
124
|
+
|
|
125
|
+
# Contributing
|
|
126
|
+
|
|
127
|
+
See [CONTRIBUTING](CONTRIBUTING.md)
|
|
128
|
+
|
|
129
|
+
# License
|
|
130
|
+
|
|
131
|
+
See [LICENSE](LICENSE.md)
|
|
132
|
+
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Hakai Api Python Client
|
|
2
|
+
|
|
3
|
+
This project exports a single Python class that can be used to make HTTP requests to the
|
|
4
|
+
Hakai API resource server.
|
|
5
|
+
The exported `Client` class extends the functionality of the
|
|
6
|
+
Python [requests library](https://docs.python-requests.org/en/master/) to supply Hakai
|
|
7
|
+
OAuth2 credentials with url requests.
|
|
8
|
+
|
|
9
|
+
 [](https://github.com/HakaiInstitute/hakai-api-client-py/actions/workflows/test.yaml) [](https://opensource.org/licenses/MIT)
|
|
10
|
+
|
|
11
|
+
<details>
|
|
12
|
+
|
|
13
|
+
<summary>Table of Contents</summary>
|
|
14
|
+
|
|
15
|
+
[Installation](#installation)
|
|
16
|
+
|
|
17
|
+
[Quickstart](#quickstart)
|
|
18
|
+
|
|
19
|
+
[Methods](#methods)
|
|
20
|
+
|
|
21
|
+
[API endpoints](#api-endpoints)
|
|
22
|
+
|
|
23
|
+
[Advanced usage](#advanced-usage)
|
|
24
|
+
|
|
25
|
+
[Contributing](#contributing)
|
|
26
|
+
|
|
27
|
+
</details>
|
|
28
|
+
|
|
29
|
+
# Installation
|
|
30
|
+
|
|
31
|
+
Python 3.8 or higher is required. Install with pip:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install hakai-api
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
# Quickstart
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from hakai_api import Client
|
|
41
|
+
|
|
42
|
+
# Get the api request client
|
|
43
|
+
client = Client() # Follow stdout prompts to get an API token
|
|
44
|
+
|
|
45
|
+
# Make a data request for chlorophyll data
|
|
46
|
+
url = '%s/%s' % (client.api_root, 'eims/views/output/chlorophyll?limit=50')
|
|
47
|
+
response = client.get(url)
|
|
48
|
+
|
|
49
|
+
print(url) # https://hecate.hakai.org/api/eims/views/output/chlorophyll...
|
|
50
|
+
print(response.json())
|
|
51
|
+
# [{'action': '', 'event_pk': 7064, 'rn': '1', 'date': '2012-05-17', 'work_area': 'CALVERT'...
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
# Methods
|
|
55
|
+
|
|
56
|
+
This library exports a single client name `Client`. Instantiating this class produces
|
|
57
|
+
a `requests.Session` client from the Python requests library. The Hakai API Python
|
|
58
|
+
Client inherits directly from `requests.Session` thus all methods available on that
|
|
59
|
+
parent class are available. For details see
|
|
60
|
+
the [requests documentation](http://docs.python-requests.org/).
|
|
61
|
+
|
|
62
|
+
The hakai_api `Client` class also contains a property `api_root` which is useful for
|
|
63
|
+
constructing urls to access data from the API. The
|
|
64
|
+
above [Quickstart example](#quickstart) demonstrates using this property to construct a
|
|
65
|
+
url to access project names.
|
|
66
|
+
|
|
67
|
+
# API endpoints
|
|
68
|
+
|
|
69
|
+
For details about the API, including available endpoints where data can be requested
|
|
70
|
+
from, see the [Hakai API documentation](https://github.com/HakaiInstitute/hakai-api).
|
|
71
|
+
|
|
72
|
+
# Advanced usage
|
|
73
|
+
|
|
74
|
+
You can specify which API to access when instantiating the Client. By default, the API
|
|
75
|
+
uses `https://hecate.hakai.org/api` as the API root. It may be useful to use this
|
|
76
|
+
library to access a locally running API instance or to access the Goose API for testing
|
|
77
|
+
purposes. If you are always going to be accessing data from a locally running API
|
|
78
|
+
instance, you are better off using the requests.py library directly since Authorization
|
|
79
|
+
is not required for local requests.
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
from hakai_api import Client
|
|
83
|
+
|
|
84
|
+
# Get a client for a locally running API instance
|
|
85
|
+
client = Client("http://localhost:8666")
|
|
86
|
+
print(client.api_root) # http://localhost:8666
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
You can also pass in the credentials string retrieved from the hakai API login page
|
|
90
|
+
while initiating the Client class.
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
from hakai_api import Client
|
|
94
|
+
|
|
95
|
+
# Pass a credentials token as the Client Class is initiated
|
|
96
|
+
client = Client(credentials="CREDENTIAL_TOKEN")
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Finally, you can set credentials for the client class using the `HAKAI_API_CREDENTIALS`
|
|
100
|
+
environment variable. This is useful for e.g. setting credentials in a docker container.
|
|
101
|
+
The value of the environment variable should be the credentials token retrieved from the
|
|
102
|
+
Hakai API login page.
|
|
103
|
+
|
|
104
|
+
# Contributing
|
|
105
|
+
|
|
106
|
+
See [CONTRIBUTING](CONTRIBUTING.md)
|
|
107
|
+
|
|
108
|
+
# License
|
|
109
|
+
|
|
110
|
+
See [LICENSE](LICENSE.md)
|
|
@@ -17,31 +17,34 @@ class Client(OAuth2Session):
|
|
|
17
17
|
_credentials_file = os.path.expanduser("~/.hakai-api-auth")
|
|
18
18
|
DEFAULT_API_ROOT = "https://hecate.hakai.org/api"
|
|
19
19
|
DEFAULT_LOGIN_PAGE = "https://hecate.hakai.org/api-client-login"
|
|
20
|
+
CREDENTIALS_ENV_VAR = "HAKAI_API_CREDENTIALS"
|
|
20
21
|
|
|
21
22
|
def __init__(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
self,
|
|
24
|
+
api_root: str = DEFAULT_API_ROOT,
|
|
25
|
+
login_page: str = DEFAULT_LOGIN_PAGE,
|
|
26
|
+
credentials: Union[str, Dict] = None,
|
|
26
27
|
):
|
|
27
28
|
"""Create a new Client class with credentials.
|
|
28
29
|
|
|
29
30
|
Params:
|
|
30
31
|
api_root: The base url of the hakai api you want to call.
|
|
31
|
-
|
|
32
|
-
credentials (str, Dict): Credentials token retrieved from the hakai api
|
|
33
|
-
|
|
32
|
+
Defaults to the production server.
|
|
33
|
+
credentials (str, Dict): Credentials token retrieved from the hakai api
|
|
34
|
+
login page. If `None`, loads cached credentials or prompts for log in.
|
|
34
35
|
"""
|
|
35
36
|
self._api_root = api_root
|
|
36
37
|
self._login_page = login_page
|
|
37
38
|
self._credentials = None
|
|
38
39
|
|
|
39
|
-
|
|
40
|
+
env_credentials = os.getenv(self.CREDENTIALS_ENV_VAR, None)
|
|
41
|
+
if env_credentials is not None:
|
|
42
|
+
self._credentials = self._parse_credentials_string(env_credentials)
|
|
43
|
+
elif isinstance(credentials, dict):
|
|
40
44
|
self._credentials = credentials
|
|
41
45
|
elif isinstance(credentials, str):
|
|
42
46
|
# Parse credentials from string
|
|
43
|
-
self._credentials =
|
|
44
|
-
map(lambda x: x.split("="), credentials.split("&")))
|
|
47
|
+
self._credentials = self._parse_credentials_string(credentials)
|
|
45
48
|
elif self.file_credentials_are_valid():
|
|
46
49
|
self._credentials = self._get_credentials_from_file()
|
|
47
50
|
else:
|
|
@@ -89,33 +92,34 @@ class Client(OAuth2Session):
|
|
|
89
92
|
"""Check if the cached credentials exist and are valid."""
|
|
90
93
|
if not os.path.isfile(cls._credentials_file):
|
|
91
94
|
return False
|
|
92
|
-
|
|
93
|
-
with open(cls._credentials_file, "rb"):
|
|
95
|
+
with open(cls._credentials_file, "r"):
|
|
94
96
|
try:
|
|
95
97
|
credentials = cls._get_credentials_from_file()
|
|
96
|
-
expires_at =
|
|
98
|
+
expires_at = credentials["expires_at"]
|
|
97
99
|
except (KeyError, ValueError):
|
|
98
100
|
os.remove(cls._credentials_file)
|
|
99
101
|
return False
|
|
100
102
|
|
|
101
103
|
now = int(
|
|
102
104
|
(
|
|
103
|
-
|
|
104
|
-
|
|
105
|
+
mktime(datetime.now().timetuple())
|
|
106
|
+
+ datetime.now().microsecond / 1000000.0
|
|
105
107
|
)
|
|
106
108
|
) # utc timestamp
|
|
107
109
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
110
|
+
if now > expires_at:
|
|
111
|
+
cls.reset_credentials()
|
|
112
|
+
return False
|
|
111
113
|
|
|
112
114
|
return True
|
|
113
115
|
|
|
114
116
|
@classmethod
|
|
115
117
|
def _get_credentials_from_file(cls) -> Dict:
|
|
116
118
|
"""Get user credentials from a cached file."""
|
|
117
|
-
with open(cls._credentials_file, "
|
|
118
|
-
|
|
119
|
+
with open(cls._credentials_file, "r") as infile:
|
|
120
|
+
result = json.load(infile)
|
|
121
|
+
result = Client._check_keys_convert_types(result)
|
|
122
|
+
return result
|
|
119
123
|
|
|
120
124
|
def _get_credentials_from_web(self) -> Dict:
|
|
121
125
|
"""Get user credentials from a web sign-in."""
|
|
@@ -126,3 +130,32 @@ class Client(OAuth2Session):
|
|
|
126
130
|
# Reformat response to dict
|
|
127
131
|
credentials = dict(map(lambda x: x.split("="), response.split("&")))
|
|
128
132
|
return credentials
|
|
133
|
+
|
|
134
|
+
@staticmethod
|
|
135
|
+
def _parse_credentials_string(credentials: str) -> Dict:
|
|
136
|
+
"""Parse a credentials string into a dictionary."""
|
|
137
|
+
result = dict(map(lambda x: x.split("="), credentials.split("&")))
|
|
138
|
+
result = Client._check_keys_convert_types(result)
|
|
139
|
+
return result
|
|
140
|
+
|
|
141
|
+
@staticmethod
|
|
142
|
+
def _check_keys_convert_types(credentials: dict) -> dict:
|
|
143
|
+
"""Check that the credentials dict has the required keys and convert types."""
|
|
144
|
+
missing_keys = [
|
|
145
|
+
key
|
|
146
|
+
for key in ["access_token", "token_type", "expires_at"]
|
|
147
|
+
if key not in credentials
|
|
148
|
+
]
|
|
149
|
+
if len(missing_keys) > 0:
|
|
150
|
+
raise ValueError(
|
|
151
|
+
f"Credentials string is missing required keys: {str(missing_keys)}."
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
# Convert expires_at to int
|
|
155
|
+
credentials["expires_at"] = int(float(credentials["expires_at"]))
|
|
156
|
+
|
|
157
|
+
# If expires_in is present, convert to int
|
|
158
|
+
if "expires_in" in credentials:
|
|
159
|
+
credentials["expires_in"] = int(float(credentials["expires_in"]))
|
|
160
|
+
|
|
161
|
+
return credentials
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "hakai_api"
|
|
3
|
+
version = "v1.5.0"
|
|
4
|
+
description = "Get Hakai database resources using http calls"
|
|
5
|
+
authors = ["Taylor Denouden <taylor.denouden@hakai.org>"]
|
|
6
|
+
license = "MIT"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
packages = [{include = "hakai_api"}]
|
|
9
|
+
repository = "https://github.com/HakaiInstitute/hakai-api-client-py"
|
|
10
|
+
|
|
11
|
+
[tool.poetry.dependencies]
|
|
12
|
+
python = "^3.8,<3.12"
|
|
13
|
+
pytz = "^2023.3"
|
|
14
|
+
requests = "^2.30.0"
|
|
15
|
+
requests-oauthlib = "^1.3.1"
|
|
16
|
+
|
|
17
|
+
[tool.poetry.group.dev.dependencies]
|
|
18
|
+
black = "^23.3.0"
|
|
19
|
+
isort = "^5.12.0"
|
|
20
|
+
pre-commit = "^3.3.1"
|
|
21
|
+
pytest = "^7.3.1"
|
|
22
|
+
ruff = "^0.0.265"
|
|
23
|
+
|
|
24
|
+
[build-system]
|
|
25
|
+
requires = ["poetry-core"]
|
|
26
|
+
build-backend = "poetry.core.masonry.api"
|
hakai_api-1.5.0/setup.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from setuptools import setup
|
|
3
|
+
|
|
4
|
+
packages = \
|
|
5
|
+
['hakai_api']
|
|
6
|
+
|
|
7
|
+
package_data = \
|
|
8
|
+
{'': ['*']}
|
|
9
|
+
|
|
10
|
+
install_requires = \
|
|
11
|
+
['pytz>=2023.3,<2024.0',
|
|
12
|
+
'requests-oauthlib>=1.3.1,<2.0.0',
|
|
13
|
+
'requests>=2.30.0,<3.0.0']
|
|
14
|
+
|
|
15
|
+
setup_kwargs = {
|
|
16
|
+
'name': 'hakai-api',
|
|
17
|
+
'version': '1.5.0',
|
|
18
|
+
'description': 'Get Hakai database resources using http calls',
|
|
19
|
+
'long_description': '# Hakai Api Python Client\n\nThis project exports a single Python class that can be used to make HTTP requests to the\nHakai API resource server.\nThe exported `Client` class extends the functionality of the\nPython [requests library](https://docs.python-requests.org/en/master/) to supply Hakai\nOAuth2 credentials with url requests.\n\n [](https://github.com/HakaiInstitute/hakai-api-client-py/actions/workflows/test.yaml) [](https://opensource.org/licenses/MIT)\n\n<details>\n\n<summary>Table of Contents</summary>\n\n[Installation](#installation)\n\n[Quickstart](#quickstart)\n\n[Methods](#methods)\n\n[API endpoints](#api-endpoints)\n\n[Advanced usage](#advanced-usage)\n\n[Contributing](#contributing)\n\n</details>\n\n# Installation\n\nPython 3.8 or higher is required. Install with pip:\n\n```bash\npip install hakai-api\n```\n\n# Quickstart\n\n```python\nfrom hakai_api import Client\n\n# Get the api request client\nclient = Client() # Follow stdout prompts to get an API token\n\n# Make a data request for chlorophyll data\nurl = \'%s/%s\' % (client.api_root, \'eims/views/output/chlorophyll?limit=50\')\nresponse = client.get(url)\n\nprint(url) # https://hecate.hakai.org/api/eims/views/output/chlorophyll...\nprint(response.json())\n# [{\'action\': \'\', \'event_pk\': 7064, \'rn\': \'1\', \'date\': \'2012-05-17\', \'work_area\': \'CALVERT\'...\n```\n\n# Methods\n\nThis library exports a single client name `Client`. Instantiating this class produces\na `requests.Session` client from the Python requests library. The Hakai API Python\nClient inherits directly from `requests.Session` thus all methods available on that\nparent class are available. For details see\nthe [requests documentation](http://docs.python-requests.org/).\n\nThe hakai_api `Client` class also contains a property `api_root` which is useful for\nconstructing urls to access data from the API. The\nabove [Quickstart example](#quickstart) demonstrates using this property to construct a\nurl to access project names.\n\n# API endpoints\n\nFor details about the API, including available endpoints where data can be requested\nfrom, see the [Hakai API documentation](https://github.com/HakaiInstitute/hakai-api).\n\n# Advanced usage\n\nYou can specify which API to access when instantiating the Client. By default, the API\nuses `https://hecate.hakai.org/api` as the API root. It may be useful to use this\nlibrary to access a locally running API instance or to access the Goose API for testing\npurposes. If you are always going to be accessing data from a locally running API\ninstance, you are better off using the requests.py library directly since Authorization\nis not required for local requests.\n\n```python\nfrom hakai_api import Client\n\n# Get a client for a locally running API instance\nclient = Client("http://localhost:8666")\nprint(client.api_root) # http://localhost:8666\n```\n\nYou can also pass in the credentials string retrieved from the hakai API login page\nwhile initiating the Client class.\n\n```python\nfrom hakai_api import Client\n\n# Pass a credentials token as the Client Class is initiated\nclient = Client(credentials="CREDENTIAL_TOKEN")\n```\n\nFinally, you can set credentials for the client class using the `HAKAI_API_CREDENTIALS`\nenvironment variable. This is useful for e.g. setting credentials in a docker container.\nThe value of the environment variable should be the credentials token retrieved from the\nHakai API login page.\n\n# Contributing\n\nSee [CONTRIBUTING](CONTRIBUTING.md)\n\n# License\n\nSee [LICENSE](LICENSE.md)\n',
|
|
20
|
+
'author': 'Taylor Denouden',
|
|
21
|
+
'author_email': 'taylor.denouden@hakai.org',
|
|
22
|
+
'maintainer': 'None',
|
|
23
|
+
'maintainer_email': 'None',
|
|
24
|
+
'url': 'https://github.com/HakaiInstitute/hakai-api-client-py',
|
|
25
|
+
'packages': packages,
|
|
26
|
+
'package_data': package_data,
|
|
27
|
+
'install_requires': install_requires,
|
|
28
|
+
'python_requires': '>=3.8,<3.12',
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
setup(**setup_kwargs)
|
hakai_api-1.4.0/PKG-INFO
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: hakai_api
|
|
3
|
-
Version: 1.4.0
|
|
4
|
-
Summary: Get Hakai database resources using http calls
|
|
5
|
-
Home-page: https://github.com/HakaiInstitute/hakai-api-client-python
|
|
6
|
-
Author: Taylor Denouden
|
|
7
|
-
Author-email: taylor.denouden@hakai.org
|
|
8
|
-
License: MIT
|
|
9
|
-
Description-Content-Type: text/markdown
|
|
10
|
-
|
|
11
|
-
# Hakai Api Python Client
|
|
12
|
-
|
|
13
|
-
This project exports a single Python class that can be used to make HTTP requests to the Hakai API resource server.
|
|
14
|
-
The exported `Client` class extends the functionality of the Python [requests library](https://docs.python-requests.org/en/master/) to supply Hakai OAuth2 credentials with url requests.
|
|
15
|
-
|
|
16
|
-
# Installation
|
|
17
|
-
|
|
18
|
-
```bash
|
|
19
|
-
pip install hakai-api
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
# Requirements
|
|
23
|
-
Python 3.6 or higher
|
|
24
|
-
|
|
25
|
-
# Quickstart
|
|
26
|
-
|
|
27
|
-
```python
|
|
28
|
-
from hakai_api import Client
|
|
29
|
-
|
|
30
|
-
# Get the api request client
|
|
31
|
-
client = Client() # Follow stdout prompts to get an API token
|
|
32
|
-
|
|
33
|
-
# Make a data request for chlorophyll data
|
|
34
|
-
url = '%s/%s' % (client.api_root, 'eims/views/output/chlorophyll?limit=50')
|
|
35
|
-
response = client.get(url)
|
|
36
|
-
|
|
37
|
-
print(url) # https://hecate.hakai.org/api/eims/views/output/chlorophyll...
|
|
38
|
-
print(response.json()) # [{'action': '', 'event_pk': 7064, 'rn': '1', 'date': '2012-05-17', 'work_area': 'CALVERT'...
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
# Methods
|
|
42
|
-
|
|
43
|
-
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](http://docs.python-requests.org/).
|
|
44
|
-
|
|
45
|
-
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](#quickstart) demonstrates using this property to construct a url to access project names.
|
|
46
|
-
|
|
47
|
-
# API endpoints
|
|
48
|
-
|
|
49
|
-
For details about the API, including available endpoints where data can be requested from, see the [Hakai API documentation](https://github.com/HakaiInstitute/hakai-api).
|
|
50
|
-
|
|
51
|
-
# Advanced usage
|
|
52
|
-
|
|
53
|
-
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.
|
|
54
|
-
|
|
55
|
-
```python
|
|
56
|
-
# Get a client for a locally running API instance
|
|
57
|
-
client = Client("http://localhost:8666")
|
|
58
|
-
print(client.api_root) # http://localhost:8666
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
You can also pass in the credentials string retrieved from the hakai API login page while initiating the Client class.
|
|
62
|
-
|
|
63
|
-
```python
|
|
64
|
-
# Pass a credentials token as the Client Class is initiated
|
|
65
|
-
client = Client(credentials="CREDENTIAL_TOKEN")
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
# Development
|
|
69
|
-
The business code for this package is in the file [`hakai_api/Client.py`](hakai_api/Client.py).
|
|
70
|
-
The `./setup.py` file is important for giving details about how to install the package when users do `pip install hakai-api`.
|
|
71
|
-
|
|
72
|
-
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`).
|
|
73
|
-
Github Actions should take care of packaging and pushing it to Hakai's PyPi repository from there.
|
hakai_api-1.4.0/README.md
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
# Hakai Api Python Client
|
|
2
|
-
|
|
3
|
-
This project exports a single Python class that can be used to make HTTP requests to the Hakai API resource server.
|
|
4
|
-
The exported `Client` class extends the functionality of the Python [requests library](https://docs.python-requests.org/en/master/) to supply Hakai OAuth2 credentials with url requests.
|
|
5
|
-
|
|
6
|
-
# Installation
|
|
7
|
-
|
|
8
|
-
```bash
|
|
9
|
-
pip install hakai-api
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
# Requirements
|
|
13
|
-
Python 3.6 or higher
|
|
14
|
-
|
|
15
|
-
# Quickstart
|
|
16
|
-
|
|
17
|
-
```python
|
|
18
|
-
from hakai_api import Client
|
|
19
|
-
|
|
20
|
-
# Get the api request client
|
|
21
|
-
client = Client() # Follow stdout prompts to get an API token
|
|
22
|
-
|
|
23
|
-
# Make a data request for chlorophyll data
|
|
24
|
-
url = '%s/%s' % (client.api_root, 'eims/views/output/chlorophyll?limit=50')
|
|
25
|
-
response = client.get(url)
|
|
26
|
-
|
|
27
|
-
print(url) # https://hecate.hakai.org/api/eims/views/output/chlorophyll...
|
|
28
|
-
print(response.json()) # [{'action': '', 'event_pk': 7064, 'rn': '1', 'date': '2012-05-17', 'work_area': 'CALVERT'...
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
# Methods
|
|
32
|
-
|
|
33
|
-
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](http://docs.python-requests.org/).
|
|
34
|
-
|
|
35
|
-
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](#quickstart) demonstrates using this property to construct a url to access project names.
|
|
36
|
-
|
|
37
|
-
# API endpoints
|
|
38
|
-
|
|
39
|
-
For details about the API, including available endpoints where data can be requested from, see the [Hakai API documentation](https://github.com/HakaiInstitute/hakai-api).
|
|
40
|
-
|
|
41
|
-
# Advanced usage
|
|
42
|
-
|
|
43
|
-
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.
|
|
44
|
-
|
|
45
|
-
```python
|
|
46
|
-
# Get a client for a locally running API instance
|
|
47
|
-
client = Client("http://localhost:8666")
|
|
48
|
-
print(client.api_root) # http://localhost:8666
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
You can also pass in the credentials string retrieved from the hakai API login page while initiating the Client class.
|
|
52
|
-
|
|
53
|
-
```python
|
|
54
|
-
# Pass a credentials token as the Client Class is initiated
|
|
55
|
-
client = Client(credentials="CREDENTIAL_TOKEN")
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
# Development
|
|
59
|
-
The business code for this package is in the file [`hakai_api/Client.py`](hakai_api/Client.py).
|
|
60
|
-
The `./setup.py` file is important for giving details about how to install the package when users do `pip install hakai-api`.
|
|
61
|
-
|
|
62
|
-
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`).
|
|
63
|
-
Github Actions should take care of packaging and pushing it to Hakai's PyPi repository from there.
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: hakai-api
|
|
3
|
-
Version: 1.4.0
|
|
4
|
-
Summary: Get Hakai database resources using http calls
|
|
5
|
-
Home-page: https://github.com/HakaiInstitute/hakai-api-client-python
|
|
6
|
-
Author: Taylor Denouden
|
|
7
|
-
Author-email: taylor.denouden@hakai.org
|
|
8
|
-
License: MIT
|
|
9
|
-
Description-Content-Type: text/markdown
|
|
10
|
-
|
|
11
|
-
# Hakai Api Python Client
|
|
12
|
-
|
|
13
|
-
This project exports a single Python class that can be used to make HTTP requests to the Hakai API resource server.
|
|
14
|
-
The exported `Client` class extends the functionality of the Python [requests library](https://docs.python-requests.org/en/master/) to supply Hakai OAuth2 credentials with url requests.
|
|
15
|
-
|
|
16
|
-
# Installation
|
|
17
|
-
|
|
18
|
-
```bash
|
|
19
|
-
pip install hakai-api
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
# Requirements
|
|
23
|
-
Python 3.6 or higher
|
|
24
|
-
|
|
25
|
-
# Quickstart
|
|
26
|
-
|
|
27
|
-
```python
|
|
28
|
-
from hakai_api import Client
|
|
29
|
-
|
|
30
|
-
# Get the api request client
|
|
31
|
-
client = Client() # Follow stdout prompts to get an API token
|
|
32
|
-
|
|
33
|
-
# Make a data request for chlorophyll data
|
|
34
|
-
url = '%s/%s' % (client.api_root, 'eims/views/output/chlorophyll?limit=50')
|
|
35
|
-
response = client.get(url)
|
|
36
|
-
|
|
37
|
-
print(url) # https://hecate.hakai.org/api/eims/views/output/chlorophyll...
|
|
38
|
-
print(response.json()) # [{'action': '', 'event_pk': 7064, 'rn': '1', 'date': '2012-05-17', 'work_area': 'CALVERT'...
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
# Methods
|
|
42
|
-
|
|
43
|
-
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](http://docs.python-requests.org/).
|
|
44
|
-
|
|
45
|
-
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](#quickstart) demonstrates using this property to construct a url to access project names.
|
|
46
|
-
|
|
47
|
-
# API endpoints
|
|
48
|
-
|
|
49
|
-
For details about the API, including available endpoints where data can be requested from, see the [Hakai API documentation](https://github.com/HakaiInstitute/hakai-api).
|
|
50
|
-
|
|
51
|
-
# Advanced usage
|
|
52
|
-
|
|
53
|
-
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.
|
|
54
|
-
|
|
55
|
-
```python
|
|
56
|
-
# Get a client for a locally running API instance
|
|
57
|
-
client = Client("http://localhost:8666")
|
|
58
|
-
print(client.api_root) # http://localhost:8666
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
You can also pass in the credentials string retrieved from the hakai API login page while initiating the Client class.
|
|
62
|
-
|
|
63
|
-
```python
|
|
64
|
-
# Pass a credentials token as the Client Class is initiated
|
|
65
|
-
client = Client(credentials="CREDENTIAL_TOKEN")
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
# Development
|
|
69
|
-
The business code for this package is in the file [`hakai_api/Client.py`](hakai_api/Client.py).
|
|
70
|
-
The `./setup.py` file is important for giving details about how to install the package when users do `pip install hakai-api`.
|
|
71
|
-
|
|
72
|
-
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`).
|
|
73
|
-
Github Actions should take care of packaging and pushing it to Hakai's PyPi repository from there.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
hakai_api
|
hakai_api-1.4.0/setup.cfg
DELETED
hakai_api-1.4.0/setup.py
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
|
|
3
|
-
from setuptools import setup
|
|
4
|
-
|
|
5
|
-
setup(
|
|
6
|
-
name='hakai_api',
|
|
7
|
-
url='https://github.com/HakaiInstitute/hakai-api-client-python',
|
|
8
|
-
author='Taylor Denouden',
|
|
9
|
-
author_email='taylor.denouden@hakai.org',
|
|
10
|
-
packages=['hakai_api'],
|
|
11
|
-
install_requires=[
|
|
12
|
-
'pytz',
|
|
13
|
-
'requests',
|
|
14
|
-
'requests-oauthlib',
|
|
15
|
-
],
|
|
16
|
-
version=os.getenv('VERSION', '1.0.0.dev1'),
|
|
17
|
-
license='MIT',
|
|
18
|
-
description='Get Hakai database resources using http calls',
|
|
19
|
-
long_description=open('README.md').read(),
|
|
20
|
-
long_description_content_type="text/markdown"
|
|
21
|
-
)
|