hydopt-client 0.0.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,25 @@
1
+ name: Release to PyPI
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*"
7
+
8
+ jobs:
9
+ release:
10
+ name: Build and publish to PyPI
11
+ runs-on: ubuntu-latest
12
+ permissions:
13
+ contents: read
14
+ id-token: write
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+
18
+ - name: Set up uv
19
+ uses: astral-sh/setup-uv@v4
20
+
21
+ - name: Build package
22
+ run: uv build
23
+
24
+ - name: Publish to PyPI
25
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,63 @@
1
+ name: Tests
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ jobs:
9
+ lint:
10
+ name: Lint
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+
15
+ - name: Set up uv
16
+ uses: astral-sh/setup-uv@v4
17
+
18
+ - name: Run ruff
19
+ run: uv run ruff check src/
20
+
21
+ test:
22
+ name: Test
23
+ runs-on: ubuntu-latest
24
+ permissions:
25
+ contents: read
26
+ id-token: write
27
+ steps:
28
+ - uses: actions/checkout@v4
29
+
30
+ - name: Set up uv
31
+ uses: astral-sh/setup-uv@v4
32
+
33
+ - name: Authenticate to Google Cloud
34
+ uses: google-github-actions/auth@v2
35
+ with:
36
+ token_format: access_token
37
+ service_account: job-deployer@hydopt.iam.gserviceaccount.com
38
+ workload_identity_provider: projects/131385138719/locations/global/workloadIdentityPools/github-actions/providers/github-actions-provider
39
+
40
+ - name: Configure Docker for GAR
41
+ run: gcloud auth configure-docker us-central1-docker.pkg.dev --quiet
42
+
43
+ - name: Start hydopt-api
44
+ run: docker compose up -d
45
+
46
+ - name: Wait for API
47
+ run: |
48
+ for i in $(seq 1 60); do
49
+ if curl -sf http://localhost:8083/healthz > /dev/null 2>&1; then
50
+ echo "API ready"
51
+ exit 0
52
+ fi
53
+ sleep 1
54
+ done
55
+ docker compose logs
56
+ exit 1
57
+
58
+ - name: Run tests
59
+ run: uv run pytest
60
+
61
+ - name: Dump API logs
62
+ if: always()
63
+ run: docker compose logs
@@ -0,0 +1,219 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ # Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ # poetry.lock
109
+ # poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ # pdm.lock
116
+ # pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ # pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # Redis
135
+ *.rdb
136
+ *.aof
137
+ *.pid
138
+
139
+ # RabbitMQ
140
+ mnesia/
141
+ rabbitmq/
142
+ rabbitmq-data/
143
+
144
+ # ActiveMQ
145
+ activemq-data/
146
+
147
+ # SageMath parsed files
148
+ *.sage.py
149
+
150
+ # Environments
151
+ .env
152
+ .envrc
153
+ .venv
154
+ .hydopt-api/
155
+ env/
156
+ venv/
157
+ ENV/
158
+ env.bak/
159
+ venv.bak/
160
+
161
+ # Spyder project settings
162
+ .spyderproject
163
+ .spyproject
164
+
165
+ # Rope project settings
166
+ .ropeproject
167
+
168
+ # mkdocs documentation
169
+ /site
170
+
171
+ # mypy
172
+ .mypy_cache/
173
+ .dmypy.json
174
+ dmypy.json
175
+
176
+ # Pyre type checker
177
+ .pyre/
178
+
179
+ # pytype static type analyzer
180
+ .pytype/
181
+
182
+ # Cython debug symbols
183
+ cython_debug/
184
+
185
+ # PyCharm
186
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
187
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
188
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
189
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
190
+ # .idea/
191
+
192
+ # Abstra
193
+ # Abstra is an AI-powered process automation framework.
194
+ # Ignore directories containing user credentials, local state, and settings.
195
+ # Learn more at https://abstra.io/docs
196
+ .abstra/
197
+
198
+ # Visual Studio Code
199
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
200
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
201
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
202
+ # you could uncomment the following to ignore the entire vscode folder
203
+ # .vscode/
204
+ # Temporary file for partial code execution
205
+ tempCodeRunnerFile.py
206
+
207
+ # Ruff stuff:
208
+ .ruff_cache/
209
+
210
+ # PyPI configuration file
211
+ .pypirc
212
+
213
+ # Marimo
214
+ marimo/_static/
215
+ marimo/_lsp/
216
+ __marimo__/
217
+
218
+ # Streamlit
219
+ .streamlit/secrets.toml
@@ -0,0 +1,20 @@
1
+ LAST_TAG := $(shell git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
2
+
3
+ ## Create a new semver tag based on conventional commits since last tag
4
+ tag:
5
+ @BUMP=$$(git log $(LAST_TAG)..HEAD --pretty=format:'%s' 2>/dev/null \
6
+ | grep -qE '!:|BREAKING CHANGE' && echo major \
7
+ || git log $(LAST_TAG)..HEAD --pretty=format:'%s' 2>/dev/null \
8
+ | grep -qE '^feat' && echo minor \
9
+ || echo patch); \
10
+ OLD=$$(echo $(LAST_TAG) | sed 's/^v//'); \
11
+ NEW=$$(echo $$OLD | awk -v b=$$BUMP -F. '{ \
12
+ if(b=="major") print $$1+1".0.0"; \
13
+ else if(b=="minor") print $$1"."$$2+1".0"; \
14
+ else print $$1"."$$2"."$$3+1}'); \
15
+ echo "$$OLD -> $$NEW ($$BUMP)"; \
16
+ git tag "v$$NEW"
17
+
18
+ ## Push the latest tag to origin
19
+ push:
20
+ @git push origin $(LAST_TAG)
@@ -0,0 +1,68 @@
1
+ Metadata-Version: 2.5
2
+ Name: hydopt-client
3
+ Version: 0.0.2
4
+ Summary: Python client for the HydOpt hydropower optimization API
5
+ Requires-Python: >=3.13
6
+ Requires-Dist: google-auth>=2.56.3
7
+ Requires-Dist: httpx>=0.28.1
8
+ Requires-Dist: pydantic>=2.13.4
9
+ Requires-Dist: requests>=2.34.2
10
+ Description-Content-Type: text/markdown
11
+
12
+ # hydopt-client
13
+
14
+ Python client for the [HydOpt](https://hydopt.io) hydropower optimization API.
15
+
16
+ ## Install
17
+
18
+ ```bash
19
+ uv add hydopt-client
20
+ ```
21
+
22
+ ## Authentication
23
+
24
+ Authenticate with Google Cloud:
25
+
26
+ ```bash
27
+ gcloud auth application-default login
28
+ ```
29
+
30
+ ## Quick Start
31
+
32
+ ```python
33
+ from hydopt_client.client import Client
34
+
35
+ client = Client()
36
+
37
+ # List available partition dates
38
+ dates = client.list_partitions()
39
+ print(dates) # ["2026-01-01", "2026-01-02", ...]
40
+
41
+ # Fetch a time series
42
+ records = client.series(dates[0], "production")
43
+ for record in records:
44
+ print(record.name, record.x[0], record.y[0])
45
+
46
+ # Filter and group results
47
+ from hydopt_client.client import Filters, GroupBy
48
+
49
+ filtered = client.series(
50
+ dates[0],
51
+ "production",
52
+ filters=Filters(country=["norway"]),
53
+ group_by=[GroupBy.region],
54
+ )
55
+ ```
56
+
57
+ ## Available Methods
58
+
59
+ | Method | Description |
60
+ |--------|-------------|
61
+ | `list_partitions()` | List available partition dates |
62
+ | `series(asof, category1, ...)` | Query time-series data |
63
+ | `diff(category1, from, to, ...)` | Compare two partitions |
64
+ | `static(category1, ...)` | Query static dataset |
65
+ | `realized(category1, ...)` | Query realized dataset |
66
+ | `catchments(asof)` | Fetch catchment geometries |
67
+ | `orders(asof)` | Fetch energy orders |
68
+ | `object_report(source, target)` | Compare two partition objects |
@@ -0,0 +1,57 @@
1
+ # hydopt-client
2
+
3
+ Python client for the [HydOpt](https://hydopt.io) hydropower optimization API.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ uv add hydopt-client
9
+ ```
10
+
11
+ ## Authentication
12
+
13
+ Authenticate with Google Cloud:
14
+
15
+ ```bash
16
+ gcloud auth application-default login
17
+ ```
18
+
19
+ ## Quick Start
20
+
21
+ ```python
22
+ from hydopt_client.client import Client
23
+
24
+ client = Client()
25
+
26
+ # List available partition dates
27
+ dates = client.list_partitions()
28
+ print(dates) # ["2026-01-01", "2026-01-02", ...]
29
+
30
+ # Fetch a time series
31
+ records = client.series(dates[0], "production")
32
+ for record in records:
33
+ print(record.name, record.x[0], record.y[0])
34
+
35
+ # Filter and group results
36
+ from hydopt_client.client import Filters, GroupBy
37
+
38
+ filtered = client.series(
39
+ dates[0],
40
+ "production",
41
+ filters=Filters(country=["norway"]),
42
+ group_by=[GroupBy.region],
43
+ )
44
+ ```
45
+
46
+ ## Available Methods
47
+
48
+ | Method | Description |
49
+ |--------|-------------|
50
+ | `list_partitions()` | List available partition dates |
51
+ | `series(asof, category1, ...)` | Query time-series data |
52
+ | `diff(category1, from, to, ...)` | Compare two partitions |
53
+ | `static(category1, ...)` | Query static dataset |
54
+ | `realized(category1, ...)` | Query realized dataset |
55
+ | `catchments(asof)` | Fetch catchment geometries |
56
+ | `orders(asof)` | Fetch energy orders |
57
+ | `object_report(source, target)` | Compare two partition objects |
@@ -0,0 +1,15 @@
1
+ name: hydopt-api
2
+
3
+ services:
4
+ api:
5
+ image: us-central1-docker.pkg.dev/hydopt/hydopt-backend/hydopt-api:20260817T143154-066d541
6
+ ports:
7
+ - "${PORT:-8083}:8083"
8
+ environment:
9
+ MODE: testing
10
+ WITH_AUTH: "0"
11
+ healthcheck:
12
+ test: ["CMD", "curl", "-sf", "http://localhost:8083/healthz"]
13
+ interval: 5s
14
+ timeout: 5s
15
+ retries: 12
@@ -0,0 +1,31 @@
1
+ [project]
2
+ name = "hydopt-client"
3
+ dynamic = ["version"]
4
+ description = "Python client for the HydOpt hydropower optimization API"
5
+ readme = "README.md"
6
+ requires-python = ">=3.13"
7
+ dependencies = [
8
+ "google-auth>=2.56.3",
9
+ "httpx>=0.28.1",
10
+ "pydantic>=2.13.4",
11
+ "requests>=2.34.2",
12
+ ]
13
+
14
+ [tool.hatch.version]
15
+ source = "uv-dynamic-versioning"
16
+
17
+ [tool.hatch.build.targets.wheel]
18
+ packages = ["src/hydopt_client"]
19
+
20
+ [tool.uv]
21
+ dev-dependencies = [
22
+ "pytest>=8.3",
23
+ "ruff>=0.11",
24
+ ]
25
+
26
+ [tool.pytest.ini_options]
27
+ testpaths = ["tests"]
28
+
29
+ [build-system]
30
+ requires = ["hatchling", "uv-dynamic-versioning"]
31
+ build-backend = "hatchling.build"
@@ -0,0 +1,3 @@
1
+ from importlib.metadata import version
2
+
3
+ __version__ = version("hydopt-client")
@@ -0,0 +1,17 @@
1
+ from google.auth.transport import requests as google_requests
2
+ from google.oauth2 import id_token
3
+
4
+ SERVER_URL = "https://hydopt-api-131385138719.us-central1.run.app"
5
+ AUDIENCE = "131385138719-463u6bbculfbqd491e2falsocsdr0rca.apps.googleusercontent.com"
6
+
7
+
8
+ class TokenProvider:
9
+ def __init__(
10
+ self,
11
+ audience: str | None = None,
12
+ ) -> None:
13
+ self.audience = audience or AUDIENCE
14
+
15
+ def get_token(self) -> str:
16
+ request = google_requests.Request()
17
+ return id_token.fetch_id_token(request, self.audience)