grawgo 2.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.
grawgo-2.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 GRAW Radiosondes
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.
grawgo-2.0.0/PKG-INFO ADDED
@@ -0,0 +1,25 @@
1
+ Metadata-Version: 2.4
2
+ Name: grawgo
3
+ Version: 2.0.0
4
+ Summary: A python lib to use the grawGo api
5
+ Author-email: Niklas Wildenburg <niklas.wildenburg@graw.de>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/GrawRadiosondes/grawgo-python-api
8
+ Project-URL: Bug Tracker, https://github.com/GrawRadiosondes/grawgo-python-api/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.14
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: requests~=2.34.0
15
+ Dynamic: license-file
16
+
17
+ # grawGo API
18
+
19
+ ## Release
20
+
21
+ 1. `ruff format`
22
+ 2. Bump version in [pyproject.toml](pyproject.toml)
23
+ 3. Commit
24
+ 4. Apply SemVer tag
25
+ 5. Push commit and tag
grawgo-2.0.0/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # grawGo API
2
+
3
+ ## Release
4
+
5
+ 1. `ruff format`
6
+ 2. Bump version in [pyproject.toml](pyproject.toml)
7
+ 3. Commit
8
+ 4. Apply SemVer tag
9
+ 5. Push commit and tag
@@ -0,0 +1,29 @@
1
+ [build-system]
2
+ requires = ["setuptools>=74.1.1"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "grawgo"
7
+ version = "2.0.0"
8
+ description = "A python lib to use the grawGo api"
9
+ readme = "README.md"
10
+ requires-python = ">=3.14"
11
+ license = "MIT"
12
+ authors = [{ name = "Niklas Wildenburg", email = "niklas.wildenburg@graw.de" }]
13
+ classifiers = [
14
+ "Programming Language :: Python :: 3",
15
+ "Operating System :: OS Independent"
16
+ ]
17
+ dependencies = ["requests~=2.34.0"]
18
+
19
+ [dependency-groups]
20
+ "dev" = ["pytest~=9.0.3", "Faker~=40.15.0", "python-dotenv~=1.2.2"]
21
+
22
+ [project.urls]
23
+ "Homepage" = "https://github.com/GrawRadiosondes/grawgo-python-api"
24
+ "Bug Tracker" = "https://github.com/GrawRadiosondes/grawgo-python-api/issues"
25
+
26
+ [tool.pytest.ini_options]
27
+ filterwarnings = [
28
+ "ignore::urllib3.exceptions.InsecureRequestWarning"
29
+ ]
grawgo-2.0.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
File without changes
@@ -0,0 +1,9 @@
1
+ import logging
2
+ from os import getenv
3
+
4
+ logging.basicConfig(
5
+ level=getattr(
6
+ logging, getenv(key="LOG_LEVEL", default="INFO").upper(), logging.INFO
7
+ ),
8
+ format="%(levelname)s: %(message)s",
9
+ )
@@ -0,0 +1,179 @@
1
+ from logging import info
2
+ from typing import Any
3
+ from urllib.parse import urlparse
4
+
5
+ from requests import Response, get, post
6
+
7
+
8
+ class Api:
9
+ def __init__(
10
+ self,
11
+ base_url: str,
12
+ username: str = "",
13
+ password: str = "",
14
+ logging: bool = False,
15
+ ) -> None:
16
+ self.base_url: str = base_url
17
+ self.auth: tuple[str, str] = (username, password)
18
+ self.logging: bool = logging
19
+ self.verify_https: bool = urlparse(self.base_url).hostname != "localhost"
20
+
21
+ def log(self, message: str | dict[str, Any]) -> None:
22
+ if self.logging:
23
+ if isinstance(message, dict) and "password" in message:
24
+ message = {**message, "password": "[REDACTED]"}
25
+
26
+ info(msg=message)
27
+
28
+ def log_response(self, response: Response) -> None:
29
+ if self.logging and not response.ok:
30
+ info(msg=response.status_code)
31
+ info(msg=response.content)
32
+
33
+ def get(self, path: str, authorized: bool = True) -> Response:
34
+ self.log(message=f"GET {self.base_url}/{path}")
35
+
36
+ auth = None
37
+ if authorized:
38
+ auth = self.auth
39
+
40
+ response: Response = get(
41
+ url=f"{self.base_url}/{path}",
42
+ headers={
43
+ "Accept": "application/json",
44
+ },
45
+ auth=auth,
46
+ verify=self.verify_https,
47
+ )
48
+
49
+ self.log_response(response=response)
50
+ return response
51
+
52
+ def post(self, path: str, json: Any) -> Response:
53
+ # TODO: fix for list in json instead of dict
54
+ # sanitized_json: dict[str, Any] = {**json}
55
+ # if "password" in sanitized_json:
56
+ # sanitized_json["password"] = "[REDACTED]"
57
+ # self.log(message=f"POST {self.base_url}/{path} {sanitized_json}")
58
+
59
+ response: Response = post(
60
+ url=f"{self.base_url}/{path}",
61
+ headers={"Accept": "application/json", "Content-Type": "application/json"},
62
+ auth=self.auth,
63
+ json=json,
64
+ verify=self.verify_https,
65
+ )
66
+
67
+ self.log_response(response=response)
68
+ return response
69
+
70
+ def status(self) -> Response:
71
+ return self.get(path="status", authorized=False)
72
+
73
+ def user_self(self) -> Response:
74
+ return self.get(path="user/self")
75
+
76
+ def user_self_stations(self) -> list[Any]:
77
+ return self.user_self().json()["data"]["stations"]
78
+
79
+ def user_self_first_station(self):
80
+ return self.user_self_stations()[0]
81
+
82
+ def create_user(self, email: str, password: str, role: str, name: str) -> Response:
83
+ return self.post(
84
+ path="user",
85
+ json={
86
+ "email": email,
87
+ "password": password,
88
+ "role": role,
89
+ "name": name,
90
+ },
91
+ )
92
+
93
+ def create_station(
94
+ self,
95
+ name: str,
96
+ operation_type: str,
97
+ wmo_id: int,
98
+ latitude: float,
99
+ longitude: float,
100
+ altitude: float,
101
+ ) -> Response:
102
+ return self.post(
103
+ path="station",
104
+ json={
105
+ "name": name,
106
+ "type": operation_type,
107
+ "wmo_id": wmo_id,
108
+ "latitude": latitude,
109
+ "longitude": longitude,
110
+ "altitude": altitude,
111
+ },
112
+ )
113
+
114
+ def create_flight(
115
+ self,
116
+ station_id: int,
117
+ status: str,
118
+ sonde_serial: str,
119
+ set_frequency: float,
120
+ sonde_firmware_version: str,
121
+ ) -> Response:
122
+ return self.post(
123
+ path="flight",
124
+ json={
125
+ "station_id": station_id,
126
+ "status": status,
127
+ "sonde_serial": sonde_serial,
128
+ "set_frequency": set_frequency,
129
+ "sonde_firmware_version": sonde_firmware_version,
130
+ },
131
+ )
132
+
133
+ def create_measurement(
134
+ self,
135
+ flight_id: int,
136
+ time_after_launch: int,
137
+ utc_time: str,
138
+ pressure: float,
139
+ temperature: float,
140
+ humidity: float,
141
+ wind_speed: float,
142
+ wind_direction: float,
143
+ latitude: float,
144
+ longitude: float,
145
+ altitude: float,
146
+ vertical_speed: float,
147
+ geo_potential: float,
148
+ dew_point: float,
149
+ elevation: float,
150
+ azimuth: float,
151
+ distance: float,
152
+ ) -> Response:
153
+ return self.post(
154
+ path="measurement",
155
+ json=[
156
+ {
157
+ "flight_id": flight_id,
158
+ "time_after_launch": time_after_launch,
159
+ "utc_time": utc_time,
160
+ "pressure": pressure,
161
+ "temperature": temperature,
162
+ "humidity": humidity,
163
+ "wind_speed": wind_speed,
164
+ "wind_direction": wind_direction,
165
+ "latitude": latitude,
166
+ "longitude": longitude,
167
+ "altitude": altitude,
168
+ "vertical_speed": vertical_speed,
169
+ "geo_potential": geo_potential,
170
+ "dew_point": dew_point,
171
+ "elevation": elevation,
172
+ "azimuth": azimuth,
173
+ "distance": distance,
174
+ },
175
+ ],
176
+ )
177
+
178
+ def attach_station_to_user(self, user_id: int, station_id: int) -> Response:
179
+ return self.post(path=f"user/{user_id}/attachStation/{station_id}", json={})
File without changes
@@ -0,0 +1,25 @@
1
+ Metadata-Version: 2.4
2
+ Name: grawgo
3
+ Version: 2.0.0
4
+ Summary: A python lib to use the grawGo api
5
+ Author-email: Niklas Wildenburg <niklas.wildenburg@graw.de>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/GrawRadiosondes/grawgo-python-api
8
+ Project-URL: Bug Tracker, https://github.com/GrawRadiosondes/grawgo-python-api/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.14
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: requests~=2.34.0
15
+ Dynamic: license-file
16
+
17
+ # grawGo API
18
+
19
+ ## Release
20
+
21
+ 1. `ruff format`
22
+ 2. Bump version in [pyproject.toml](pyproject.toml)
23
+ 3. Commit
24
+ 4. Apply SemVer tag
25
+ 5. Push commit and tag
@@ -0,0 +1,15 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/__init__.py
5
+ src/grawgo/__init__.py
6
+ src/grawgo/api.py
7
+ src/grawgo/py.typed
8
+ src/grawgo.egg-info/PKG-INFO
9
+ src/grawgo.egg-info/SOURCES.txt
10
+ src/grawgo.egg-info/dependency_links.txt
11
+ src/grawgo.egg-info/requires.txt
12
+ src/grawgo.egg-info/top_level.txt
13
+ tests/test_api_as_admin.py
14
+ tests/test_api_as_api.py
15
+ tests/test_api_as_public.py
@@ -0,0 +1 @@
1
+ requests~=2.34.0
@@ -0,0 +1,2 @@
1
+ __init__
2
+ grawgo
@@ -0,0 +1,71 @@
1
+ import pytest
2
+ from faker import Faker
3
+ from requests import codes
4
+
5
+ from grawgo.api import Api
6
+
7
+
8
+ def test_user_self(api_as_admin: Api):
9
+ assert api_as_admin.user_self().status_code == codes.ok
10
+
11
+
12
+ def test_user_self_stations(api_as_admin: Api):
13
+ assert isinstance(api_as_admin.user_self_stations(), list)
14
+
15
+
16
+ @pytest.mark.parametrize("role", ["admin", "station_admin", "user", "api"])
17
+ def test_create_user(api_as_admin: Api, faker: Faker, role: str):
18
+ assert (
19
+ api_as_admin.create_user(
20
+ faker.email(),
21
+ faker.password(),
22
+ role,
23
+ faker.name(),
24
+ ).status_code
25
+ == codes.created
26
+ )
27
+
28
+
29
+ @pytest.mark.parametrize("type", ["selerys", "operated_fixed", "operated_mobile"])
30
+ def test_create_station(api_as_admin: Api, faker: Faker, type: str):
31
+ assert (
32
+ api_as_admin.create_station(
33
+ faker.name(),
34
+ type,
35
+ faker.random_int(10000, 99999),
36
+ float(faker.latitude()),
37
+ float(faker.longitude()),
38
+ faker.random_int(min=0, max=8848),
39
+ ).status_code
40
+ == codes.created
41
+ )
42
+
43
+
44
+ @pytest.mark.parametrize("role", ["admin", "station_admin", "user", "api"])
45
+ @pytest.mark.parametrize("type", ["selerys", "operated_fixed", "operated_mobile"])
46
+ def test_attach_station_to_user(api_as_admin: Api, faker: Faker, role: str, type: str):
47
+ username = faker.email()
48
+ password = faker.password()
49
+ user = api_as_admin.create_user(username, password, role, faker.name()).json()
50
+ user_api = Api(api_as_admin.base_url, username, password)
51
+
52
+ assert len(user_api.user_self_stations()) == 0
53
+
54
+ station = api_as_admin.create_station(
55
+ faker.name(),
56
+ type,
57
+ faker.random_int(10000, 99999),
58
+ float(faker.latitude()),
59
+ float(faker.longitude()),
60
+ faker.random_int(min=0, max=8848),
61
+ ).json()
62
+ assert (
63
+ api_as_admin.attach_station_to_user(
64
+ user["data"]["id"], station["data"]["id"]
65
+ ).status_code
66
+ == codes.ok
67
+ )
68
+
69
+ stations = user_api.user_self_stations()
70
+ assert len(stations) == 1
71
+ assert station == stations[0]
@@ -0,0 +1,56 @@
1
+ from faker import Faker
2
+ from requests import codes
3
+
4
+ from grawgo.api import Api
5
+
6
+
7
+ def test_user_self(api_as_api: Api):
8
+ assert api_as_api.user_self().status_code == codes.ok
9
+
10
+
11
+ def test_user_self_first_station(api_as_api: Api):
12
+ assert api_as_api.user_self_first_station()
13
+
14
+
15
+ def test_create_flight(api_as_api: Api, faker: Faker):
16
+ assert (
17
+ api_as_api.create_flight(
18
+ station_id=api_as_api.user_self_first_station()["data"]["id"],
19
+ status="created",
20
+ sonde_serial=faker.name(),
21
+ set_frequency=faker.random_int(min=400, max=406),
22
+ sonde_firmware_version=faker.name(),
23
+ ).status_code
24
+ == codes.created
25
+ )
26
+
27
+
28
+ def test_create_measurement(api_as_api: Api, faker: Faker):
29
+ assert (
30
+ api_as_api.create_measurement(
31
+ flight_id=api_as_api.create_flight(
32
+ station_id=api_as_api.user_self_first_station()["data"]["id"],
33
+ status="created",
34
+ sonde_serial=faker.name(),
35
+ set_frequency=faker.random_int(min=400, max=406),
36
+ sonde_firmware_version=faker.name(),
37
+ ).json()["data"]["id"],
38
+ time_after_launch=0,
39
+ utc_time="00:00:00",
40
+ pressure=0,
41
+ temperature=0,
42
+ humidity=0,
43
+ wind_speed=0,
44
+ wind_direction=0,
45
+ latitude=0,
46
+ longitude=0,
47
+ altitude=0,
48
+ vertical_speed=0,
49
+ geo_potential=0,
50
+ dew_point=0,
51
+ elevation=0,
52
+ azimuth=0,
53
+ distance=0,
54
+ ).status_code
55
+ == codes.created
56
+ )
@@ -0,0 +1,7 @@
1
+ from requests import codes
2
+
3
+ from grawgo.api import Api
4
+
5
+
6
+ def test_status(api_as_public: Api):
7
+ assert api_as_public.status().status_code == codes.ok