kystdatahuset-python-lib 0.1.0__tar.gz → 0.9.1__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.
- kystdatahuset_python_lib-0.9.1/PKG-INFO +145 -0
- kystdatahuset_python_lib-0.9.1/README.md +119 -0
- {kystdatahuset_python_lib-0.1.0 → kystdatahuset_python_lib-0.9.1}/pyproject.toml +9 -2
- kystdatahuset_python_lib-0.9.1/src/kystdatahuset/__init__.py +1 -0
- kystdatahuset_python_lib-0.9.1/src/kystdatahuset/ais.py +29 -0
- {kystdatahuset_python_lib-0.1.0 → kystdatahuset_python_lib-0.9.1}/src/kystdatahuset/api_client.py +1 -1
- kystdatahuset_python_lib-0.9.1/src/kystdatahuset/utils/__init__.py +1 -0
- kystdatahuset_python_lib-0.9.1/src/kystdatahuset/utils/_date_range.py +15 -0
- kystdatahuset_python_lib-0.9.1/src/kystdatahuset/voyage.py +28 -0
- kystdatahuset_python_lib-0.9.1/src/kystdatahuset_python_lib.egg-info/PKG-INFO +145 -0
- {kystdatahuset_python_lib-0.1.0 → kystdatahuset_python_lib-0.9.1}/src/kystdatahuset_python_lib.egg-info/SOURCES.txt +6 -3
- kystdatahuset_python_lib-0.9.1/src/kystdatahuset_python_lib.egg-info/requires.txt +6 -0
- kystdatahuset_python_lib-0.9.1/tests/test_ais.py +18 -0
- {kystdatahuset_python_lib-0.1.0 → kystdatahuset_python_lib-0.9.1}/tests/test_file_storage.py +12 -4
- kystdatahuset_python_lib-0.9.1/tests/test_voyage.py +15 -0
- kystdatahuset_python_lib-0.1.0/PKG-INFO +0 -26
- kystdatahuset_python_lib-0.1.0/README.md +0 -3
- kystdatahuset_python_lib-0.1.0/src/kystdatahuset/__init__.py +0 -0
- kystdatahuset_python_lib-0.1.0/src/kystdatahuset/utils/__init__.py +0 -0
- kystdatahuset_python_lib-0.1.0/src/kystdatahuset/utils/date_range.py +0 -14
- kystdatahuset_python_lib-0.1.0/src/kystdatahuset/voyages.py +0 -0
- kystdatahuset_python_lib-0.1.0/src/kystdatahuset_python_lib.egg-info/PKG-INFO +0 -26
- kystdatahuset_python_lib-0.1.0/src/kystdatahuset_python_lib.egg-info/requires.txt +0 -3
- {kystdatahuset_python_lib-0.1.0 → kystdatahuset_python_lib-0.9.1}/LICENSE +0 -0
- {kystdatahuset_python_lib-0.1.0 → kystdatahuset_python_lib-0.9.1}/setup.cfg +0 -0
- {kystdatahuset_python_lib-0.1.0 → kystdatahuset_python_lib-0.9.1}/src/__init__.py +0 -0
- {kystdatahuset_python_lib-0.1.0 → kystdatahuset_python_lib-0.9.1}/src/kystdatahuset/auth.py +0 -0
- {kystdatahuset_python_lib-0.1.0 → kystdatahuset_python_lib-0.9.1}/src/kystdatahuset/const.py +0 -0
- {kystdatahuset_python_lib-0.1.0 → kystdatahuset_python_lib-0.9.1}/src/kystdatahuset/file_storage.py +0 -0
- {kystdatahuset_python_lib-0.1.0 → kystdatahuset_python_lib-0.9.1}/src/kystdatahuset/logging.py +0 -0
- {kystdatahuset_python_lib-0.1.0 → kystdatahuset_python_lib-0.9.1}/src/kystdatahuset/models/AuthData.py +0 -0
- {kystdatahuset_python_lib-0.1.0 → kystdatahuset_python_lib-0.9.1}/src/kystdatahuset/models/FileListing.py +0 -0
- {kystdatahuset_python_lib-0.1.0 → kystdatahuset_python_lib-0.9.1}/src/kystdatahuset/models/WebServiceResponse.py +0 -0
- {kystdatahuset_python_lib-0.1.0 → kystdatahuset_python_lib-0.9.1}/src/kystdatahuset/models/__init__.py +0 -0
- {kystdatahuset_python_lib-0.1.0 → kystdatahuset_python_lib-0.9.1}/src/kystdatahuset/types/PandasFrequency.py +0 -0
- {kystdatahuset_python_lib-0.1.0 → kystdatahuset_python_lib-0.9.1}/src/kystdatahuset/types/UploadFileType.py +0 -0
- {kystdatahuset_python_lib-0.1.0 → kystdatahuset_python_lib-0.9.1}/src/kystdatahuset/types/__init__.py +0 -0
- {kystdatahuset_python_lib-0.1.0 → kystdatahuset_python_lib-0.9.1}/src/kystdatahuset_python_lib.egg-info/dependency_links.txt +0 -0
- {kystdatahuset_python_lib-0.1.0 → kystdatahuset_python_lib-0.9.1}/src/kystdatahuset_python_lib.egg-info/top_level.txt +0 -0
- {kystdatahuset_python_lib-0.1.0 → kystdatahuset_python_lib-0.9.1}/tests/test_auth.py +0 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kystdatahuset-python-lib
|
|
3
|
+
Version: 0.9.1
|
|
4
|
+
Summary: A python library for accessing and querying data from Kystdatahuset
|
|
5
|
+
Author-email: Kystdatahuset developer team <support@kystdatahuset.no>, "(Stein) Runar Bergheim" <runar.bergheim@avinet.no>, Sigve Bergh <sigve.bergh@kystverket.no>, Hermann Klaus Kurt von Lupfert <hermann.lupfert@kystverket.no>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Kystverket/kystdatahuset-python-lib
|
|
8
|
+
Project-URL: Repository, https://github.com/Kystverket/kystdatahuset-python-lib
|
|
9
|
+
Project-URL: Issues, https://github.com/Kystverket/kystdatahuset-python-lib/issues
|
|
10
|
+
Keywords: spatial,analytics,visualization,geodata
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Requires-Python: >=3.10
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: numpy>=1.24
|
|
20
|
+
Requires-Dist: pandas>=2.0
|
|
21
|
+
Requires-Dist: pydantic>=2.0
|
|
22
|
+
Requires-Dist: requests>=2.28
|
|
23
|
+
Requires-Dist: shapely>=2.0
|
|
24
|
+
Requires-Dist: tqdm>=4.65
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# Kystdatahuset Python Library
|
|
28
|
+
|
|
29
|
+
`kystdatahuset-python-lib` — Python SDK companion for the Kystdatahuset API
|
|
30
|
+
|
|
31
|
+
`kystdatahuset-python-lib` is the official Python client for accessing the **Kystdatahuset API**, a unified data and knowledge platform for coastal and maritime spatial analytics.
|
|
32
|
+
|
|
33
|
+
It provides a clean, Pythonic, and strongly typed interface for querying datasets, managing authentication, and performing efficient data access.
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## ✨ Features
|
|
38
|
+
|
|
39
|
+
### 🚀 Easy Installation
|
|
40
|
+
Install directly from PyPI:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pip install kystdatahuset-python-lib
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Supports Python **3.9+** on Linux, macOS, and Windows.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
### 🔐 Simple Authentication
|
|
51
|
+
The client offers:
|
|
52
|
+
|
|
53
|
+
- API key authentication
|
|
54
|
+
- Support for headless servers and notebooks
|
|
55
|
+
|
|
56
|
+
Example:
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from kystdatahuset.auth import login
|
|
60
|
+
import os
|
|
61
|
+
|
|
62
|
+
login_response = login("username", "password")
|
|
63
|
+
jwt = auth_res.data.JWT
|
|
64
|
+
voyages = get_voyages_for_ships_by_mmsi(
|
|
65
|
+
auth_jwt=jwt,
|
|
66
|
+
mmsi_ids=[258090000, 259028000],
|
|
67
|
+
start_date=datetime(2024,1,1),
|
|
68
|
+
end_date=datetime(2024,5,1),
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## 🌍 Efficient & “Social” Data Access
|
|
75
|
+
|
|
76
|
+
Instead of fetching massive multi-GB extracts, the library is designed for **smart, cooperative usage patterns**, where users share infrastructure responsibly:
|
|
77
|
+
|
|
78
|
+
### ✅ Time Window Batching
|
|
79
|
+
Fetch long time periods in small, safe slices, python/Pandas "periods"
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
### ✅ Geographic Slicing
|
|
83
|
+
Request only the needed spatial extent by WKT filters
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## 🧱 Library Structure
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
+---kystdatahuset
|
|
91
|
+
| | ais.py
|
|
92
|
+
| | api_client.py
|
|
93
|
+
| | auth.py
|
|
94
|
+
| | const.py
|
|
95
|
+
| | file_storage.py
|
|
96
|
+
| | logging.py
|
|
97
|
+
| | voyage.py
|
|
98
|
+
| | __init__.py
|
|
99
|
+
| |
|
|
100
|
+
| +---models
|
|
101
|
+
| | | AuthData.py
|
|
102
|
+
| | | FileListing.py
|
|
103
|
+
| | | WebServiceResponse.py
|
|
104
|
+
| | | __init__.py
|
|
105
|
+
| | |
|
|
106
|
+
| |
|
|
107
|
+
| +---types
|
|
108
|
+
| | | PandasFrequency.py
|
|
109
|
+
| | | UploadFileType.py
|
|
110
|
+
| | | __init__.py
|
|
111
|
+
| | |
|
|
112
|
+
| |
|
|
113
|
+
| +---utils
|
|
114
|
+
| | | _date_range.py
|
|
115
|
+
| | | __init__.py
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## 📦 Development & Distribution
|
|
121
|
+
|
|
122
|
+
`kystdatahuset-py` uses standard packaging:
|
|
123
|
+
|
|
124
|
+
- `pyproject.toml` + `PEP 621` metadata
|
|
125
|
+
- versioning via Semantic Versioning
|
|
126
|
+
- full type hints (mypy-friendly)
|
|
127
|
+
- GitHub Actions for automated testing & publishing
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## 🧠 Typical Use Cases
|
|
132
|
+
|
|
133
|
+
- Query live AIS vessel data efficiently
|
|
134
|
+
- Retrieve spatial datasets in bounded windows
|
|
135
|
+
- Build dashboards, decision-support tools, or AI/ML pipelines
|
|
136
|
+
- Use Jackdaw (GeoAI) for semantic dataset discovery
|
|
137
|
+
- Integrate with Maritime or Rural Development workflows
|
|
138
|
+
- Avoid oversized extracts by using time/space batching helpers
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## 📄 License
|
|
143
|
+
|
|
144
|
+
Open source under the **MIT License**.
|
|
145
|
+
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# Kystdatahuset Python Library
|
|
2
|
+
|
|
3
|
+
`kystdatahuset-python-lib` — Python SDK companion for the Kystdatahuset API
|
|
4
|
+
|
|
5
|
+
`kystdatahuset-python-lib` is the official Python client for accessing the **Kystdatahuset API**, a unified data and knowledge platform for coastal and maritime spatial analytics.
|
|
6
|
+
|
|
7
|
+
It provides a clean, Pythonic, and strongly typed interface for querying datasets, managing authentication, and performing efficient data access.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## ✨ Features
|
|
12
|
+
|
|
13
|
+
### 🚀 Easy Installation
|
|
14
|
+
Install directly from PyPI:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install kystdatahuset-python-lib
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Supports Python **3.9+** on Linux, macOS, and Windows.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
### 🔐 Simple Authentication
|
|
25
|
+
The client offers:
|
|
26
|
+
|
|
27
|
+
- API key authentication
|
|
28
|
+
- Support for headless servers and notebooks
|
|
29
|
+
|
|
30
|
+
Example:
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
from kystdatahuset.auth import login
|
|
34
|
+
import os
|
|
35
|
+
|
|
36
|
+
login_response = login("username", "password")
|
|
37
|
+
jwt = auth_res.data.JWT
|
|
38
|
+
voyages = get_voyages_for_ships_by_mmsi(
|
|
39
|
+
auth_jwt=jwt,
|
|
40
|
+
mmsi_ids=[258090000, 259028000],
|
|
41
|
+
start_date=datetime(2024,1,1),
|
|
42
|
+
end_date=datetime(2024,5,1),
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## 🌍 Efficient & “Social” Data Access
|
|
49
|
+
|
|
50
|
+
Instead of fetching massive multi-GB extracts, the library is designed for **smart, cooperative usage patterns**, where users share infrastructure responsibly:
|
|
51
|
+
|
|
52
|
+
### ✅ Time Window Batching
|
|
53
|
+
Fetch long time periods in small, safe slices, python/Pandas "periods"
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
### ✅ Geographic Slicing
|
|
57
|
+
Request only the needed spatial extent by WKT filters
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## 🧱 Library Structure
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
+---kystdatahuset
|
|
65
|
+
| | ais.py
|
|
66
|
+
| | api_client.py
|
|
67
|
+
| | auth.py
|
|
68
|
+
| | const.py
|
|
69
|
+
| | file_storage.py
|
|
70
|
+
| | logging.py
|
|
71
|
+
| | voyage.py
|
|
72
|
+
| | __init__.py
|
|
73
|
+
| |
|
|
74
|
+
| +---models
|
|
75
|
+
| | | AuthData.py
|
|
76
|
+
| | | FileListing.py
|
|
77
|
+
| | | WebServiceResponse.py
|
|
78
|
+
| | | __init__.py
|
|
79
|
+
| | |
|
|
80
|
+
| |
|
|
81
|
+
| +---types
|
|
82
|
+
| | | PandasFrequency.py
|
|
83
|
+
| | | UploadFileType.py
|
|
84
|
+
| | | __init__.py
|
|
85
|
+
| | |
|
|
86
|
+
| |
|
|
87
|
+
| +---utils
|
|
88
|
+
| | | _date_range.py
|
|
89
|
+
| | | __init__.py
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## 📦 Development & Distribution
|
|
95
|
+
|
|
96
|
+
`kystdatahuset-py` uses standard packaging:
|
|
97
|
+
|
|
98
|
+
- `pyproject.toml` + `PEP 621` metadata
|
|
99
|
+
- versioning via Semantic Versioning
|
|
100
|
+
- full type hints (mypy-friendly)
|
|
101
|
+
- GitHub Actions for automated testing & publishing
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## 🧠 Typical Use Cases
|
|
106
|
+
|
|
107
|
+
- Query live AIS vessel data efficiently
|
|
108
|
+
- Retrieve spatial datasets in bounded windows
|
|
109
|
+
- Build dashboards, decision-support tools, or AI/ML pipelines
|
|
110
|
+
- Use Jackdaw (GeoAI) for semantic dataset discovery
|
|
111
|
+
- Integrate with Maritime or Rural Development workflows
|
|
112
|
+
- Avoid oversized extracts by using time/space batching helpers
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## 📄 License
|
|
117
|
+
|
|
118
|
+
Open source under the **MIT License**.
|
|
119
|
+
|
|
@@ -4,7 +4,8 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "kystdatahuset-python-lib"
|
|
7
|
-
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
# version = "0.1.0"
|
|
8
9
|
description = "A python library for accessing and querying data from Kystdatahuset"
|
|
9
10
|
readme = "README.md"
|
|
10
11
|
requires-python = ">=3.10"
|
|
@@ -33,6 +34,9 @@ dependencies = [
|
|
|
33
34
|
"numpy>=1.24",
|
|
34
35
|
"pandas>=2.0",
|
|
35
36
|
"pydantic>=2.0",
|
|
37
|
+
"requests>=2.28",
|
|
38
|
+
"shapely>=2.0",
|
|
39
|
+
"tqdm>=4.65",
|
|
36
40
|
]
|
|
37
41
|
|
|
38
42
|
[project.urls]
|
|
@@ -42,4 +46,7 @@ Issues = "https://github.com/Kystverket/kystdatahuset-python-lib/issues"
|
|
|
42
46
|
|
|
43
47
|
[tool.pytest.ini_options]
|
|
44
48
|
pythonpath = ["src"]
|
|
45
|
-
testpaths = ["tests"]
|
|
49
|
+
testpaths = ["tests"]
|
|
50
|
+
|
|
51
|
+
[tool.setuptools.dynamic]
|
|
52
|
+
version = {attr = "kystdatahuset.__version__"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.9.1"
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from typing import Dict, List
|
|
3
|
+
from kystdatahuset.api_client import post_api
|
|
4
|
+
|
|
5
|
+
def get_ais_positions_within_geom_time(
|
|
6
|
+
jwt_token: str,
|
|
7
|
+
geometry: str,
|
|
8
|
+
start_time: datetime,
|
|
9
|
+
end_time: datetime,
|
|
10
|
+
) -> List[Dict]:
|
|
11
|
+
"""
|
|
12
|
+
Placeholder for getting AIS positions for a given geometry and time range.
|
|
13
|
+
"""
|
|
14
|
+
response = post_api(
|
|
15
|
+
jwt_token=jwt_token,
|
|
16
|
+
fragment="api/ais/positions/within-geom-time",
|
|
17
|
+
payload={
|
|
18
|
+
"geom": geometry,
|
|
19
|
+
"start": start_time.isoformat(),
|
|
20
|
+
"end": end_time.isoformat(),
|
|
21
|
+
"minSpeed": 0,
|
|
22
|
+
},
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
# This is a placeholder implementation.
|
|
26
|
+
if (response is None) or (not response["success"]):
|
|
27
|
+
raise Exception(f"Failed to get AIS positions: {response['msg'] if response else 'No response'}")
|
|
28
|
+
|
|
29
|
+
return response["data"]
|
{kystdatahuset_python_lib-0.1.0 → kystdatahuset_python_lib-0.9.1}/src/kystdatahuset/api_client.py
RENAMED
|
@@ -82,7 +82,7 @@ def delete_api(jwt_token: str, fragment: str, params: Optional[Dict[str, Any]] =
|
|
|
82
82
|
raise Exception(f"API GET failed with status code {response.status_code}: {response.text}")
|
|
83
83
|
|
|
84
84
|
|
|
85
|
-
def
|
|
85
|
+
def post_api(jwt_token: str, fragment: str, payload: Dict[str, Any]) -> WebServiceResponse:
|
|
86
86
|
"""
|
|
87
87
|
Perform a POST request with a JSON body and parse JSON response.
|
|
88
88
|
"""
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from ._date_range import date_range
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
import pandas as pd
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from kystdatahuset.types import PandasFreqency
|
|
5
|
+
from more_itertools import pairwise
|
|
6
|
+
|
|
7
|
+
def date_range(start_date: datetime, end_date: datetime, freq: PandasFreqency = "D") -> List[datetime]:
|
|
8
|
+
"""
|
|
9
|
+
Generate a list of dates from start_date to end_date, inclusive.
|
|
10
|
+
"""
|
|
11
|
+
if start_date > end_date:
|
|
12
|
+
raise ValueError("start_date must be less than or equal to end_date")
|
|
13
|
+
|
|
14
|
+
dates = pd.date_range(start=start_date, end=end_date, freq=freq)
|
|
15
|
+
return pairwise([dt.to_pydatetime() for dt in dates])
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from typing import List, Dict
|
|
2
|
+
from requests_cache import datetime
|
|
3
|
+
from kystdatahuset.api_client import post_api
|
|
4
|
+
from kystdatahuset.utils import date_range
|
|
5
|
+
|
|
6
|
+
def get_voyages_for_ships_by_mmsi(auth_jwt: str, mmsi_ids: List[int], start_date: datetime, end_date: datetime) -> List[Dict]:
|
|
7
|
+
"""
|
|
8
|
+
Placeholder for getting voyages data for ships by MMSI.
|
|
9
|
+
"""
|
|
10
|
+
date_ranges = date_range(start_date, end_date, "MS")
|
|
11
|
+
for pair in date_ranges:
|
|
12
|
+
print(pair) # Debug print to verify date ranges
|
|
13
|
+
|
|
14
|
+
response = post_api(
|
|
15
|
+
jwt_token=auth_jwt,
|
|
16
|
+
fragment="api/voyage/for-ships/by-mmsi",
|
|
17
|
+
payload={
|
|
18
|
+
"mmsiIds": mmsi_ids,
|
|
19
|
+
"startTime": start_date.isoformat(),
|
|
20
|
+
"endTime": end_date.isoformat()
|
|
21
|
+
},
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
if (response is None) or (not response["success"]):
|
|
25
|
+
raise Exception(f"Failed to get voyages for ships by MMSI: {response['msg'] if response else 'No response'}")
|
|
26
|
+
else:
|
|
27
|
+
return response["data"]
|
|
28
|
+
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kystdatahuset-python-lib
|
|
3
|
+
Version: 0.9.1
|
|
4
|
+
Summary: A python library for accessing and querying data from Kystdatahuset
|
|
5
|
+
Author-email: Kystdatahuset developer team <support@kystdatahuset.no>, "(Stein) Runar Bergheim" <runar.bergheim@avinet.no>, Sigve Bergh <sigve.bergh@kystverket.no>, Hermann Klaus Kurt von Lupfert <hermann.lupfert@kystverket.no>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Kystverket/kystdatahuset-python-lib
|
|
8
|
+
Project-URL: Repository, https://github.com/Kystverket/kystdatahuset-python-lib
|
|
9
|
+
Project-URL: Issues, https://github.com/Kystverket/kystdatahuset-python-lib/issues
|
|
10
|
+
Keywords: spatial,analytics,visualization,geodata
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Requires-Python: >=3.10
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: numpy>=1.24
|
|
20
|
+
Requires-Dist: pandas>=2.0
|
|
21
|
+
Requires-Dist: pydantic>=2.0
|
|
22
|
+
Requires-Dist: requests>=2.28
|
|
23
|
+
Requires-Dist: shapely>=2.0
|
|
24
|
+
Requires-Dist: tqdm>=4.65
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# Kystdatahuset Python Library
|
|
28
|
+
|
|
29
|
+
`kystdatahuset-python-lib` — Python SDK companion for the Kystdatahuset API
|
|
30
|
+
|
|
31
|
+
`kystdatahuset-python-lib` is the official Python client for accessing the **Kystdatahuset API**, a unified data and knowledge platform for coastal and maritime spatial analytics.
|
|
32
|
+
|
|
33
|
+
It provides a clean, Pythonic, and strongly typed interface for querying datasets, managing authentication, and performing efficient data access.
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## ✨ Features
|
|
38
|
+
|
|
39
|
+
### 🚀 Easy Installation
|
|
40
|
+
Install directly from PyPI:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pip install kystdatahuset-python-lib
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Supports Python **3.9+** on Linux, macOS, and Windows.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
### 🔐 Simple Authentication
|
|
51
|
+
The client offers:
|
|
52
|
+
|
|
53
|
+
- API key authentication
|
|
54
|
+
- Support for headless servers and notebooks
|
|
55
|
+
|
|
56
|
+
Example:
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from kystdatahuset.auth import login
|
|
60
|
+
import os
|
|
61
|
+
|
|
62
|
+
login_response = login("username", "password")
|
|
63
|
+
jwt = auth_res.data.JWT
|
|
64
|
+
voyages = get_voyages_for_ships_by_mmsi(
|
|
65
|
+
auth_jwt=jwt,
|
|
66
|
+
mmsi_ids=[258090000, 259028000],
|
|
67
|
+
start_date=datetime(2024,1,1),
|
|
68
|
+
end_date=datetime(2024,5,1),
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## 🌍 Efficient & “Social” Data Access
|
|
75
|
+
|
|
76
|
+
Instead of fetching massive multi-GB extracts, the library is designed for **smart, cooperative usage patterns**, where users share infrastructure responsibly:
|
|
77
|
+
|
|
78
|
+
### ✅ Time Window Batching
|
|
79
|
+
Fetch long time periods in small, safe slices, python/Pandas "periods"
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
### ✅ Geographic Slicing
|
|
83
|
+
Request only the needed spatial extent by WKT filters
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## 🧱 Library Structure
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
+---kystdatahuset
|
|
91
|
+
| | ais.py
|
|
92
|
+
| | api_client.py
|
|
93
|
+
| | auth.py
|
|
94
|
+
| | const.py
|
|
95
|
+
| | file_storage.py
|
|
96
|
+
| | logging.py
|
|
97
|
+
| | voyage.py
|
|
98
|
+
| | __init__.py
|
|
99
|
+
| |
|
|
100
|
+
| +---models
|
|
101
|
+
| | | AuthData.py
|
|
102
|
+
| | | FileListing.py
|
|
103
|
+
| | | WebServiceResponse.py
|
|
104
|
+
| | | __init__.py
|
|
105
|
+
| | |
|
|
106
|
+
| |
|
|
107
|
+
| +---types
|
|
108
|
+
| | | PandasFrequency.py
|
|
109
|
+
| | | UploadFileType.py
|
|
110
|
+
| | | __init__.py
|
|
111
|
+
| | |
|
|
112
|
+
| |
|
|
113
|
+
| +---utils
|
|
114
|
+
| | | _date_range.py
|
|
115
|
+
| | | __init__.py
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## 📦 Development & Distribution
|
|
121
|
+
|
|
122
|
+
`kystdatahuset-py` uses standard packaging:
|
|
123
|
+
|
|
124
|
+
- `pyproject.toml` + `PEP 621` metadata
|
|
125
|
+
- versioning via Semantic Versioning
|
|
126
|
+
- full type hints (mypy-friendly)
|
|
127
|
+
- GitHub Actions for automated testing & publishing
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## 🧠 Typical Use Cases
|
|
132
|
+
|
|
133
|
+
- Query live AIS vessel data efficiently
|
|
134
|
+
- Retrieve spatial datasets in bounded windows
|
|
135
|
+
- Build dashboards, decision-support tools, or AI/ML pipelines
|
|
136
|
+
- Use Jackdaw (GeoAI) for semantic dataset discovery
|
|
137
|
+
- Integrate with Maritime or Rural Development workflows
|
|
138
|
+
- Avoid oversized extracts by using time/space batching helpers
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## 📄 License
|
|
143
|
+
|
|
144
|
+
Open source under the **MIT License**.
|
|
145
|
+
|
|
@@ -3,12 +3,13 @@ README.md
|
|
|
3
3
|
pyproject.toml
|
|
4
4
|
src/__init__.py
|
|
5
5
|
src/kystdatahuset/__init__.py
|
|
6
|
+
src/kystdatahuset/ais.py
|
|
6
7
|
src/kystdatahuset/api_client.py
|
|
7
8
|
src/kystdatahuset/auth.py
|
|
8
9
|
src/kystdatahuset/const.py
|
|
9
10
|
src/kystdatahuset/file_storage.py
|
|
10
11
|
src/kystdatahuset/logging.py
|
|
11
|
-
src/kystdatahuset/
|
|
12
|
+
src/kystdatahuset/voyage.py
|
|
12
13
|
src/kystdatahuset/models/AuthData.py
|
|
13
14
|
src/kystdatahuset/models/FileListing.py
|
|
14
15
|
src/kystdatahuset/models/WebServiceResponse.py
|
|
@@ -17,11 +18,13 @@ src/kystdatahuset/types/PandasFrequency.py
|
|
|
17
18
|
src/kystdatahuset/types/UploadFileType.py
|
|
18
19
|
src/kystdatahuset/types/__init__.py
|
|
19
20
|
src/kystdatahuset/utils/__init__.py
|
|
20
|
-
src/kystdatahuset/utils/
|
|
21
|
+
src/kystdatahuset/utils/_date_range.py
|
|
21
22
|
src/kystdatahuset_python_lib.egg-info/PKG-INFO
|
|
22
23
|
src/kystdatahuset_python_lib.egg-info/SOURCES.txt
|
|
23
24
|
src/kystdatahuset_python_lib.egg-info/dependency_links.txt
|
|
24
25
|
src/kystdatahuset_python_lib.egg-info/requires.txt
|
|
25
26
|
src/kystdatahuset_python_lib.egg-info/top_level.txt
|
|
27
|
+
tests/test_ais.py
|
|
26
28
|
tests/test_auth.py
|
|
27
|
-
tests/test_file_storage.py
|
|
29
|
+
tests/test_file_storage.py
|
|
30
|
+
tests/test_voyage.py
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from conftest import auth_jwt, wkt
|
|
3
|
+
from kystdatahuset.ais import get_ais_positions_within_geom_time
|
|
4
|
+
from kystdatahuset.logging import logger
|
|
5
|
+
|
|
6
|
+
def test_get_ais_pos_for_geom_time(auth_jwt, wkt):
|
|
7
|
+
response = get_ais_positions_within_geom_time(
|
|
8
|
+
jwt_token=auth_jwt,
|
|
9
|
+
geometry=wkt,
|
|
10
|
+
start_time=datetime(2024, 1, 1),
|
|
11
|
+
end_time=datetime(2024, 1, 2),
|
|
12
|
+
)
|
|
13
|
+
assert response is not None, "Expected a response, got None"
|
|
14
|
+
assert isinstance(response, list), "Expected response to be a list"
|
|
15
|
+
assert len(response) > 0, "Expected non-empty response list"
|
|
16
|
+
assert all(len(item) == 12 for item in response), "Expected all items in response to be of length >= 5"
|
|
17
|
+
logger.info(f"Response sample: {response[:2]}")
|
|
18
|
+
logger.info(f"Retrieved {len(response)} AIS positions")
|
{kystdatahuset_python_lib-0.1.0 → kystdatahuset_python_lib-0.9.1}/tests/test_file_storage.py
RENAMED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
from kystdatahuset.file_storage import publish, list, delete
|
|
2
2
|
from uuid import UUID
|
|
3
3
|
from typing import List
|
|
4
|
+
from glob import glob
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
def test_publish(upload_filename, auth_jwt):
|
|
8
|
+
publish_res = publish(jwt_token=auth_jwt, resource_uuid=UUID("64127fc2-2644-4ed9-b886-fecfb914c4b5"), file_path=upload_filename, title="Testfile", upload_file_type="csv", description="This is a test upload", categories=["test", "upload"], compressed=True)
|
|
9
|
+
assert publish_res is not None, "Expected publish to return True"
|
|
10
|
+
|
|
11
|
+
def test_publish_mfiles(auth_jwt):
|
|
12
|
+
files = glob(r"C:\Users\runar.bergheim\Documents\Development\nsr2csv\tmp\*.zip")
|
|
13
|
+
for file in files:
|
|
14
|
+
publish_res = publish(jwt_token=auth_jwt, resource_uuid=UUID("8e16b69e-d466-47bd-91d2-179aebdf4f65"), file_path=file, title=Path(file).name, upload_file_type="csv", description="Månedsfil med meldepliktige seilas fra SafeSeaNet", categories=["test", "upload"], compressed=True)
|
|
15
|
+
assert publish_res is not None, "Expected publish to return True"
|
|
4
16
|
|
|
5
17
|
def test_list(auth_jwt):
|
|
6
18
|
list_res = list(jwt_token=auth_jwt, resource_uuid=UUID("64127fc2-2644-4ed9-b886-fecfb914c4b5"))
|
|
7
19
|
assert isinstance(list_res, List) and len(list_res) >= 0, "Expected non-empty file list"
|
|
8
20
|
|
|
9
|
-
def test_publish(upload_filename, auth_jwt):
|
|
10
|
-
publish_res = publish(jwt_token=auth_jwt, resource_uuid=UUID("64127fc2-2644-4ed9-b886-fecfb914c4b5"), file_path=upload_filename, title="Test Upload", upload_file_type="csv", description="This is a test upload", categories=["test", "upload"], compressed=True)
|
|
11
|
-
assert publish_res is not None, "Expected publish to return True"
|
|
12
|
-
|
|
13
21
|
def test_delete(auth_jwt):
|
|
14
22
|
list_res = list(jwt_token=auth_jwt, resource_uuid=UUID("64127fc2-2644-4ed9-b886-fecfb914c4b5"))
|
|
15
23
|
delete_res = delete(jwt_token=auth_jwt, file_uuid=list_res[0].uuid)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from kystdatahuset.voyage import get_voyages_for_ships_by_mmsi
|
|
2
|
+
from kystdatahuset.logging import logger
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from conftest import auth_jwt
|
|
5
|
+
|
|
6
|
+
def test_get_voyages_for_ships_by_mmsi(auth_jwt):
|
|
7
|
+
response = get_voyages_for_ships_by_mmsi(
|
|
8
|
+
auth_jwt=auth_jwt,
|
|
9
|
+
mmsi_ids=[258090000, 259028000],
|
|
10
|
+
start_date=datetime(2024,1,1),
|
|
11
|
+
end_date=datetime(2024,5,1),
|
|
12
|
+
)
|
|
13
|
+
assert response is not None, "Expected a response, got None"
|
|
14
|
+
assert isinstance(response, list), "Expected response to be a list"
|
|
15
|
+
logger.info(f"Retrieved {len(response)} voyages")
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: kystdatahuset-python-lib
|
|
3
|
-
Version: 0.1.0
|
|
4
|
-
Summary: A python library for accessing and querying data from Kystdatahuset
|
|
5
|
-
Author-email: Kystdatahuset developer team <support@kystdatahuset.no>, "(Stein) Runar Bergheim" <runar.bergheim@avinet.no>, Sigve Bergh <sigve.bergh@kystverket.no>, Hermann Klaus Kurt von Lupfert <hermann.lupfert@kystverket.no>
|
|
6
|
-
License-Expression: MIT
|
|
7
|
-
Project-URL: Homepage, https://github.com/Kystverket/kystdatahuset-python-lib
|
|
8
|
-
Project-URL: Repository, https://github.com/Kystverket/kystdatahuset-python-lib
|
|
9
|
-
Project-URL: Issues, https://github.com/Kystverket/kystdatahuset-python-lib/issues
|
|
10
|
-
Keywords: spatial,analytics,visualization,geodata
|
|
11
|
-
Classifier: Development Status :: 4 - Beta
|
|
12
|
-
Classifier: Intended Audience :: Developers
|
|
13
|
-
Classifier: Topic :: Software Development :: Libraries
|
|
14
|
-
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
-
Requires-Python: >=3.10
|
|
17
|
-
Description-Content-Type: text/markdown
|
|
18
|
-
License-File: LICENSE
|
|
19
|
-
Requires-Dist: numpy>=1.24
|
|
20
|
-
Requires-Dist: pandas>=2.0
|
|
21
|
-
Requires-Dist: pydantic>=2.0
|
|
22
|
-
Dynamic: license-file
|
|
23
|
-
|
|
24
|
-
# Kystdatahuset Python Library
|
|
25
|
-
|
|
26
|
-
A library to access and query Kystdatahuset
|
|
File without changes
|
|
File without changes
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
from typing import List, Optional, Tuple
|
|
2
|
-
|
|
3
|
-
from datetime import datetime, timedelta
|
|
4
|
-
from kystdatahuset.types import PandasFreqency
|
|
5
|
-
|
|
6
|
-
def date_range2(start_date: datetime, end_date: datetime, freq: PandasFreqency) -> List[datetime]:
|
|
7
|
-
"""
|
|
8
|
-
Generate a list of dates from start_date to end_date, inclusive.
|
|
9
|
-
"""
|
|
10
|
-
if start_date > end_date:
|
|
11
|
-
raise ValueError("start_date must be less than or equal to end_date")
|
|
12
|
-
|
|
13
|
-
delta = end_date - start_date
|
|
14
|
-
return [start_date + timedelta(days=i) for i in range(delta.days + 1)]
|
|
File without changes
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: kystdatahuset-python-lib
|
|
3
|
-
Version: 0.1.0
|
|
4
|
-
Summary: A python library for accessing and querying data from Kystdatahuset
|
|
5
|
-
Author-email: Kystdatahuset developer team <support@kystdatahuset.no>, "(Stein) Runar Bergheim" <runar.bergheim@avinet.no>, Sigve Bergh <sigve.bergh@kystverket.no>, Hermann Klaus Kurt von Lupfert <hermann.lupfert@kystverket.no>
|
|
6
|
-
License-Expression: MIT
|
|
7
|
-
Project-URL: Homepage, https://github.com/Kystverket/kystdatahuset-python-lib
|
|
8
|
-
Project-URL: Repository, https://github.com/Kystverket/kystdatahuset-python-lib
|
|
9
|
-
Project-URL: Issues, https://github.com/Kystverket/kystdatahuset-python-lib/issues
|
|
10
|
-
Keywords: spatial,analytics,visualization,geodata
|
|
11
|
-
Classifier: Development Status :: 4 - Beta
|
|
12
|
-
Classifier: Intended Audience :: Developers
|
|
13
|
-
Classifier: Topic :: Software Development :: Libraries
|
|
14
|
-
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
-
Requires-Python: >=3.10
|
|
17
|
-
Description-Content-Type: text/markdown
|
|
18
|
-
License-File: LICENSE
|
|
19
|
-
Requires-Dist: numpy>=1.24
|
|
20
|
-
Requires-Dist: pandas>=2.0
|
|
21
|
-
Requires-Dist: pydantic>=2.0
|
|
22
|
-
Dynamic: license-file
|
|
23
|
-
|
|
24
|
-
# Kystdatahuset Python Library
|
|
25
|
-
|
|
26
|
-
A library to access and query Kystdatahuset
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{kystdatahuset_python_lib-0.1.0 → kystdatahuset_python_lib-0.9.1}/src/kystdatahuset/const.py
RENAMED
|
File without changes
|
{kystdatahuset_python_lib-0.1.0 → kystdatahuset_python_lib-0.9.1}/src/kystdatahuset/file_storage.py
RENAMED
|
File without changes
|
{kystdatahuset_python_lib-0.1.0 → kystdatahuset_python_lib-0.9.1}/src/kystdatahuset/logging.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|