hakai_api 1.5.2__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.
@@ -0,0 +1,21 @@
1
+ name: lint
2
+ on:
3
+ push:
4
+ branches:
5
+ - main
6
+ pull_request:
7
+ branches:
8
+ - main
9
+ workflow_dispatch:
10
+
11
+ jobs:
12
+ Tests:
13
+ name: lint
14
+ runs-on: Ubuntu-latest
15
+ concurrency:
16
+ group: ${{ github.workflow }}-${{ github.ref }}
17
+ cancel-in-progress: true
18
+
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+ - uses: astral-sh/ruff-action@v3
@@ -0,0 +1,52 @@
1
+ name: 'PyPI Publish 🐍'
2
+
3
+ on:
4
+ push:
5
+ branches-ignore:
6
+ - '**'
7
+ tags:
8
+ - 'v[0-9]+.[0-9]+.[0-9]+'
9
+ - 'v[0-9]+.[0-9]+.[0-9]+rc[0-9]+'
10
+
11
+ jobs:
12
+ publish:
13
+ name: upload release to PyPI
14
+ runs-on: ubuntu-latest
15
+ environment: pypi
16
+ permissions:
17
+ id-token: write
18
+ steps:
19
+ - uses: actions/checkout@v4
20
+
21
+ - name: Get tag
22
+ id: tag
23
+ run: echo "tag=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
24
+
25
+ - name: Install uv
26
+ uses: astral-sh/setup-uv@v5
27
+ with:
28
+ enable-cache: true
29
+
30
+ - name: "Set up Python"
31
+ uses: actions/setup-python@v5
32
+ with:
33
+ python-version: "3.x"
34
+
35
+ - name: "Set version"
36
+ run: |
37
+ uv version ${{ env.tag }}
38
+ uv lock
39
+
40
+ - name: Install the project
41
+ run: uv sync --locked --all-extras --dev
42
+
43
+ - name: Run tests
44
+ run: uv run pytest tests
45
+
46
+ - name: Build the project
47
+ run: uv build
48
+
49
+ - name: Publish to PyPI
50
+ env:
51
+ UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }}
52
+ run: uv publish
@@ -0,0 +1,48 @@
1
+ name: tests
2
+ on:
3
+ push:
4
+ branches:
5
+ - main
6
+ pull_request:
7
+ branches:
8
+ - main
9
+ workflow_dispatch:
10
+
11
+ jobs:
12
+ Tests:
13
+ name: test ${{ matrix.py }} - ${{ matrix.os }}
14
+ runs-on: ${{ matrix.os }}-latest
15
+ concurrency:
16
+ group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.os }}-${{ matrix.py }}
17
+ cancel-in-progress: true
18
+
19
+ strategy:
20
+ fail-fast: false
21
+ matrix:
22
+ os:
23
+ - Ubuntu
24
+ - Windows
25
+ - MacOs
26
+ py:
27
+ - "3.13"
28
+ - "3.12"
29
+ - "3.11"
30
+ - "3.10"
31
+ - "3.9"
32
+ steps:
33
+ - uses: actions/checkout@v4
34
+ - name: Install uv
35
+ uses: astral-sh/setup-uv@v5
36
+ with:
37
+ enable-cache: true
38
+
39
+ - name: "Set up Python"
40
+ uses: actions/setup-python@v5
41
+ with:
42
+ python-version: ${{ matrix.py }}
43
+
44
+ - name: Install dependencies
45
+ run: uv sync --locked --all-extras --dev
46
+
47
+ - name: Run tests
48
+ run: uv run pytest tests
@@ -0,0 +1,103 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ env/
12
+ build/
13
+ develop-eggs/
14
+ dist/
15
+ downloads/
16
+ eggs/
17
+ .eggs/
18
+ lib/
19
+ lib64/
20
+ parts/
21
+ sdist/
22
+ var/
23
+ wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+
28
+ # PyInstaller
29
+ # Usually these files are written by a python script from a template
30
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
31
+ *.manifest
32
+ *.spec
33
+
34
+ # Installer logs
35
+ pip-log.txt
36
+ pip-delete-this-directory.txt
37
+
38
+ # Unit test / coverage reports
39
+ htmlcov/
40
+ .tox/
41
+ .coverage
42
+ .coverage.*
43
+ .cache
44
+ nosetests.xml
45
+ coverage.xml
46
+ *.cover
47
+ .hypothesis/
48
+
49
+ # Translations
50
+ *.mo
51
+ *.pot
52
+
53
+ # Django stuff:
54
+ *.log
55
+ local_settings.py
56
+
57
+ # Flask stuff:
58
+ instance/
59
+ .webassets-cache
60
+
61
+ # Scrapy stuff:
62
+ .scrapy
63
+
64
+ # Sphinx documentation
65
+ docs/_build/
66
+
67
+ # PyBuilder
68
+ target/
69
+
70
+ # Jupyter Notebook
71
+ .ipynb_checkpoints
72
+
73
+ # pyenv
74
+ .python-version
75
+
76
+ # celery beat schedule file
77
+ celerybeat-schedule
78
+
79
+ # SageMath parsed files
80
+ *.sage.py
81
+
82
+ # dotenv
83
+ .env
84
+
85
+ # virtualenv
86
+ .venv
87
+ venv/
88
+ ENV/
89
+
90
+ # Spyder project settings
91
+ .spyderproject
92
+ .spyproject
93
+
94
+ # Rope project settings
95
+ .ropeproject
96
+
97
+ # mkdocs documentation
98
+ /site
99
+
100
+ # mypy
101
+ .mypy_cache/
102
+
103
+ .idea/
@@ -0,0 +1,19 @@
1
+ # See https://pre-commit.com for more information
2
+ # See https://pre-commit.com/hooks.html for more hooks
3
+ repos:
4
+ - repo: https://github.com/pre-commit/pre-commit-hooks
5
+ rev: v5.0.0
6
+ hooks:
7
+ - id: trailing-whitespace
8
+ - id: end-of-file-fixer
9
+ - id: check-yaml
10
+ - id: check-added-large-files
11
+ - repo: https://github.com/astral-sh/ruff-pre-commit
12
+ # Ruff version.
13
+ rev: v0.11.9
14
+ hooks:
15
+ # Run the linter.
16
+ - id: ruff
17
+ args: [ --fix ]
18
+ # Run the formatter.
19
+ - id: ruff-format
@@ -0,0 +1 @@
1
+ * @tayden
@@ -0,0 +1,99 @@
1
+ # Contributing
2
+
3
+ This document describes how to set up a development environment for this project, modify
4
+ and test the code, and deploy a new version.
5
+
6
+ <details>
7
+
8
+ <summary>Table of Contents</summary>
9
+
10
+ [Project structure](#project-structure)
11
+
12
+ [Configuration](#configuration)
13
+
14
+ [Tests](#tests)
15
+
16
+ [Deployment](#deployment)
17
+
18
+ </details>
19
+
20
+ ## Project structure
21
+
22
+ The business logic for this package is located
23
+ in [`src/hakai_api/Client.py`](src/hakai_api/Client.py).
24
+ All tests are located in the `tests/` directory.
25
+
26
+ ## Configuration
27
+
28
+ ### uv
29
+
30
+ This project uses [uv](https://github.com/astral-sh/uv) for dependency management and
31
+ package installation. Install `uv` using the instructions on their website before continuing.
32
+
33
+ To set up an environment for development, clone this repository and run the following
34
+ commands from the root directory of the repository:
35
+
36
+ ```bash
37
+ # Create and activate a virtual environment (optional but recommended)
38
+ python -m venv .venv
39
+ source .venv/bin/activate # On Windows use: .venv\Scripts\activate
40
+
41
+ # Install the package and its dependencies
42
+ uv sync --dev
43
+ ```
44
+
45
+ ### Pre-commit
46
+
47
+ This project uses [pre-commit](https://pre-commit.com/) to run lint checks and tests
48
+ before every commit. To install the pre-commit hooks, run the following command from the
49
+ root directory of the repository while the virtual environment is active:
50
+
51
+ ```bash
52
+ pre-commit install
53
+ ```
54
+
55
+ This is highly recommended and will prevent failed builds on GitHub Actions, as well as
56
+ ensure consistent code style and quality.
57
+
58
+ You can also run the pre-commit hooks manually on all files by running:
59
+
60
+ ```bash
61
+ pre-commit run -a
62
+ ```
63
+
64
+ ## Tests
65
+
66
+ Tests and lint checks are automatically run on pull requests and pushes to the main
67
+ branch using GitHub Actions.
68
+
69
+ To run the tests locally, run the following command from the root directory of the
70
+ repository while the virtual environment is active:
71
+
72
+ ```bash
73
+ pytest
74
+ ```
75
+
76
+ To run lint checks locally:
77
+
78
+ ```bash
79
+ ruff check .
80
+ ```
81
+
82
+ To automatically fix linting issues:
83
+
84
+ ```bash
85
+ ruff check --fix .
86
+ ```
87
+
88
+ To automatically format the code:
89
+
90
+ ```bash
91
+ ruff format .
92
+ ```
93
+
94
+ ## Deployment
95
+
96
+ To build and deploy a new PyPi package version, push a tag matching the
97
+ pattern `v[0-9]+.[0-9]+.[0-9]+` or `v[0-9]+.[0-9]+.[0-9]+rc[0-9]+` (e.g. `v0.4.1`
98
+ or `v0.5.2rc1`) to GitHub. GitHub Actions will take care of packaging and pushing it
99
+ to Hakai's PyPi repository from there.
@@ -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.
@@ -0,0 +1,123 @@
1
+ Metadata-Version: 2.4
2
+ Name: hakai_api
3
+ Version: 1.5.2
4
+ Summary: Get Hakai database resources using http calls
5
+ Author-email: Taylor Denouden <taylor.denouden@hakai.org>
6
+ License-Expression: MIT
7
+ License-File: LICENSE
8
+ Requires-Python: >=3.8
9
+ Requires-Dist: pytz>=2025.2
10
+ Requires-Dist: requests-oauthlib>=2.0.0
11
+ Requires-Dist: requests>=2.32.3
12
+ Description-Content-Type: text/markdown
13
+
14
+ # Hakai Api Python Client
15
+
16
+ This project exports a single Python class that can be used to make HTTP requests to the
17
+ Hakai API resource server.
18
+ The exported `Client` class extends the functionality of the
19
+ Python [requests library](https://docs.python-requests.org/en/master/) to supply Hakai
20
+ OAuth2 credentials with url requests.
21
+
22
+ ![PyPI](https://img.shields.io/pypi/v/hakai-api) [![tests](https://github.com/HakaiInstitute/hakai-api-client-py/actions/workflows/test.yaml/badge.svg)](https://github.com/HakaiInstitute/hakai-api-client-py/actions/workflows/test.yaml) [![License: MIT](https://img.shields.io/badge/License-MIT-black.svg)](https://opensource.org/licenses/MIT)
23
+
24
+ <details>
25
+
26
+ <summary>Table of Contents</summary>
27
+
28
+ [Installation](#installation)
29
+
30
+ [Quickstart](#quickstart)
31
+
32
+ [Methods](#methods)
33
+
34
+ [API endpoints](#api-endpoints)
35
+
36
+ [Advanced usage](#advanced-usage)
37
+
38
+ [Contributing](#contributing)
39
+
40
+ </details>
41
+
42
+ # Installation
43
+
44
+ Python 3.8 or higher is required. Install with pip:
45
+
46
+ ```bash
47
+ pip install hakai-api
48
+ ```
49
+
50
+ # Quickstart
51
+
52
+ ```python
53
+ from hakai_api import Client
54
+
55
+ # Get the api request client
56
+ client = Client() # Follow stdout prompts to get an API token
57
+
58
+ # Make a data request for chlorophyll data
59
+ url = '%s/%s' % (client.api_root, 'eims/views/output/chlorophyll?limit=50')
60
+ response = client.get(url)
61
+
62
+ print(url) # https://hecate.hakai.org/api/eims/views/output/chlorophyll...
63
+ print(response.json())
64
+ # [{'action': '', 'event_pk': 7064, 'rn': '1', 'date': '2012-05-17', 'work_area': 'CALVERT'...
65
+ ```
66
+
67
+ # Methods
68
+
69
+ This library exports a single client name `Client`. Instantiating this class produces
70
+ a `requests.Session` client from the Python requests library. The Hakai API Python
71
+ Client inherits directly from `requests.Session` thus all methods available on that
72
+ parent class are available. For details see
73
+ the [requests documentation](http://docs.python-requests.org/).
74
+
75
+ The hakai_api `Client` class also contains a property `api_root` which is useful for
76
+ constructing urls to access data from the API. The
77
+ above [Quickstart example](#quickstart) demonstrates using this property to construct a
78
+ url to access project names.
79
+
80
+ # API endpoints
81
+
82
+ For details about the API, including available endpoints where data can be requested
83
+ from, see the [Hakai API documentation](https://github.com/HakaiInstitute/hakai-api).
84
+
85
+ # Advanced usage
86
+
87
+ You can specify which API to access when instantiating the Client. By default, the API
88
+ uses `https://hecate.hakai.org/api` as the API root. It may be useful to use this
89
+ library to access a locally running API instance or to access the Goose API for testing
90
+ purposes. If you are always going to be accessing data from a locally running API
91
+ instance, you are better off using the requests.py library directly since Authorization
92
+ is not required for local requests.
93
+
94
+ ```python
95
+ from hakai_api import Client
96
+
97
+ # Get a client for a locally running API instance
98
+ client = Client("http://localhost:8666")
99
+ print(client.api_root) # http://localhost:8666
100
+ ```
101
+
102
+ You can also pass in the credentials string retrieved from the hakai API login page
103
+ while initiating the Client class.
104
+
105
+ ```python
106
+ from hakai_api import Client
107
+
108
+ # Pass a credentials token as the Client Class is initiated
109
+ client = Client(credentials="CREDENTIAL_TOKEN")
110
+ ```
111
+
112
+ Finally, you can set credentials for the client class using the `HAKAI_API_CREDENTIALS`
113
+ environment variable. This is useful for e.g. setting credentials in a docker container.
114
+ The value of the environment variable should be the credentials token retrieved from the
115
+ Hakai API login page.
116
+
117
+ # Contributing
118
+
119
+ See [CONTRIBUTING](CONTRIBUTING.md)
120
+
121
+ # License
122
+
123
+ See [LICENSE](LICENSE.md)
@@ -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
+ ![PyPI](https://img.shields.io/pypi/v/hakai-api) [![tests](https://github.com/HakaiInstitute/hakai-api-client-py/actions/workflows/test.yaml/badge.svg)](https://github.com/HakaiInstitute/hakai-api-client-py/actions/workflows/test.yaml) [![License: MIT](https://img.shields.io/badge/License-MIT-black.svg)](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)
@@ -0,0 +1,14 @@
1
+ """An example showing how to use the Hakai Api Python Client."""
2
+
3
+ from hakai_api import Client
4
+
5
+ if __name__ == "__main__":
6
+ # Get the api request client
7
+ client = Client()
8
+
9
+ # Make a data request for sampling stations
10
+ url = "%s/%s" % (client.api_root, "/aco/views/projects/phases")
11
+ response = client.get(url)
12
+
13
+ print(url)
14
+ print(response.json())
@@ -0,0 +1,28 @@
1
+ [project]
2
+ name = "hakai_api"
3
+ version = "1.5.2"
4
+ description = "Get Hakai database resources using http calls"
5
+ authors = [
6
+ {name = "Taylor Denouden", email = "taylor.denouden@hakai.org"},
7
+ ]
8
+ repository = "https://github.com/HakaiInstitute/hakai-api-client-py"
9
+ license = "MIT"
10
+ readme = "README.md"
11
+ requires-python = ">=3.8"
12
+
13
+ dependencies = [
14
+ "pytz>=2025.2",
15
+ "requests>=2.32.3",
16
+ "requests-oauthlib>=2.0.0",
17
+ ]
18
+
19
+ [dependency-groups]
20
+ dev = [
21
+ "pre-commit>=3.5.0",
22
+ "pytest>=8.3.5",
23
+ "ruff>=0.11.9",
24
+ ]
25
+
26
+ [build-system]
27
+ requires = ["hatchling"]
28
+ build-backend = "hatchling.build"