pd4castr-api-sdk 0.0.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.
- pd4castr_api_sdk-0.0.0/.gitignore +71 -0
- pd4castr_api_sdk-0.0.0/LICENSE.md +21 -0
- pd4castr_api_sdk-0.0.0/PKG-INFO +338 -0
- pd4castr_api_sdk-0.0.0/README.md +299 -0
- pd4castr_api_sdk-0.0.0/docs/assets/logo.png +0 -0
- pd4castr_api_sdk-0.0.0/pyproject.toml +60 -0
- pd4castr_api_sdk-0.0.0/src/pd4castr_api_sdk/__init__.py +13 -0
- pd4castr_api_sdk-0.0.0/src/pd4castr_api_sdk/auth.py +69 -0
- pd4castr_api_sdk-0.0.0/src/pd4castr_api_sdk/client.py +123 -0
- pd4castr_api_sdk-0.0.0/src/pd4castr_api_sdk/config.py +29 -0
- pd4castr_api_sdk-0.0.0/src/pd4castr_api_sdk/errors.py +27 -0
- pd4castr_api_sdk-0.0.0/src/pd4castr_api_sdk/models.py +83 -0
- pd4castr_api_sdk-0.0.0/src/pd4castr_api_sdk/py.typed +1 -0
- pd4castr_api_sdk-0.0.0/src/pd4castr_api_sdk/transport.py +48 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# temp & system files
|
|
2
|
+
.DS_Store
|
|
3
|
+
.temp
|
|
4
|
+
.tmp
|
|
5
|
+
|
|
6
|
+
# compiled - dependencies & build artifacts
|
|
7
|
+
dist
|
|
8
|
+
node_modules
|
|
9
|
+
/.pnp
|
|
10
|
+
.pnp.js
|
|
11
|
+
.yarn/install-state.gz
|
|
12
|
+
|
|
13
|
+
# logs
|
|
14
|
+
logs
|
|
15
|
+
*.log
|
|
16
|
+
npm-debug.log*
|
|
17
|
+
pnpm-debug.log*
|
|
18
|
+
yarn-debug.log*
|
|
19
|
+
yarn-error.log*
|
|
20
|
+
lerna-debug.log*
|
|
21
|
+
|
|
22
|
+
# our debugging output
|
|
23
|
+
sql-debug
|
|
24
|
+
profile.json
|
|
25
|
+
|
|
26
|
+
# test runners
|
|
27
|
+
/coverage
|
|
28
|
+
/.nyc_output
|
|
29
|
+
|
|
30
|
+
# IDEs and editors
|
|
31
|
+
/.idea
|
|
32
|
+
.project
|
|
33
|
+
.classpath
|
|
34
|
+
.c9/
|
|
35
|
+
*.launch
|
|
36
|
+
.settings/
|
|
37
|
+
*.sublime-workspace
|
|
38
|
+
|
|
39
|
+
# IDE - VSCode
|
|
40
|
+
.vscode/*
|
|
41
|
+
!.vscode/settings.json
|
|
42
|
+
!.vscode/tasks.json
|
|
43
|
+
!.vscode/launch.json
|
|
44
|
+
!.vscode/extensions.json
|
|
45
|
+
|
|
46
|
+
# next.js
|
|
47
|
+
.next/
|
|
48
|
+
out/
|
|
49
|
+
next-env.d.ts
|
|
50
|
+
|
|
51
|
+
# pulumi
|
|
52
|
+
.pulumi
|
|
53
|
+
|
|
54
|
+
# cursor agent files
|
|
55
|
+
todo.md
|
|
56
|
+
memory.md
|
|
57
|
+
|
|
58
|
+
# secrets
|
|
59
|
+
.env*
|
|
60
|
+
*.pem
|
|
61
|
+
|
|
62
|
+
# development environment
|
|
63
|
+
dev-volumes/registry-auth/*
|
|
64
|
+
dev-volumes/registry-data/*
|
|
65
|
+
|
|
66
|
+
# python
|
|
67
|
+
.venv*
|
|
68
|
+
__pycache__/
|
|
69
|
+
.pytest_cache/
|
|
70
|
+
.mypy_cache/
|
|
71
|
+
.ruff_cache/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Endgame Economics Pty Ltd t/as Endgame Analytics
|
|
4
|
+
<contact@endgameanalytics.com.au> https://endgameanalytics.com.au
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
7
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
8
|
+
the Software without restriction, including without limitation the rights to
|
|
9
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
10
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
11
|
+
subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
18
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
19
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
20
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
21
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pd4castr-api-sdk
|
|
3
|
+
Version: 0.0.0
|
|
4
|
+
Summary: Python client for the pd4castr API
|
|
5
|
+
Author: pd4castr
|
|
6
|
+
License: MIT License (MIT)
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 Endgame Economics Pty Ltd t/as Endgame Analytics
|
|
9
|
+
<contact@endgameanalytics.com.au> https://endgameanalytics.com.au
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
12
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
13
|
+
the Software without restriction, including without limitation the rights to
|
|
14
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
15
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
16
|
+
subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
23
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
24
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
25
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
26
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
27
|
+
License-File: LICENSE.md
|
|
28
|
+
Requires-Python: >=3.11
|
|
29
|
+
Requires-Dist: httpx>=0.27.2
|
|
30
|
+
Requires-Dist: pydantic>=2.7.0
|
|
31
|
+
Provides-Extra: dev
|
|
32
|
+
Requires-Dist: mypy>=1.11.0; extra == 'dev'
|
|
33
|
+
Requires-Dist: pytest-cov>=5.0.0; extra == 'dev'
|
|
34
|
+
Requires-Dist: pytest-sugar>=1.0.0; extra == 'dev'
|
|
35
|
+
Requires-Dist: pytest>=8.2.0; extra == 'dev'
|
|
36
|
+
Requires-Dist: respx>=0.21.1; extra == 'dev'
|
|
37
|
+
Requires-Dist: ruff>=0.6.0; extra == 'dev'
|
|
38
|
+
Description-Content-Type: text/markdown
|
|
39
|
+
|
|
40
|
+
<div align="center">
|
|
41
|
+
<img src="./docs/assets/logo.png" alt="pdView logo" width="92">
|
|
42
|
+
|
|
43
|
+
<h1>pd4castr API SDK</h1>
|
|
44
|
+
|
|
45
|
+
<p>Official Python client for the pd4castr API</p>
|
|
46
|
+
|
|
47
|
+
<p>
|
|
48
|
+
<a href="#installation">Installation</a> •
|
|
49
|
+
<a href="#quick-start">Quick Start</a> •
|
|
50
|
+
<a href="#usage">Usage</a> •
|
|
51
|
+
<a href="#api-reference">API Reference</a>
|
|
52
|
+
</p>
|
|
53
|
+
</div>
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## Installation
|
|
58
|
+
|
|
59
|
+
> Requires Python >= 3.8
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pip install pd4castr-api-sdk
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Quick Start
|
|
66
|
+
|
|
67
|
+
Authenticate using your [pd4castr](https://v2.pd4castr.com.au) API credentials:
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from pd4castr_api_sdk import Client
|
|
71
|
+
|
|
72
|
+
client = Client(
|
|
73
|
+
client_id="my-client-id",
|
|
74
|
+
client_secret="my-client-secret",
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
models = client.get_models()
|
|
78
|
+
print(f"Found {len(models)} models")
|
|
79
|
+
|
|
80
|
+
client.close()
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Context Manager
|
|
84
|
+
|
|
85
|
+
The client implements context manager protocol for automatic cleanup:
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
with Client(
|
|
89
|
+
client_id="my-client-id",
|
|
90
|
+
client_secret="my-client-secret",
|
|
91
|
+
) as client:
|
|
92
|
+
models = client.get_models()
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Usage
|
|
96
|
+
|
|
97
|
+
### List all Models
|
|
98
|
+
|
|
99
|
+
[Reference: `Client.getModels`](#get_models)
|
|
100
|
+
|
|
101
|
+
Retrieve all available models, optionally filtered by time horizon.
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
# Get all models
|
|
105
|
+
models = client.get_models()
|
|
106
|
+
|
|
107
|
+
# Filter by time horizon
|
|
108
|
+
models = client.get_models(time_horizon="day_ahead")
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Get a Model
|
|
112
|
+
|
|
113
|
+
[Reference: `Client.get_model`](#clientgetmodel)
|
|
114
|
+
|
|
115
|
+
Retrieve detailed information for a specific model.
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
model = client.get_model("model-id")
|
|
119
|
+
print(f"Model: {model.displayName}")
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Get Current User
|
|
123
|
+
|
|
124
|
+
[Reference: `Client.get_current_user`](#clientgetcurrentuser)
|
|
125
|
+
|
|
126
|
+
Retrieve information about the currently authenticated user.
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
user = client.get_current_user()
|
|
130
|
+
print(f"User: {user.email}")
|
|
131
|
+
if user.organisation:
|
|
132
|
+
print(f"Organisation: {user.organisation.displayName}")
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Error Handling
|
|
136
|
+
|
|
137
|
+
[Reference: Exceptions](#exceptions)
|
|
138
|
+
|
|
139
|
+
Handle common error cases with typed exceptions.
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
from pd4castr_api_sdk import NotFoundError, ApiError
|
|
143
|
+
|
|
144
|
+
try:
|
|
145
|
+
model = client.get_model("invalid-id")
|
|
146
|
+
except NotFoundError:
|
|
147
|
+
print("Model not found")
|
|
148
|
+
except ApiError as e:
|
|
149
|
+
print(f"API error {e.status_code}: {e.message}")
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## API Reference
|
|
153
|
+
|
|
154
|
+
**Client:**
|
|
155
|
+
|
|
156
|
+
- [`Client`](#client) - Main API client
|
|
157
|
+
- [`Client#getModels`](#clientgetmodels) - List all models
|
|
158
|
+
- [`Client#getModel`](#clientgetmodel) - Get a specific model
|
|
159
|
+
- [`Client#getCurrentUser`](#clientgetcurrentuser) - Get the current user
|
|
160
|
+
|
|
161
|
+
**Types:**
|
|
162
|
+
|
|
163
|
+
- [`Model`](#model) - Model information and related types
|
|
164
|
+
- [`User`](#user) - User information and related types
|
|
165
|
+
|
|
166
|
+
**Exceptions:**
|
|
167
|
+
|
|
168
|
+
- [`ApiError`](#apierror) - Base API error
|
|
169
|
+
- [`NotFoundError`](#notfounderror) - Resource not found error
|
|
170
|
+
|
|
171
|
+
### `Client`
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
Client(
|
|
175
|
+
client_id: str,
|
|
176
|
+
client_secret: str,
|
|
177
|
+
timeout: float = 30.0,
|
|
178
|
+
)
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Main client class for interacting with the pd4castr API. Supports context
|
|
182
|
+
manager protocol for automatic cleanup.
|
|
183
|
+
|
|
184
|
+
**Configuration:**
|
|
185
|
+
|
|
186
|
+
- `client_id` - OAuth client ID for authentication
|
|
187
|
+
- `client_secret` - OAuth client secret for authentication
|
|
188
|
+
- `timeout` - Request timeout in seconds (default: 30.0)
|
|
189
|
+
|
|
190
|
+
### `Client#getModels`
|
|
191
|
+
|
|
192
|
+
List all models with optional time horizon filter.
|
|
193
|
+
|
|
194
|
+
`Client#getModels(*, time_horizon: str | None = None) -> list[`[`Model`](#model)`]`
|
|
195
|
+
|
|
196
|
+
**Parameters:**
|
|
197
|
+
|
|
198
|
+
- `time_horizon` (optional) - Filter models by time horizon:
|
|
199
|
+
- `day_ahead`
|
|
200
|
+
- `week_ahead`
|
|
201
|
+
- `quarterly`
|
|
202
|
+
- `historical`
|
|
203
|
+
|
|
204
|
+
**Returns:** A list of [`Model`](#model) instances
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
### `Client#getModel`
|
|
209
|
+
|
|
210
|
+
Get a specific model by ID.
|
|
211
|
+
|
|
212
|
+
`Client#get_model(model_id: str) ->`[`Model`](#model)
|
|
213
|
+
|
|
214
|
+
**Parameters:**
|
|
215
|
+
|
|
216
|
+
- `model_id` - Unique model identifier
|
|
217
|
+
|
|
218
|
+
**Returns:** [`Model`](#model) instance
|
|
219
|
+
|
|
220
|
+
**Raises:**
|
|
221
|
+
|
|
222
|
+
- [`NotFoundError`](#notfounderror) if model doesn't exist
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
### `Client#getCurrentUser`
|
|
227
|
+
|
|
228
|
+
Get the currently authenticated user.
|
|
229
|
+
|
|
230
|
+
`Client#get_current_user() ->`[`User`](#user)
|
|
231
|
+
|
|
232
|
+
**Returns:** [`User`](#user) instance
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
### Types
|
|
237
|
+
|
|
238
|
+
All types are implemented as
|
|
239
|
+
[pydantic models](https://docs.pydantic.dev/latest/).
|
|
240
|
+
|
|
241
|
+
#### `Model`
|
|
242
|
+
|
|
243
|
+
```python
|
|
244
|
+
class Model(BaseModel):
|
|
245
|
+
id: str
|
|
246
|
+
modelGroupId: str
|
|
247
|
+
name: str
|
|
248
|
+
displayName: str
|
|
249
|
+
displayTimezone: str
|
|
250
|
+
revision: int
|
|
251
|
+
dockerImage: str
|
|
252
|
+
notes: str
|
|
253
|
+
createdAt: str
|
|
254
|
+
horizon: TimeHorizon
|
|
255
|
+
modelMetadata: ModelMetadata
|
|
256
|
+
outputSpecification: list[ColumnSpecification]
|
|
257
|
+
tags: list[str]
|
|
258
|
+
sensitivities: list[SensitivitySpecification]
|
|
259
|
+
outputFileFormat: FileFormat
|
|
260
|
+
forecastVariable: ForecastVariableSpecification
|
|
261
|
+
|
|
262
|
+
class TimeHorizon(BaseModel):
|
|
263
|
+
name: str
|
|
264
|
+
shortName: str
|
|
265
|
+
key: str
|
|
266
|
+
|
|
267
|
+
class ModelMetadata(BaseModel):
|
|
268
|
+
description: str | None
|
|
269
|
+
releaseDate: str | None
|
|
270
|
+
resolution: str | None
|
|
271
|
+
baseComparisonModel: str | None
|
|
272
|
+
|
|
273
|
+
class ColumnSpecification(BaseModel):
|
|
274
|
+
name: str
|
|
275
|
+
type: str
|
|
276
|
+
ui: UISpecification | None
|
|
277
|
+
|
|
278
|
+
class UISpecification(BaseModel):
|
|
279
|
+
seriesKey: bool | None
|
|
280
|
+
colours: list[str] | None
|
|
281
|
+
|
|
282
|
+
class SensitivitySpecification(BaseModel):
|
|
283
|
+
name: str
|
|
284
|
+
categories: list[str]
|
|
285
|
+
|
|
286
|
+
class ForecastVariableSpecification(BaseModel):
|
|
287
|
+
name: str
|
|
288
|
+
shortName: str
|
|
289
|
+
key: str
|
|
290
|
+
|
|
291
|
+
class FileFormat(Enum):
|
|
292
|
+
json = "json"
|
|
293
|
+
csv = "csv"
|
|
294
|
+
parquet = "parquet"
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
#### `User`
|
|
298
|
+
|
|
299
|
+
```python
|
|
300
|
+
class User(BaseModel):
|
|
301
|
+
id: str
|
|
302
|
+
email: str
|
|
303
|
+
organisation: Organisation | None
|
|
304
|
+
|
|
305
|
+
class Organisation(BaseModel):
|
|
306
|
+
id: str
|
|
307
|
+
displayName: str
|
|
308
|
+
slug: str
|
|
309
|
+
domains: list[str]
|
|
310
|
+
permissions: list[str]
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
### Exceptions
|
|
314
|
+
|
|
315
|
+
#### `ApiError`
|
|
316
|
+
|
|
317
|
+
Base exception for API errors.
|
|
318
|
+
|
|
319
|
+
```python
|
|
320
|
+
class ApiError(Exception):
|
|
321
|
+
status_code: int
|
|
322
|
+
message: str
|
|
323
|
+
body: dict | None
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
#### `NotFoundError`
|
|
327
|
+
|
|
328
|
+
Resource not found error (HTTP 404). Inherits from [`ApiError`](#apierror).
|
|
329
|
+
|
|
330
|
+
```python
|
|
331
|
+
class NotFoundError(ApiError):
|
|
332
|
+
pass
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
## Contributing
|
|
336
|
+
|
|
337
|
+
See [CONTRIBUTING.md](./CONTRIBUTING.md) for development setup, testing, and
|
|
338
|
+
contribution guidelines.
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="./docs/assets/logo.png" alt="pdView logo" width="92">
|
|
3
|
+
|
|
4
|
+
<h1>pd4castr API SDK</h1>
|
|
5
|
+
|
|
6
|
+
<p>Official Python client for the pd4castr API</p>
|
|
7
|
+
|
|
8
|
+
<p>
|
|
9
|
+
<a href="#installation">Installation</a> •
|
|
10
|
+
<a href="#quick-start">Quick Start</a> •
|
|
11
|
+
<a href="#usage">Usage</a> •
|
|
12
|
+
<a href="#api-reference">API Reference</a>
|
|
13
|
+
</p>
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
> Requires Python >= 3.8
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install pd4castr-api-sdk
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
Authenticate using your [pd4castr](https://v2.pd4castr.com.au) API credentials:
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from pd4castr_api_sdk import Client
|
|
32
|
+
|
|
33
|
+
client = Client(
|
|
34
|
+
client_id="my-client-id",
|
|
35
|
+
client_secret="my-client-secret",
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
models = client.get_models()
|
|
39
|
+
print(f"Found {len(models)} models")
|
|
40
|
+
|
|
41
|
+
client.close()
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Context Manager
|
|
45
|
+
|
|
46
|
+
The client implements context manager protocol for automatic cleanup:
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
with Client(
|
|
50
|
+
client_id="my-client-id",
|
|
51
|
+
client_secret="my-client-secret",
|
|
52
|
+
) as client:
|
|
53
|
+
models = client.get_models()
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Usage
|
|
57
|
+
|
|
58
|
+
### List all Models
|
|
59
|
+
|
|
60
|
+
[Reference: `Client.getModels`](#get_models)
|
|
61
|
+
|
|
62
|
+
Retrieve all available models, optionally filtered by time horizon.
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
# Get all models
|
|
66
|
+
models = client.get_models()
|
|
67
|
+
|
|
68
|
+
# Filter by time horizon
|
|
69
|
+
models = client.get_models(time_horizon="day_ahead")
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Get a Model
|
|
73
|
+
|
|
74
|
+
[Reference: `Client.get_model`](#clientgetmodel)
|
|
75
|
+
|
|
76
|
+
Retrieve detailed information for a specific model.
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
model = client.get_model("model-id")
|
|
80
|
+
print(f"Model: {model.displayName}")
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Get Current User
|
|
84
|
+
|
|
85
|
+
[Reference: `Client.get_current_user`](#clientgetcurrentuser)
|
|
86
|
+
|
|
87
|
+
Retrieve information about the currently authenticated user.
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
user = client.get_current_user()
|
|
91
|
+
print(f"User: {user.email}")
|
|
92
|
+
if user.organisation:
|
|
93
|
+
print(f"Organisation: {user.organisation.displayName}")
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Error Handling
|
|
97
|
+
|
|
98
|
+
[Reference: Exceptions](#exceptions)
|
|
99
|
+
|
|
100
|
+
Handle common error cases with typed exceptions.
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from pd4castr_api_sdk import NotFoundError, ApiError
|
|
104
|
+
|
|
105
|
+
try:
|
|
106
|
+
model = client.get_model("invalid-id")
|
|
107
|
+
except NotFoundError:
|
|
108
|
+
print("Model not found")
|
|
109
|
+
except ApiError as e:
|
|
110
|
+
print(f"API error {e.status_code}: {e.message}")
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## API Reference
|
|
114
|
+
|
|
115
|
+
**Client:**
|
|
116
|
+
|
|
117
|
+
- [`Client`](#client) - Main API client
|
|
118
|
+
- [`Client#getModels`](#clientgetmodels) - List all models
|
|
119
|
+
- [`Client#getModel`](#clientgetmodel) - Get a specific model
|
|
120
|
+
- [`Client#getCurrentUser`](#clientgetcurrentuser) - Get the current user
|
|
121
|
+
|
|
122
|
+
**Types:**
|
|
123
|
+
|
|
124
|
+
- [`Model`](#model) - Model information and related types
|
|
125
|
+
- [`User`](#user) - User information and related types
|
|
126
|
+
|
|
127
|
+
**Exceptions:**
|
|
128
|
+
|
|
129
|
+
- [`ApiError`](#apierror) - Base API error
|
|
130
|
+
- [`NotFoundError`](#notfounderror) - Resource not found error
|
|
131
|
+
|
|
132
|
+
### `Client`
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
Client(
|
|
136
|
+
client_id: str,
|
|
137
|
+
client_secret: str,
|
|
138
|
+
timeout: float = 30.0,
|
|
139
|
+
)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Main client class for interacting with the pd4castr API. Supports context
|
|
143
|
+
manager protocol for automatic cleanup.
|
|
144
|
+
|
|
145
|
+
**Configuration:**
|
|
146
|
+
|
|
147
|
+
- `client_id` - OAuth client ID for authentication
|
|
148
|
+
- `client_secret` - OAuth client secret for authentication
|
|
149
|
+
- `timeout` - Request timeout in seconds (default: 30.0)
|
|
150
|
+
|
|
151
|
+
### `Client#getModels`
|
|
152
|
+
|
|
153
|
+
List all models with optional time horizon filter.
|
|
154
|
+
|
|
155
|
+
`Client#getModels(*, time_horizon: str | None = None) -> list[`[`Model`](#model)`]`
|
|
156
|
+
|
|
157
|
+
**Parameters:**
|
|
158
|
+
|
|
159
|
+
- `time_horizon` (optional) - Filter models by time horizon:
|
|
160
|
+
- `day_ahead`
|
|
161
|
+
- `week_ahead`
|
|
162
|
+
- `quarterly`
|
|
163
|
+
- `historical`
|
|
164
|
+
|
|
165
|
+
**Returns:** A list of [`Model`](#model) instances
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
### `Client#getModel`
|
|
170
|
+
|
|
171
|
+
Get a specific model by ID.
|
|
172
|
+
|
|
173
|
+
`Client#get_model(model_id: str) ->`[`Model`](#model)
|
|
174
|
+
|
|
175
|
+
**Parameters:**
|
|
176
|
+
|
|
177
|
+
- `model_id` - Unique model identifier
|
|
178
|
+
|
|
179
|
+
**Returns:** [`Model`](#model) instance
|
|
180
|
+
|
|
181
|
+
**Raises:**
|
|
182
|
+
|
|
183
|
+
- [`NotFoundError`](#notfounderror) if model doesn't exist
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
### `Client#getCurrentUser`
|
|
188
|
+
|
|
189
|
+
Get the currently authenticated user.
|
|
190
|
+
|
|
191
|
+
`Client#get_current_user() ->`[`User`](#user)
|
|
192
|
+
|
|
193
|
+
**Returns:** [`User`](#user) instance
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
### Types
|
|
198
|
+
|
|
199
|
+
All types are implemented as
|
|
200
|
+
[pydantic models](https://docs.pydantic.dev/latest/).
|
|
201
|
+
|
|
202
|
+
#### `Model`
|
|
203
|
+
|
|
204
|
+
```python
|
|
205
|
+
class Model(BaseModel):
|
|
206
|
+
id: str
|
|
207
|
+
modelGroupId: str
|
|
208
|
+
name: str
|
|
209
|
+
displayName: str
|
|
210
|
+
displayTimezone: str
|
|
211
|
+
revision: int
|
|
212
|
+
dockerImage: str
|
|
213
|
+
notes: str
|
|
214
|
+
createdAt: str
|
|
215
|
+
horizon: TimeHorizon
|
|
216
|
+
modelMetadata: ModelMetadata
|
|
217
|
+
outputSpecification: list[ColumnSpecification]
|
|
218
|
+
tags: list[str]
|
|
219
|
+
sensitivities: list[SensitivitySpecification]
|
|
220
|
+
outputFileFormat: FileFormat
|
|
221
|
+
forecastVariable: ForecastVariableSpecification
|
|
222
|
+
|
|
223
|
+
class TimeHorizon(BaseModel):
|
|
224
|
+
name: str
|
|
225
|
+
shortName: str
|
|
226
|
+
key: str
|
|
227
|
+
|
|
228
|
+
class ModelMetadata(BaseModel):
|
|
229
|
+
description: str | None
|
|
230
|
+
releaseDate: str | None
|
|
231
|
+
resolution: str | None
|
|
232
|
+
baseComparisonModel: str | None
|
|
233
|
+
|
|
234
|
+
class ColumnSpecification(BaseModel):
|
|
235
|
+
name: str
|
|
236
|
+
type: str
|
|
237
|
+
ui: UISpecification | None
|
|
238
|
+
|
|
239
|
+
class UISpecification(BaseModel):
|
|
240
|
+
seriesKey: bool | None
|
|
241
|
+
colours: list[str] | None
|
|
242
|
+
|
|
243
|
+
class SensitivitySpecification(BaseModel):
|
|
244
|
+
name: str
|
|
245
|
+
categories: list[str]
|
|
246
|
+
|
|
247
|
+
class ForecastVariableSpecification(BaseModel):
|
|
248
|
+
name: str
|
|
249
|
+
shortName: str
|
|
250
|
+
key: str
|
|
251
|
+
|
|
252
|
+
class FileFormat(Enum):
|
|
253
|
+
json = "json"
|
|
254
|
+
csv = "csv"
|
|
255
|
+
parquet = "parquet"
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
#### `User`
|
|
259
|
+
|
|
260
|
+
```python
|
|
261
|
+
class User(BaseModel):
|
|
262
|
+
id: str
|
|
263
|
+
email: str
|
|
264
|
+
organisation: Organisation | None
|
|
265
|
+
|
|
266
|
+
class Organisation(BaseModel):
|
|
267
|
+
id: str
|
|
268
|
+
displayName: str
|
|
269
|
+
slug: str
|
|
270
|
+
domains: list[str]
|
|
271
|
+
permissions: list[str]
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### Exceptions
|
|
275
|
+
|
|
276
|
+
#### `ApiError`
|
|
277
|
+
|
|
278
|
+
Base exception for API errors.
|
|
279
|
+
|
|
280
|
+
```python
|
|
281
|
+
class ApiError(Exception):
|
|
282
|
+
status_code: int
|
|
283
|
+
message: str
|
|
284
|
+
body: dict | None
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
#### `NotFoundError`
|
|
288
|
+
|
|
289
|
+
Resource not found error (HTTP 404). Inherits from [`ApiError`](#apierror).
|
|
290
|
+
|
|
291
|
+
```python
|
|
292
|
+
class NotFoundError(ApiError):
|
|
293
|
+
pass
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## Contributing
|
|
297
|
+
|
|
298
|
+
See [CONTRIBUTING.md](./CONTRIBUTING.md) for development setup, testing, and
|
|
299
|
+
contribution guidelines.
|
|
Binary file
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27.0"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pd4castr-api-sdk"
|
|
7
|
+
version = "0.0.0"
|
|
8
|
+
description = "Python client for the pd4castr API"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { file = "LICENSE.md" }
|
|
11
|
+
requires-python = ">=3.11"
|
|
12
|
+
authors = [{ name = "pd4castr" }]
|
|
13
|
+
dependencies = [
|
|
14
|
+
"httpx>=0.27.2",
|
|
15
|
+
"pydantic>=2.7.0",
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
[project.optional-dependencies]
|
|
19
|
+
dev = [
|
|
20
|
+
"mypy>=1.11.0",
|
|
21
|
+
"pytest>=8.2.0",
|
|
22
|
+
"pytest-cov>=5.0.0",
|
|
23
|
+
"pytest-sugar>=1.0.0",
|
|
24
|
+
"respx>=0.21.1",
|
|
25
|
+
"ruff>=0.6.0",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[tool.hatch.build.targets.wheel]
|
|
29
|
+
packages = ["src/pd4castr_api_sdk"]
|
|
30
|
+
|
|
31
|
+
[tool.hatch.build]
|
|
32
|
+
include = [
|
|
33
|
+
"src/pd4castr_api_sdk/**",
|
|
34
|
+
"LICENSE.md",
|
|
35
|
+
"docs/assets/**",
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
[tool.ruff]
|
|
39
|
+
target-version = "py311"
|
|
40
|
+
line-length = 88
|
|
41
|
+
|
|
42
|
+
[tool.ruff.lint]
|
|
43
|
+
select = ["E", "F", "I", "UP", "B"]
|
|
44
|
+
|
|
45
|
+
[tool.pytest.ini_options]
|
|
46
|
+
testpaths = ["tests"]
|
|
47
|
+
|
|
48
|
+
[tool.mypy]
|
|
49
|
+
python_version = "3.11"
|
|
50
|
+
strict = true
|
|
51
|
+
warn_unreachable = true
|
|
52
|
+
disallow_any_generics = true
|
|
53
|
+
no_implicit_optional = true
|
|
54
|
+
|
|
55
|
+
[tool.semantic_release]
|
|
56
|
+
tag_format = "python-api-sdk-v{version}"
|
|
57
|
+
version_toml = ["pyproject.toml:project.version"]
|
|
58
|
+
version_variables = ["src/pd4castr_api_sdk/__init__.py:__version__"]
|
|
59
|
+
commit_message = "chore(python-api-sdk): release {version} [skip ci]"
|
|
60
|
+
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import time
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from .errors import AuthenticationError
|
|
8
|
+
from .transport import Transport
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _normalize_auth0_domain(domain: str) -> str:
|
|
12
|
+
if domain.startswith("https://") or domain.startswith("http://"):
|
|
13
|
+
return domain.rstrip("/")
|
|
14
|
+
return f"https://{domain.rstrip('/')}"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass
|
|
18
|
+
class ClientCredentialsAuth:
|
|
19
|
+
auth0_domain: str
|
|
20
|
+
audience: str
|
|
21
|
+
client_id: str
|
|
22
|
+
client_secret: str
|
|
23
|
+
|
|
24
|
+
_access_token: str | None = None
|
|
25
|
+
_expires_at_epoch: float | None = None
|
|
26
|
+
|
|
27
|
+
def get_access_token(self, transport: Transport) -> str:
|
|
28
|
+
if self._access_token and self._expires_at_epoch:
|
|
29
|
+
# refresh a little early to avoid clock skew.
|
|
30
|
+
if time.time() < (self._expires_at_epoch - 10):
|
|
31
|
+
return self._access_token
|
|
32
|
+
|
|
33
|
+
token_url = f"{_normalize_auth0_domain(self.auth0_domain)}/oauth/token"
|
|
34
|
+
|
|
35
|
+
response = transport.request(
|
|
36
|
+
"POST",
|
|
37
|
+
token_url,
|
|
38
|
+
headers={"content-type": "application/x-www-form-urlencoded"},
|
|
39
|
+
data={
|
|
40
|
+
"grant_type": "client_credentials",
|
|
41
|
+
"client_id": self.client_id,
|
|
42
|
+
"client_secret": self.client_secret,
|
|
43
|
+
"audience": self.audience,
|
|
44
|
+
},
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
if response.status_code >= 400:
|
|
48
|
+
raise AuthenticationError(
|
|
49
|
+
f"auth0 token request failed ({response.status_code})"
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
try:
|
|
53
|
+
payload: dict[str, Any] = response.json()
|
|
54
|
+
except Exception as exc: # pragma: no cover
|
|
55
|
+
raise AuthenticationError("auth0 token response was not json") from exc
|
|
56
|
+
|
|
57
|
+
access_token = payload.get("access_token")
|
|
58
|
+
expires_in = payload.get("expires_in")
|
|
59
|
+
|
|
60
|
+
if not isinstance(access_token, str):
|
|
61
|
+
raise AuthenticationError("auth0 token response missing access_token")
|
|
62
|
+
|
|
63
|
+
if not isinstance(expires_in, int):
|
|
64
|
+
raise AuthenticationError("auth0 token response missing expires_in")
|
|
65
|
+
|
|
66
|
+
self._access_token = access_token
|
|
67
|
+
self._expires_at_epoch = time.time() + expires_in
|
|
68
|
+
|
|
69
|
+
return access_token
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
import httpx
|
|
6
|
+
|
|
7
|
+
from .auth import ClientCredentialsAuth
|
|
8
|
+
from .config import (
|
|
9
|
+
DEFAULT_API_URL,
|
|
10
|
+
DEFAULT_AUTH0_AUDIENCE,
|
|
11
|
+
DEFAULT_AUTH0_DOMAIN,
|
|
12
|
+
load_config,
|
|
13
|
+
)
|
|
14
|
+
from .errors import ApiError, NotFoundError
|
|
15
|
+
from .models import Model, User
|
|
16
|
+
from .transport import HttpxSyncTransport, Transport
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _normalize_base_url(base_url: str) -> str:
|
|
20
|
+
return base_url.rstrip("/")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class Client:
|
|
24
|
+
def __init__(
|
|
25
|
+
self,
|
|
26
|
+
*,
|
|
27
|
+
base_url: str | None = None,
|
|
28
|
+
auth0_domain: str | None = None,
|
|
29
|
+
auth0_audience: str | None = None,
|
|
30
|
+
client_id: str,
|
|
31
|
+
client_secret: str,
|
|
32
|
+
timeout: float = 30.0,
|
|
33
|
+
transport: Transport | None = None,
|
|
34
|
+
) -> None:
|
|
35
|
+
config = load_config()
|
|
36
|
+
|
|
37
|
+
resolved_base_url = base_url or config.base_url or DEFAULT_API_URL
|
|
38
|
+
resolved_domain = auth0_domain or config.auth0_domain or DEFAULT_AUTH0_DOMAIN
|
|
39
|
+
resolved_audience = (
|
|
40
|
+
auth0_audience or config.auth0_audience or DEFAULT_AUTH0_AUDIENCE
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
self._base_url = _normalize_base_url(resolved_base_url)
|
|
44
|
+
self._auth = ClientCredentialsAuth(
|
|
45
|
+
auth0_domain=resolved_domain,
|
|
46
|
+
audience=resolved_audience,
|
|
47
|
+
client_id=client_id,
|
|
48
|
+
client_secret=client_secret,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
self._transport = transport or HttpxSyncTransport(
|
|
52
|
+
client=httpx.Client(timeout=timeout)
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
def close(self) -> None:
|
|
56
|
+
self._transport.close()
|
|
57
|
+
|
|
58
|
+
def __enter__(self) -> Client:
|
|
59
|
+
return self
|
|
60
|
+
|
|
61
|
+
def __exit__(self, exc_type: object, exc: object, tb: object) -> None:
|
|
62
|
+
self.close()
|
|
63
|
+
|
|
64
|
+
def get_models(self, *, time_horizon: str | None = None) -> list[Model]:
|
|
65
|
+
params: dict[str, Any] = {}
|
|
66
|
+
if time_horizon is not None:
|
|
67
|
+
params["timeHorizon"] = time_horizon
|
|
68
|
+
|
|
69
|
+
data = self._request_json("GET", "/model", params=params)
|
|
70
|
+
return [Model.model_validate(item) for item in data]
|
|
71
|
+
|
|
72
|
+
def get_model(self, model_id: str) -> Model:
|
|
73
|
+
data = self._request_json("GET", f"/model/{model_id}")
|
|
74
|
+
return Model.model_validate(data)
|
|
75
|
+
|
|
76
|
+
def get_current_user(self) -> User:
|
|
77
|
+
data = self._request_json("GET", "/user/current")
|
|
78
|
+
return User.model_validate(data)
|
|
79
|
+
|
|
80
|
+
def _request_json(
|
|
81
|
+
self,
|
|
82
|
+
method: str,
|
|
83
|
+
path: str,
|
|
84
|
+
*,
|
|
85
|
+
params: dict[str, Any] | None = None,
|
|
86
|
+
) -> Any:
|
|
87
|
+
url = f"{self._base_url}{path}"
|
|
88
|
+
token = self._auth.get_access_token(self._transport)
|
|
89
|
+
|
|
90
|
+
response = self._transport.request(
|
|
91
|
+
method,
|
|
92
|
+
url,
|
|
93
|
+
headers={
|
|
94
|
+
"authorization": f"Bearer {token}",
|
|
95
|
+
"accept": "application/json",
|
|
96
|
+
},
|
|
97
|
+
params=params,
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
if response.status_code == 404:
|
|
101
|
+
raise NotFoundError("resource not found")
|
|
102
|
+
|
|
103
|
+
if response.status_code >= 400:
|
|
104
|
+
body: Any | None
|
|
105
|
+
try:
|
|
106
|
+
body = response.json()
|
|
107
|
+
except Exception:
|
|
108
|
+
body = response.text
|
|
109
|
+
|
|
110
|
+
raise ApiError(
|
|
111
|
+
status_code=response.status_code,
|
|
112
|
+
message="request failed",
|
|
113
|
+
body=body,
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
try:
|
|
117
|
+
return response.json()
|
|
118
|
+
except ValueError as e:
|
|
119
|
+
raise ApiError(
|
|
120
|
+
status_code=response.status_code,
|
|
121
|
+
message=f"invalid JSON response: {e}",
|
|
122
|
+
body=response.text,
|
|
123
|
+
) from e
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
|
|
6
|
+
DEFAULT_API_URL = "https://api.v2.pd4castr.com.au"
|
|
7
|
+
DEFAULT_AUTH0_DOMAIN = "pdview.au.auth0.com"
|
|
8
|
+
DEFAULT_AUTH0_AUDIENCE = "https://api.pd4castr.com.au"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass(frozen=True)
|
|
12
|
+
class ClientConfig:
|
|
13
|
+
base_url: str
|
|
14
|
+
auth0_domain: str
|
|
15
|
+
auth0_audience: str
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def load_config() -> ClientConfig:
|
|
19
|
+
# allow overrides for advanced usage
|
|
20
|
+
base_url = os.environ.get("PD4CASTR_API_URL", DEFAULT_API_URL)
|
|
21
|
+
audience = os.environ.get("PD4CASTR_AUTH0_AUDIENCE", DEFAULT_AUTH0_AUDIENCE)
|
|
22
|
+
|
|
23
|
+
domain = os.environ.get("PD4CASTR_AUTH0_DOMAIN", DEFAULT_AUTH0_DOMAIN)
|
|
24
|
+
|
|
25
|
+
return ClientConfig(
|
|
26
|
+
base_url=base_url,
|
|
27
|
+
auth0_domain=domain,
|
|
28
|
+
auth0_audience=audience,
|
|
29
|
+
)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Pd4castrApiError(Exception):
|
|
8
|
+
pass
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class AuthenticationError(Pd4castrApiError):
|
|
12
|
+
pass
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class NotFoundError(Pd4castrApiError):
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# exceptions must be mutable so python can attach traceback/cause details
|
|
20
|
+
@dataclass
|
|
21
|
+
class ApiError(Pd4castrApiError):
|
|
22
|
+
status_code: int
|
|
23
|
+
message: str
|
|
24
|
+
body: Any | None = None
|
|
25
|
+
|
|
26
|
+
def __str__(self) -> str: # pragma: no cover
|
|
27
|
+
return f"{self.status_code}: {self.message}"
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from enum import Enum
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel, ConfigDict
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Pd4castrBaseModel(BaseModel):
|
|
9
|
+
model_config = ConfigDict(extra="ignore")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class FileFormat(str, Enum):
|
|
13
|
+
json = "json"
|
|
14
|
+
csv = "csv"
|
|
15
|
+
parquet = "parquet"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class TimeHorizon(Pd4castrBaseModel):
|
|
19
|
+
name: str
|
|
20
|
+
shortName: str
|
|
21
|
+
key: str
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class ModelMetadata(Pd4castrBaseModel):
|
|
25
|
+
description: str | None = None
|
|
26
|
+
releaseDate: str | None = None
|
|
27
|
+
resolution: str | None = None
|
|
28
|
+
baseComparisonModel: str | None = None
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class UISpecification(Pd4castrBaseModel):
|
|
32
|
+
seriesKey: bool | None = None
|
|
33
|
+
colours: list[str] | None = None
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class ColumnSpecification(Pd4castrBaseModel):
|
|
37
|
+
name: str
|
|
38
|
+
type: str
|
|
39
|
+
ui: UISpecification | None = None
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class SensitivitySpecification(Pd4castrBaseModel):
|
|
43
|
+
name: str
|
|
44
|
+
categories: list[str]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class ForecastVariableSpecification(Pd4castrBaseModel):
|
|
48
|
+
name: str
|
|
49
|
+
shortName: str
|
|
50
|
+
key: str
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class Model(Pd4castrBaseModel):
|
|
54
|
+
id: str
|
|
55
|
+
modelGroupId: str
|
|
56
|
+
name: str
|
|
57
|
+
displayName: str
|
|
58
|
+
notes: str
|
|
59
|
+
revision: int
|
|
60
|
+
dockerImage: str
|
|
61
|
+
createdAt: str
|
|
62
|
+
horizon: TimeHorizon
|
|
63
|
+
modelMetadata: ModelMetadata
|
|
64
|
+
outputSpecification: list[ColumnSpecification]
|
|
65
|
+
tags: list[str]
|
|
66
|
+
sensitivities: list[SensitivitySpecification]
|
|
67
|
+
outputFileFormat: FileFormat
|
|
68
|
+
displayTimezone: str
|
|
69
|
+
forecastVariable: ForecastVariableSpecification
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class Organisation(Pd4castrBaseModel):
|
|
73
|
+
id: str
|
|
74
|
+
displayName: str
|
|
75
|
+
slug: str
|
|
76
|
+
domains: list[str]
|
|
77
|
+
permissions: list[str]
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class User(Pd4castrBaseModel):
|
|
81
|
+
id: str
|
|
82
|
+
email: str
|
|
83
|
+
organisation: Organisation | None = None
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Any, Protocol
|
|
5
|
+
|
|
6
|
+
import httpx
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Transport(Protocol):
|
|
10
|
+
def request(
|
|
11
|
+
self,
|
|
12
|
+
method: str,
|
|
13
|
+
url: str,
|
|
14
|
+
*,
|
|
15
|
+
headers: dict[str, str] | None = None,
|
|
16
|
+
params: dict[str, Any] | None = None,
|
|
17
|
+
json: Any | None = None,
|
|
18
|
+
data: Any | None = None,
|
|
19
|
+
) -> httpx.Response: ...
|
|
20
|
+
|
|
21
|
+
def close(self) -> None: ...
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass
|
|
25
|
+
class HttpxSyncTransport:
|
|
26
|
+
client: httpx.Client
|
|
27
|
+
|
|
28
|
+
def request(
|
|
29
|
+
self,
|
|
30
|
+
method: str,
|
|
31
|
+
url: str,
|
|
32
|
+
*,
|
|
33
|
+
headers: dict[str, str] | None = None,
|
|
34
|
+
params: dict[str, Any] | None = None,
|
|
35
|
+
json: Any | None = None,
|
|
36
|
+
data: Any | None = None,
|
|
37
|
+
) -> httpx.Response:
|
|
38
|
+
return self.client.request(
|
|
39
|
+
method,
|
|
40
|
+
url,
|
|
41
|
+
headers=headers,
|
|
42
|
+
params=params,
|
|
43
|
+
json=json,
|
|
44
|
+
data=data,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
def close(self) -> None:
|
|
48
|
+
self.client.close()
|