dex-connector-openweathermap 0.1.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.
- dex_connector_openweathermap-0.1.0/.gitignore +6 -0
- dex_connector_openweathermap-0.1.0/PKG-INFO +49 -0
- dex_connector_openweathermap-0.1.0/README.md +38 -0
- dex_connector_openweathermap-0.1.0/examples/demo/__init__.py +3 -0
- dex_connector_openweathermap-0.1.0/examples/demo/flow.py +79 -0
- dex_connector_openweathermap-0.1.0/examples/demo/worker.py +51 -0
- dex_connector_openweathermap-0.1.0/pyproject.toml +37 -0
- dex_connector_openweathermap-0.1.0/src/dex_connectors/openweathermap/__init__.py +50 -0
- dex_connector_openweathermap-0.1.0/src/dex_connectors/openweathermap/_generated/__init__.py +2 -0
- dex_connector_openweathermap-0.1.0/src/dex_connectors/openweathermap/_generated/config.py +25 -0
- dex_connector_openweathermap-0.1.0/src/dex_connectors/openweathermap/_generated/connection.py +137 -0
- dex_connector_openweathermap-0.1.0/src/dex_connectors/openweathermap/_generated/definitions.py +57 -0
- dex_connector_openweathermap-0.1.0/src/dex_connectors/openweathermap/_generated/mock.py +119 -0
- dex_connector_openweathermap-0.1.0/src/dex_connectors/openweathermap/_generated/models.py +70 -0
- dex_connector_openweathermap-0.1.0/src/dex_connectors/openweathermap/_generated/steps.py +134 -0
- dex_connector_openweathermap-0.1.0/src/dex_connectors/openweathermap/client.py +335 -0
- dex_connector_openweathermap-0.1.0/src/dex_connectors/openweathermap/connection.py +45 -0
- dex_connector_openweathermap-0.1.0/src/dex_connectors/openweathermap/dex-connector.json +87 -0
- dex_connector_openweathermap-0.1.0/src/dex_connectors/openweathermap/models.py +24 -0
- dex_connector_openweathermap-0.1.0/src/dex_connectors/openweathermap/openweathermapmock/__init__.py +55 -0
- dex_connector_openweathermap-0.1.0/src/dex_connectors/openweathermap/py.typed +0 -0
- dex_connector_openweathermap-0.1.0/src/dex_connectors/openweathermap/steps.py +34 -0
- dex_connector_openweathermap-0.1.0/tests/test_conformance.py +45 -0
- dex_connector_openweathermap-0.1.0/tests/test_manifest_contract.py +15 -0
- dex_connector_openweathermap-0.1.0/tests/test_operations.py +160 -0
- dex_connector_openweathermap-0.1.0/uv.lock +932 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: dex-connector-openweathermap
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: OpenWeatherMap connector for Dex Flows
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Requires-Python: >=3.11
|
|
7
|
+
Requires-Dist: dex-connectors-sdk==0.1.0
|
|
8
|
+
Requires-Dist: dex-python-sdk>=1.28.0
|
|
9
|
+
Requires-Dist: httpx>=0.27
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
|
|
12
|
+
# OpenWeatherMap connector for Python
|
|
13
|
+
|
|
14
|
+
Install with `pip install dex-connector-openweathermap==0.1.0`. The package
|
|
15
|
+
requires `dex-connectors-sdk==0.1.0` and `dex-python-sdk>=1.28.0`, and
|
|
16
|
+
implements the manifest Queries `getCurrentWeather` and `getForecast` with the
|
|
17
|
+
same branches, defaults, and failure classification as the Go module.
|
|
18
|
+
|
|
19
|
+
## Operations
|
|
20
|
+
|
|
21
|
+
| Operation | Factory | Happy branch | Optional branches |
|
|
22
|
+
| --- | --- | --- | --- |
|
|
23
|
+
| `getCurrentWeather` | `new_get_current_weather_step` | `found` | `notFound`, `providerRejected`, `invalidResponse`, `defect` |
|
|
24
|
+
| `getForecast` | `new_get_forecast_step` | `found` | `notFound`, `providerRejected`, `invalidResponse`, `defect` |
|
|
25
|
+
|
|
26
|
+
Both take a latitude from -90 to 90 and a longitude from -180 to 180 in decimal
|
|
27
|
+
degrees, plus `units` of `standard` (the default, kelvin), `metric`, or
|
|
28
|
+
`imperial`. HTTP 404 selects `notFound`; 408, 429, 5xx, and transport failures
|
|
29
|
+
retry; other non-200 responses select `providerRejected`.
|
|
30
|
+
|
|
31
|
+
## Authorization
|
|
32
|
+
|
|
33
|
+
Create a Dex Web connection named `openweathermap` as described in the
|
|
34
|
+
[connector README](../README.md#authorization-and-configuration).
|
|
35
|
+
OpenWeatherMap accepts the API key only as the `appid` query parameter, so the
|
|
36
|
+
key is part of each request URL; it is resolved for every attempt.
|
|
37
|
+
|
|
38
|
+
## Example
|
|
39
|
+
|
|
40
|
+
[`examples/demo`](examples/demo/flow.py) reads the current weather for a
|
|
41
|
+
coordinate and records it. Run the Worker with
|
|
42
|
+
`uv run python -m examples.demo.worker` after `dexcli dev` has loaded a project
|
|
43
|
+
containing the `openweathermap` connection.
|
|
44
|
+
|
|
45
|
+
## Tests
|
|
46
|
+
|
|
47
|
+
`openweathermapmock.Mock` scripts both Queries and defaults to the manifest
|
|
48
|
+
answers. Run `uv run pytest tests` for provider parity and manifest contract
|
|
49
|
+
checks.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# OpenWeatherMap connector for Python
|
|
2
|
+
|
|
3
|
+
Install with `pip install dex-connector-openweathermap==0.1.0`. The package
|
|
4
|
+
requires `dex-connectors-sdk==0.1.0` and `dex-python-sdk>=1.28.0`, and
|
|
5
|
+
implements the manifest Queries `getCurrentWeather` and `getForecast` with the
|
|
6
|
+
same branches, defaults, and failure classification as the Go module.
|
|
7
|
+
|
|
8
|
+
## Operations
|
|
9
|
+
|
|
10
|
+
| Operation | Factory | Happy branch | Optional branches |
|
|
11
|
+
| --- | --- | --- | --- |
|
|
12
|
+
| `getCurrentWeather` | `new_get_current_weather_step` | `found` | `notFound`, `providerRejected`, `invalidResponse`, `defect` |
|
|
13
|
+
| `getForecast` | `new_get_forecast_step` | `found` | `notFound`, `providerRejected`, `invalidResponse`, `defect` |
|
|
14
|
+
|
|
15
|
+
Both take a latitude from -90 to 90 and a longitude from -180 to 180 in decimal
|
|
16
|
+
degrees, plus `units` of `standard` (the default, kelvin), `metric`, or
|
|
17
|
+
`imperial`. HTTP 404 selects `notFound`; 408, 429, 5xx, and transport failures
|
|
18
|
+
retry; other non-200 responses select `providerRejected`.
|
|
19
|
+
|
|
20
|
+
## Authorization
|
|
21
|
+
|
|
22
|
+
Create a Dex Web connection named `openweathermap` as described in the
|
|
23
|
+
[connector README](../README.md#authorization-and-configuration).
|
|
24
|
+
OpenWeatherMap accepts the API key only as the `appid` query parameter, so the
|
|
25
|
+
key is part of each request URL; it is resolved for every attempt.
|
|
26
|
+
|
|
27
|
+
## Example
|
|
28
|
+
|
|
29
|
+
[`examples/demo`](examples/demo/flow.py) reads the current weather for a
|
|
30
|
+
coordinate and records it. Run the Worker with
|
|
31
|
+
`uv run python -m examples.demo.worker` after `dexcli dev` has loaded a project
|
|
32
|
+
containing the `openweathermap` connection.
|
|
33
|
+
|
|
34
|
+
## Tests
|
|
35
|
+
|
|
36
|
+
`openweathermapmock.Mock` scripts both Queries and defaults to the manifest
|
|
37
|
+
answers. Run `uv run pytest tests` for provider parity and manifest contract
|
|
38
|
+
checks.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Runnable OpenWeatherMap demo Flow using the getCurrentWeather Query."""
|
|
4
|
+
|
|
5
|
+
import dex
|
|
6
|
+
from dex_connectors.sdk import QueryResult
|
|
7
|
+
|
|
8
|
+
from dex_connectors.openweathermap import (
|
|
9
|
+
Connection,
|
|
10
|
+
CurrentWeatherOutput,
|
|
11
|
+
WeatherInput,
|
|
12
|
+
new_get_current_weather_step,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
FLOW_TYPE = "OpenWeatherMapDemo"
|
|
16
|
+
CONNECTION_NAME = "openweathermap"
|
|
17
|
+
_OPERATION_STEP_TYPE = "CallGetCurrentWeather"
|
|
18
|
+
_OUTCOME = dex.Attribute("openweathermap-demo-outcome", CurrentWeatherOutput)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def map_to_operation_input(input: WeatherInput) -> WeatherInput:
|
|
22
|
+
"""Read the requested coordinate unchanged."""
|
|
23
|
+
return input
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# dex:group group-id:demo group-label:"Demo"
|
|
27
|
+
# dex:explanation text:"Start the weather lookup with the requested coordinate."
|
|
28
|
+
class _StartRequest(dex.Step[WeatherInput]):
|
|
29
|
+
def get_step_type(self) -> str:
|
|
30
|
+
return "StartGetCurrentWeather"
|
|
31
|
+
|
|
32
|
+
def execute(self, context: dex.Context, input: WeatherInput) -> dex.StepDecision:
|
|
33
|
+
return dex.go_to(dex.StepRef(_OPERATION_STEP_TYPE), input)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# dex:group group-id:demo group-label:"Demo"
|
|
37
|
+
# dex:explanation text:"Record the current weather and complete the Flow."
|
|
38
|
+
class _CompleteResult(dex.Step[QueryResult[CurrentWeatherOutput]]):
|
|
39
|
+
def get_step_type(self) -> str:
|
|
40
|
+
return "CompleteGetCurrentWeather"
|
|
41
|
+
|
|
42
|
+
def execute(self, context: dex.Context, input: QueryResult[CurrentWeatherOutput]) -> dex.StepDecision:
|
|
43
|
+
_OUTCOME.set(context, input.value)
|
|
44
|
+
return dex.graceful_complete(input.value)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class DemoFlow(dex.Flow[WeatherInput]):
|
|
48
|
+
"""Read current weather through the static openweathermap connection."""
|
|
49
|
+
|
|
50
|
+
def __init__(self, connection: Connection) -> None:
|
|
51
|
+
if connection.reference.name != CONNECTION_NAME:
|
|
52
|
+
raise ValueError("demo requires the static openweathermap connection")
|
|
53
|
+
self._start = _StartRequest()
|
|
54
|
+
self._complete = _CompleteResult()
|
|
55
|
+
self._read = new_get_current_weather_step(
|
|
56
|
+
step_type=_OPERATION_STEP_TYPE,
|
|
57
|
+
step_input_type=WeatherInput,
|
|
58
|
+
annotations={
|
|
59
|
+
"groupId": "provider",
|
|
60
|
+
"groupLabel": "OpenWeatherMap",
|
|
61
|
+
"explanation": "Call the provider's getCurrentWeather operation.",
|
|
62
|
+
},
|
|
63
|
+
connection=connection,
|
|
64
|
+
connection_name=CONNECTION_NAME,
|
|
65
|
+
map_to_operation_input=map_to_operation_input,
|
|
66
|
+
found=self._complete,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
def get_flow_type(self) -> str:
|
|
70
|
+
"""Return the stable Flow identity used in Dex Web."""
|
|
71
|
+
return FLOW_TYPE
|
|
72
|
+
|
|
73
|
+
def get_steps(self) -> dex.StepList[WeatherInput]:
|
|
74
|
+
"""Register the start, provider read, and completion Steps."""
|
|
75
|
+
return dex.StepList.start_step(self._start).other_steps(self._read, self._complete)
|
|
76
|
+
|
|
77
|
+
def get_persistence_schema(self) -> dex.PersistenceSchema:
|
|
78
|
+
"""Persist the current weather outcome."""
|
|
79
|
+
return dex.PersistenceSchema.of(_OUTCOME)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Worker entrypoint for the OpenWeatherMap demo Flow."""
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import os
|
|
7
|
+
import tempfile
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
import dex
|
|
11
|
+
from dex_connectors.sdk.projectconfig import load_from_environment
|
|
12
|
+
|
|
13
|
+
from dex_connectors.openweathermap import new_project_connection
|
|
14
|
+
|
|
15
|
+
from .flow import CONNECTION_NAME, DemoFlow
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
async def run_worker() -> None:
|
|
19
|
+
"""Load the named Dex Web connection and serve weather lookups."""
|
|
20
|
+
project = await load_from_environment()
|
|
21
|
+
connection = None
|
|
22
|
+
cache = None
|
|
23
|
+
try:
|
|
24
|
+
connection = new_project_connection(project, CONNECTION_NAME)
|
|
25
|
+
registry = dex.Registry([DemoFlow(connection)], allow_async_handlers=True)
|
|
26
|
+
cache_directory = os.environ.get(
|
|
27
|
+
"DEX_BLOB_CACHE_DIR", str(Path(tempfile.gettempdir()) / "dex-openweathermap-demo-blobs")
|
|
28
|
+
)
|
|
29
|
+
cache = dex.open_blob_cache(dex.BlobCacheConfig(cache_directory, 1 << 30))
|
|
30
|
+
worker = dex.AsyncWorker(
|
|
31
|
+
registry,
|
|
32
|
+
cache,
|
|
33
|
+
dex.WorkerOptions(server_address=os.environ.get("DEX_FLOW_SERVICE_ADDRESS", "localhost:8801")),
|
|
34
|
+
)
|
|
35
|
+
async with worker:
|
|
36
|
+
await worker.start()
|
|
37
|
+
finally:
|
|
38
|
+
if connection is not None:
|
|
39
|
+
await connection.aclose()
|
|
40
|
+
if cache is not None:
|
|
41
|
+
cache.close()
|
|
42
|
+
await project.close()
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def main() -> None:
|
|
46
|
+
"""Run until the Worker stops or the process receives an interrupt."""
|
|
47
|
+
asyncio.run(run_worker())
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
if __name__ == "__main__":
|
|
51
|
+
main()
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "dex-connector-openweathermap"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "OpenWeatherMap connector for Dex Flows"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
dependencies = ["dex-connectors-sdk==0.1.0", "dex-python-sdk>=1.28.0", "httpx>=0.27"]
|
|
13
|
+
|
|
14
|
+
[dependency-groups]
|
|
15
|
+
dev = ["pytest>=8", "pytest-asyncio>=0.24", "mypy>=1.13", "ruff>=0.7", "pyyaml>=6", "types-PyYAML>=6"]
|
|
16
|
+
|
|
17
|
+
[tool.hatch.build.targets.wheel]
|
|
18
|
+
packages = ["src/dex_connectors"]
|
|
19
|
+
|
|
20
|
+
[tool.pytest.ini_options]
|
|
21
|
+
testpaths = ["tests"]
|
|
22
|
+
pythonpath = [".", "src"]
|
|
23
|
+
asyncio_mode = "auto"
|
|
24
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
25
|
+
|
|
26
|
+
[tool.mypy]
|
|
27
|
+
python_version = "3.11"
|
|
28
|
+
strict = true
|
|
29
|
+
mypy_path = "src"
|
|
30
|
+
explicit_package_bases = true
|
|
31
|
+
|
|
32
|
+
[tool.ruff]
|
|
33
|
+
target-version = "py311"
|
|
34
|
+
line-length = 110
|
|
35
|
+
|
|
36
|
+
[tool.ruff.lint]
|
|
37
|
+
select = ["E", "F", "I", "UP", "B"]
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""OpenWeatherMap weather Queries for Dex connector Steps."""
|
|
4
|
+
|
|
5
|
+
from .client import (
|
|
6
|
+
CONNECTOR_ID,
|
|
7
|
+
DEFECT,
|
|
8
|
+
FOUND,
|
|
9
|
+
GET_CURRENT_WEATHER_DEFINITION,
|
|
10
|
+
GET_FORECAST_DEFINITION,
|
|
11
|
+
INVALID_RESPONSE,
|
|
12
|
+
NOT_FOUND,
|
|
13
|
+
PROVIDER_REJECTED,
|
|
14
|
+
UNITS,
|
|
15
|
+
Client,
|
|
16
|
+
Config,
|
|
17
|
+
Credentials,
|
|
18
|
+
GetCurrentWeatherOperation,
|
|
19
|
+
GetForecastOperation,
|
|
20
|
+
)
|
|
21
|
+
from .connection import Connection, new_connection, new_connection_with_operations, new_project_connection
|
|
22
|
+
from .models import CurrentWeatherOutput, ForecastEntry, ForecastOutput, WeatherInput
|
|
23
|
+
from .steps import new_get_current_weather_step, new_get_forecast_step
|
|
24
|
+
|
|
25
|
+
__all__ = [
|
|
26
|
+
"Client",
|
|
27
|
+
"Config",
|
|
28
|
+
"Connection",
|
|
29
|
+
"Credentials",
|
|
30
|
+
"CurrentWeatherOutput",
|
|
31
|
+
"ForecastEntry",
|
|
32
|
+
"ForecastOutput",
|
|
33
|
+
"GetCurrentWeatherOperation",
|
|
34
|
+
"GetForecastOperation",
|
|
35
|
+
"WeatherInput",
|
|
36
|
+
"new_connection",
|
|
37
|
+
"new_connection_with_operations",
|
|
38
|
+
"new_get_current_weather_step",
|
|
39
|
+
"new_get_forecast_step",
|
|
40
|
+
"new_project_connection",
|
|
41
|
+
"CONNECTOR_ID",
|
|
42
|
+
"DEFECT",
|
|
43
|
+
"FOUND",
|
|
44
|
+
"GET_CURRENT_WEATHER_DEFINITION",
|
|
45
|
+
"GET_FORECAST_DEFINITION",
|
|
46
|
+
"INVALID_RESPONSE",
|
|
47
|
+
"NOT_FOUND",
|
|
48
|
+
"PROVIDER_REJECTED",
|
|
49
|
+
"UNITS",
|
|
50
|
+
]
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
from dex_connectors.sdk import SecretString
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass(frozen=True, slots=True)
|
|
11
|
+
class Config:
|
|
12
|
+
|
|
13
|
+
base_url: str = "https://api.openweathermap.org"
|
|
14
|
+
timeout_seconds: float = 15
|
|
15
|
+
max_response_bytes: int = 1048576
|
|
16
|
+
|
|
17
|
+
setattr(Config, '__module__', 'dex_connectors.openweathermap.client')
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True, slots=True)
|
|
21
|
+
class Credentials:
|
|
22
|
+
|
|
23
|
+
api_key: SecretString
|
|
24
|
+
|
|
25
|
+
setattr(Credentials, '__module__', 'dex_connectors.openweathermap.client')
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
import httpx
|
|
8
|
+
from dex_connectors.sdk import ConnectionRef, Query, Call, SecretString
|
|
9
|
+
from dex_connectors.sdk.projectconfig import ConnectionKey, LoadedProject
|
|
10
|
+
|
|
11
|
+
from ..client import Client, Config, Credentials
|
|
12
|
+
from .definitions import CONNECTOR_ID, GET_CURRENT_WEATHER_DEFINITION, GET_FORECAST_DEFINITION
|
|
13
|
+
from ..models import CurrentWeatherOutput, ForecastOutput, WeatherInput
|
|
14
|
+
|
|
15
|
+
class Connection:
|
|
16
|
+
|
|
17
|
+
__slots__ = ('_get_current_weather', '_get_forecast', '_client', 'reference')
|
|
18
|
+
|
|
19
|
+
def __init__(self,
|
|
20
|
+
reference: ConnectionRef,
|
|
21
|
+
get_current_weather: Query[WeatherInput, CurrentWeatherOutput],
|
|
22
|
+
get_forecast: Query[WeatherInput, ForecastOutput],
|
|
23
|
+
client: Client | None = None,
|
|
24
|
+
) -> None:
|
|
25
|
+
reference.validate()
|
|
26
|
+
if reference.provider != CONNECTOR_ID or get_current_weather is None or get_forecast is None:
|
|
27
|
+
raise ValueError("OpenWeatherMap connection provider and operations are required")
|
|
28
|
+
if get_current_weather.definition().operation != GET_CURRENT_WEATHER_DEFINITION.operation:
|
|
29
|
+
raise ValueError("OpenWeatherMap connection operation identity differs")
|
|
30
|
+
if get_forecast.definition().operation != GET_FORECAST_DEFINITION.operation:
|
|
31
|
+
raise ValueError("OpenWeatherMap connection operation identity differs")
|
|
32
|
+
self.reference = reference
|
|
33
|
+
self._get_current_weather = get_current_weather
|
|
34
|
+
self._get_forecast = get_forecast
|
|
35
|
+
self._client = client
|
|
36
|
+
|
|
37
|
+
def get_current_weather(self) -> Query[WeatherInput, CurrentWeatherOutput]:
|
|
38
|
+
return self._get_current_weather
|
|
39
|
+
|
|
40
|
+
def get_forecast(self) -> Query[WeatherInput, ForecastOutput]:
|
|
41
|
+
return self._get_forecast
|
|
42
|
+
|
|
43
|
+
async def aclose(self) -> None:
|
|
44
|
+
if self._client is not None:
|
|
45
|
+
await self._client.aclose()
|
|
46
|
+
|
|
47
|
+
def __repr__(self) -> str:
|
|
48
|
+
return "openweathermap.Connection([REDACTED])"
|
|
49
|
+
|
|
50
|
+
def __reduce__(self) -> tuple[object, ...]:
|
|
51
|
+
raise TypeError("OpenWeatherMap connections cannot be serialized")
|
|
52
|
+
|
|
53
|
+
setattr(Connection, '__module__', 'dex_connectors.openweathermap.connection')
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def new_connection(client: Client, reference: ConnectionRef) -> Connection:
|
|
57
|
+
if client is None:
|
|
58
|
+
raise ValueError("OpenWeatherMap client is required")
|
|
59
|
+
return Connection(reference, client.get_current_weather(), client.get_forecast(), client)
|
|
60
|
+
|
|
61
|
+
setattr(new_connection, '__module__', 'dex_connectors.openweathermap.connection')
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def new_connection_with_operations(
|
|
65
|
+
get_current_weather: Query[WeatherInput, CurrentWeatherOutput],
|
|
66
|
+
get_forecast: Query[WeatherInput, ForecastOutput],
|
|
67
|
+
reference: ConnectionRef,
|
|
68
|
+
) -> Connection:
|
|
69
|
+
return Connection(reference, get_current_weather, get_forecast)
|
|
70
|
+
|
|
71
|
+
setattr(new_connection_with_operations, '__module__', 'dex_connectors.openweathermap.connection')
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class _ProjectCredentialSource:
|
|
75
|
+
|
|
76
|
+
def __init__(self, project: LoadedProject, key: ConnectionKey) -> None:
|
|
77
|
+
self.project = project
|
|
78
|
+
self.key = key
|
|
79
|
+
|
|
80
|
+
async def resolve(self, call: Call) -> Credentials:
|
|
81
|
+
material = await self.project.resolve_credential(self.key, str(call.id))
|
|
82
|
+
if not isinstance(material, dict):
|
|
83
|
+
raise ValueError("OpenWeatherMap stored credential does not match the connector credential fields")
|
|
84
|
+
if set(material) - set(('api_key',)):
|
|
85
|
+
raise ValueError("OpenWeatherMap stored credential does not match the connector credential fields")
|
|
86
|
+
api_key = material.get("api_key")
|
|
87
|
+
if api_key is not None and not (isinstance(api_key, str)):
|
|
88
|
+
raise ValueError("OpenWeatherMap credential api_key has an invalid type")
|
|
89
|
+
if not api_key:
|
|
90
|
+
raise ValueError("OpenWeatherMap credential api_key is required")
|
|
91
|
+
return Credentials(SecretString(api_key))
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def new_project_connection(
|
|
95
|
+
project: LoadedProject, connection_name: str, http_client: httpx.AsyncClient | None = None
|
|
96
|
+
) -> Connection:
|
|
97
|
+
if project is None:
|
|
98
|
+
raise ValueError("OpenWeatherMap connection requires loaded project configuration")
|
|
99
|
+
reference = ConnectionRef(CONNECTOR_ID, connection_name)
|
|
100
|
+
reference.validate()
|
|
101
|
+
key = ConnectionKey(CONNECTOR_ID, connection_name)
|
|
102
|
+
matching = [
|
|
103
|
+
entry
|
|
104
|
+
for entry in project.configuration.connections
|
|
105
|
+
if entry.connector_id == CONNECTOR_ID and entry.connection_name == connection_name
|
|
106
|
+
]
|
|
107
|
+
if len(matching) != 1:
|
|
108
|
+
raise ValueError("OpenWeatherMap project connection is missing or duplicated")
|
|
109
|
+
if matching[0].provider != CONNECTOR_ID:
|
|
110
|
+
raise ValueError("OpenWeatherMap project connection provider differs")
|
|
111
|
+
config = _decode_config(matching[0].configuration)
|
|
112
|
+
client = Client(config, _ProjectCredentialSource(project, key), http_client)
|
|
113
|
+
return new_connection(client, reference)
|
|
114
|
+
|
|
115
|
+
setattr(new_project_connection, '__module__', 'dex_connectors.openweathermap.connection')
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _decode_config(value: dict[str, Any]) -> Config:
|
|
119
|
+
if set(value) - {"baseUrl", "timeout", "maxResponseBytes"}:
|
|
120
|
+
raise ValueError("OpenWeatherMap configuration has unknown fields")
|
|
121
|
+
config_arguments: dict[str, Any] = {}
|
|
122
|
+
if "baseUrl" in value:
|
|
123
|
+
base_url = value["baseUrl"]
|
|
124
|
+
if not (isinstance(base_url, str)):
|
|
125
|
+
raise ValueError("OpenWeatherMap configuration baseUrl has an invalid type")
|
|
126
|
+
config_arguments['base_url'] = base_url
|
|
127
|
+
if "timeout" in value:
|
|
128
|
+
timeout = value["timeout"]
|
|
129
|
+
if not (type(timeout) is int):
|
|
130
|
+
raise ValueError("OpenWeatherMap configuration timeout has an invalid type")
|
|
131
|
+
config_arguments['timeout_seconds'] = timeout / 1_000_000_000
|
|
132
|
+
if "maxResponseBytes" in value:
|
|
133
|
+
max_response_bytes = value["maxResponseBytes"]
|
|
134
|
+
if not (type(max_response_bytes) is int):
|
|
135
|
+
raise ValueError("OpenWeatherMap configuration maxResponseBytes has an invalid type")
|
|
136
|
+
config_arguments['max_response_bytes'] = max_response_bytes
|
|
137
|
+
return Config(**config_arguments)
|
dex_connector_openweathermap-0.1.0/src/dex_connectors/openweathermap/_generated/definitions.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from datetime import timedelta
|
|
6
|
+
|
|
7
|
+
from dex_connectors.sdk import (
|
|
8
|
+
BranchDefinition,
|
|
9
|
+
MutationDefinition,
|
|
10
|
+
OperationRef,
|
|
11
|
+
QueryDefinition,
|
|
12
|
+
RetryPolicy,
|
|
13
|
+
StepDefaults,
|
|
14
|
+
default_connector_step_execute_retry_policy,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
CONNECTOR_ID = "openweathermap"
|
|
18
|
+
PROVIDER = "openweathermap"
|
|
19
|
+
GET_CURRENT_WEATHER_OPERATION_ID = "getCurrentWeather"
|
|
20
|
+
GET_FORECAST_OPERATION_ID = "getForecast"
|
|
21
|
+
DEFECT = "defect"
|
|
22
|
+
FOUND = "found"
|
|
23
|
+
INVALID_RESPONSE = "invalidResponse"
|
|
24
|
+
NOT_FOUND = "notFound"
|
|
25
|
+
PROVIDER_REJECTED = "providerRejected"
|
|
26
|
+
|
|
27
|
+
GET_CURRENT_WEATHER_DEFINITION = QueryDefinition(
|
|
28
|
+
OperationRef(CONNECTOR_ID, GET_CURRENT_WEATHER_OPERATION_ID),
|
|
29
|
+
(
|
|
30
|
+
BranchDefinition(FOUND, "OpenWeatherMap returned the requested result.", False),
|
|
31
|
+
BranchDefinition(NOT_FOUND, "The requested coordinates have no weather data.", True),
|
|
32
|
+
BranchDefinition(PROVIDER_REJECTED, "The provider conclusively rejected the request.", True),
|
|
33
|
+
BranchDefinition(INVALID_RESPONSE, "The provider returned malformed or oversized data.", True),
|
|
34
|
+
BranchDefinition(DEFECT, "Local input or credentials are invalid.", True),
|
|
35
|
+
),
|
|
36
|
+
StepDefaults(
|
|
37
|
+
timedelta(seconds=30),
|
|
38
|
+
2,
|
|
39
|
+
execute_retry=default_connector_step_execute_retry_policy(),
|
|
40
|
+
),
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
GET_FORECAST_DEFINITION = QueryDefinition(
|
|
44
|
+
OperationRef(CONNECTOR_ID, GET_FORECAST_OPERATION_ID),
|
|
45
|
+
(
|
|
46
|
+
BranchDefinition(FOUND, "OpenWeatherMap returned the requested result.", False),
|
|
47
|
+
BranchDefinition(NOT_FOUND, "The requested coordinates have no weather data.", True),
|
|
48
|
+
BranchDefinition(PROVIDER_REJECTED, "The provider conclusively rejected the request.", True),
|
|
49
|
+
BranchDefinition(INVALID_RESPONSE, "The provider returned malformed or oversized data.", True),
|
|
50
|
+
BranchDefinition(DEFECT, "Local input or credentials are invalid.", True),
|
|
51
|
+
),
|
|
52
|
+
StepDefaults(
|
|
53
|
+
timedelta(seconds=30),
|
|
54
|
+
2,
|
|
55
|
+
execute_retry=default_connector_step_execute_retry_policy(),
|
|
56
|
+
),
|
|
57
|
+
)
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
|
|
7
|
+
from dex_connectors.sdk import ConnectionRef, Failure, FailureKind
|
|
8
|
+
from dex_connectors.sdk.connectormock import Case, Query
|
|
9
|
+
|
|
10
|
+
from ..connection import Connection, new_connection_with_operations
|
|
11
|
+
from ..models import CurrentWeatherOutput, ForecastEntry, ForecastOutput, WeatherInput
|
|
12
|
+
from .definitions import CONNECTOR_ID, DEFECT, FOUND, GET_CURRENT_WEATHER_DEFINITION, GET_FORECAST_DEFINITION, INVALID_RESPONSE, NOT_FOUND, PROVIDER_REJECTED
|
|
13
|
+
|
|
14
|
+
def get_current_weather_found(value: CurrentWeatherOutput, failure: Failure | None = None) -> Case[CurrentWeatherOutput]:
|
|
15
|
+
return Case.branch_result(FOUND, value, failure)
|
|
16
|
+
|
|
17
|
+
setattr(get_current_weather_found, '__module__', "dex_connectors.openweathermap.openweathermapmock")
|
|
18
|
+
|
|
19
|
+
def get_current_weather_not_found(value: CurrentWeatherOutput, failure: Failure | None = None) -> Case[CurrentWeatherOutput]:
|
|
20
|
+
return Case.branch_result(NOT_FOUND, value, failure)
|
|
21
|
+
|
|
22
|
+
setattr(get_current_weather_not_found, '__module__', "dex_connectors.openweathermap.openweathermapmock")
|
|
23
|
+
|
|
24
|
+
def get_current_weather_provider_rejected(value: CurrentWeatherOutput, failure: Failure | None = None) -> Case[CurrentWeatherOutput]:
|
|
25
|
+
return Case.branch_result(PROVIDER_REJECTED, value, failure)
|
|
26
|
+
|
|
27
|
+
setattr(get_current_weather_provider_rejected, '__module__', "dex_connectors.openweathermap.openweathermapmock")
|
|
28
|
+
|
|
29
|
+
def get_current_weather_invalid_response(value: CurrentWeatherOutput, failure: Failure | None = None) -> Case[CurrentWeatherOutput]:
|
|
30
|
+
return Case.branch_result(INVALID_RESPONSE, value, failure)
|
|
31
|
+
|
|
32
|
+
setattr(get_current_weather_invalid_response, '__module__', "dex_connectors.openweathermap.openweathermapmock")
|
|
33
|
+
|
|
34
|
+
def get_current_weather_defect(value: CurrentWeatherOutput, failure: Failure | None = None) -> Case[CurrentWeatherOutput]:
|
|
35
|
+
return Case.branch_result(DEFECT, value, failure)
|
|
36
|
+
|
|
37
|
+
setattr(get_current_weather_defect, '__module__', "dex_connectors.openweathermap.openweathermapmock")
|
|
38
|
+
|
|
39
|
+
def get_current_weather_retry(failure: Failure, after_seconds: float = 0) -> Case[CurrentWeatherOutput]:
|
|
40
|
+
return Case.retry(failure, after_seconds)
|
|
41
|
+
|
|
42
|
+
setattr(get_current_weather_retry, '__module__', "dex_connectors.openweathermap.openweathermapmock")
|
|
43
|
+
|
|
44
|
+
def get_current_weather_found_default() -> Case[CurrentWeatherOutput]:
|
|
45
|
+
return Case.branch_result(FOUND, CurrentWeatherOutput(city='Meridian', temperature=21.5, description='clear sky'))
|
|
46
|
+
|
|
47
|
+
setattr(get_current_weather_found_default, '__module__', "dex_connectors.openweathermap.openweathermapmock")
|
|
48
|
+
|
|
49
|
+
def get_forecast_found(value: ForecastOutput, failure: Failure | None = None) -> Case[ForecastOutput]:
|
|
50
|
+
return Case.branch_result(FOUND, value, failure)
|
|
51
|
+
|
|
52
|
+
setattr(get_forecast_found, '__module__', "dex_connectors.openweathermap.openweathermapmock")
|
|
53
|
+
|
|
54
|
+
def get_forecast_not_found(value: ForecastOutput, failure: Failure | None = None) -> Case[ForecastOutput]:
|
|
55
|
+
return Case.branch_result(NOT_FOUND, value, failure)
|
|
56
|
+
|
|
57
|
+
setattr(get_forecast_not_found, '__module__', "dex_connectors.openweathermap.openweathermapmock")
|
|
58
|
+
|
|
59
|
+
def get_forecast_provider_rejected(value: ForecastOutput, failure: Failure | None = None) -> Case[ForecastOutput]:
|
|
60
|
+
return Case.branch_result(PROVIDER_REJECTED, value, failure)
|
|
61
|
+
|
|
62
|
+
setattr(get_forecast_provider_rejected, '__module__', "dex_connectors.openweathermap.openweathermapmock")
|
|
63
|
+
|
|
64
|
+
def get_forecast_invalid_response(value: ForecastOutput, failure: Failure | None = None) -> Case[ForecastOutput]:
|
|
65
|
+
return Case.branch_result(INVALID_RESPONSE, value, failure)
|
|
66
|
+
|
|
67
|
+
setattr(get_forecast_invalid_response, '__module__', "dex_connectors.openweathermap.openweathermapmock")
|
|
68
|
+
|
|
69
|
+
def get_forecast_defect(value: ForecastOutput, failure: Failure | None = None) -> Case[ForecastOutput]:
|
|
70
|
+
return Case.branch_result(DEFECT, value, failure)
|
|
71
|
+
|
|
72
|
+
setattr(get_forecast_defect, '__module__', "dex_connectors.openweathermap.openweathermapmock")
|
|
73
|
+
|
|
74
|
+
def get_forecast_retry(failure: Failure, after_seconds: float = 0) -> Case[ForecastOutput]:
|
|
75
|
+
return Case.retry(failure, after_seconds)
|
|
76
|
+
|
|
77
|
+
setattr(get_forecast_retry, '__module__', "dex_connectors.openweathermap.openweathermapmock")
|
|
78
|
+
|
|
79
|
+
def get_forecast_found_default() -> Case[ForecastOutput]:
|
|
80
|
+
return Case.branch_result(FOUND, ForecastOutput(city='Meridian', entries=(ForecastEntry(timestamp=1793210400, temperature=20.1),)))
|
|
81
|
+
|
|
82
|
+
setattr(get_forecast_found_default, '__module__', "dex_connectors.openweathermap.openweathermapmock")
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class Mock:
|
|
86
|
+
|
|
87
|
+
def __init__(self, connection_name: str = "openweathermap") -> None:
|
|
88
|
+
self.get_current_weather_script: Query[WeatherInput, CurrentWeatherOutput] = Query(GET_CURRENT_WEATHER_DEFINITION)
|
|
89
|
+
self.get_current_weather_script.default(get_current_weather_found_default())
|
|
90
|
+
self.get_forecast_script: Query[WeatherInput, ForecastOutput] = Query(GET_FORECAST_DEFINITION)
|
|
91
|
+
self.get_forecast_script.default(get_forecast_found_default())
|
|
92
|
+
self._connection = new_connection_with_operations(
|
|
93
|
+
get_current_weather=self.get_current_weather_script,
|
|
94
|
+
get_forecast=self.get_forecast_script,
|
|
95
|
+
reference=ConnectionRef(CONNECTOR_ID, connection_name),
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
def connection(self) -> Connection:
|
|
99
|
+
return self._connection
|
|
100
|
+
|
|
101
|
+
setattr(Mock, '__module__', "dex_connectors.openweathermap.openweathermapmock")
|
|
102
|
+
|
|
103
|
+
__all__ = [
|
|
104
|
+
"Mock",
|
|
105
|
+
"get_current_weather_found",
|
|
106
|
+
"get_current_weather_not_found",
|
|
107
|
+
"get_current_weather_provider_rejected",
|
|
108
|
+
"get_current_weather_invalid_response",
|
|
109
|
+
"get_current_weather_defect",
|
|
110
|
+
"get_current_weather_retry",
|
|
111
|
+
"get_current_weather_found_default",
|
|
112
|
+
"get_forecast_found",
|
|
113
|
+
"get_forecast_not_found",
|
|
114
|
+
"get_forecast_provider_rejected",
|
|
115
|
+
"get_forecast_invalid_response",
|
|
116
|
+
"get_forecast_defect",
|
|
117
|
+
"get_forecast_retry",
|
|
118
|
+
"get_forecast_found_default",
|
|
119
|
+
]
|