cloudnet-api-client 0.1.0__tar.gz → 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## 0.1.2 – 2025-03-27
9
+
10
+ - Add method to fetch instruments
11
+
12
+ ## 0.1.1 – 2025-03-27
13
+
14
+ - Add `updated_at_from` and `updated_at_to` parameters
15
+
8
16
  ## 0.1.0 – 2025-03-27
9
17
 
10
18
  - Initial release
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cloudnet-api-client
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Summary: Cloudnet API client
5
5
  Author-email: Simo Tukiainen <simo.tukiainen@fmi.fi>
6
6
  License-File: LICENSE
@@ -27,7 +27,13 @@ Description-Content-Type: text/markdown
27
27
 
28
28
  # cloudnet-api-client
29
29
 
30
- Official Python package for using Cloudnet API
30
+ Official Python client for the [Cloudnet data portal API](https://docs.cloudnet.fmi.fi/api/data-portal.html).
31
+
32
+ ## Installation
33
+
34
+ ```bash
35
+ python3 -m pip install cloudnet-api-client
36
+ ```
31
37
 
32
38
  ## Quickstart
33
39
 
@@ -40,10 +46,10 @@ sites = client.sites(type="cloudnet")
40
46
  products = client.products()
41
47
 
42
48
  metadata = client.metadata("hyytiala", "2021-01-01", product=["mwr", "radar"])
43
- cac.download(metadata, "data")
49
+ cac.download(metadata, "data/")
44
50
 
45
- raw_metadata = client.metadata("hyytiala", "2021-01-01")
46
- cac.download(raw_metadata, "data_raw")
51
+ raw_metadata = client.raw_metadata("granada", date="2024-01", instrument_id="parsivel")
52
+ cac.download(raw_metadata, "data_raw/")
47
53
  ```
48
54
 
49
55
  ## Documentation
@@ -54,16 +60,18 @@ Fetch product and raw file metadata from the Cloudnet data portal.
54
60
 
55
61
  Parameters:
56
62
 
57
- | name | type | default | example |
58
- | -------------- | ------------------------ | ------- | ---------------------------------------------------- |
59
- | site_id | `str` | | "hyytiala" |
60
- | date | `str` or `datetime.date` | `None` | "2024-01-01" |
61
- | date_from | `str` or `datetime.date` | `None` | "2025-01-01" |
62
- | date_to | `str` or `datetime.date` | `None` | "2025-01-01" |
63
- | instrument_id | `str` or `[str]` | `None` | "rpg-fmcw-94" |
64
- | instrument_pid | `str` or `[str]` | `None` | "https://hdl.handle.net/21.12132/3.191564170f8a4686" |
65
- | product\* | `str` or `[str]` | `None` | "classification" |
66
- | show_legacy\* | `bool` | `False` | |
63
+ | name | type | default | example |
64
+ | --------------- | ------------------------ | ------- | ---------------------------------------------------- |
65
+ | site_id | `str` | | "hyytiala" |
66
+ | date | `str` or `datetime.date` | `None` | "2024-01-01" |
67
+ | date_from | `str` or `datetime.date` | `None` | "2025-01-01" |
68
+ | date_to | `str` or `datetime.date` | `None` | "2025-01-01" |
69
+ | updated_at_from | `str` or `datetime.date` | `None` | "2025-01-01" |
70
+ | updated_at_to | `str` or `datetime.date` | `None` | "2025-01-01" |
71
+ | instrument_id | `str` or `[str]` | `None` | "rpg-fmcw-94" |
72
+ | instrument_pid | `str` or `[str]` | `None` | "https://hdl.handle.net/21.12132/3.191564170f8a4686" |
73
+ | product\* | `str` or `[str]` | `None` | "classification" |
74
+ | show_legacy\* | `bool` | `False` | |
67
75
 
68
76
  \* = only in `metadata()`
69
77
 
@@ -76,7 +84,8 @@ The `date` parameter supports:
76
84
  - "YYYY" — the entire year
77
85
  - Or directly as `datetime.date` object
78
86
 
79
- The `date_from` and `date_to` parameters should be "YYYY-MM-DD" or `datetime.date`. If `date` is defined, `date_from` and `date_to` have no effect.
87
+ The `date_from`, `date_to`, `updated_at_from` and `updated_at_to` parameters
88
+ should be of form "YYYY-MM-DD" or `datetime.date`. Note that, if `date` is defined, `date_from` and `date_to` have no effect.
80
89
 
81
90
  **Return value**
82
91
 
@@ -98,16 +107,40 @@ Parameters:
98
107
  | include_tag_subset | `{str}` | `None` |
99
108
  | exclude_tag_subset | `{str}` | `None` |
100
109
 
110
+ ### `APIClient().sites()` &rarr; `[Site]`
111
+
112
+ Fetch cloudnet sites.
113
+
114
+ Parameters:
115
+
116
+ | name | type | Choices | default |
117
+ | ---- | ---------------- | ----------------------------------------- | ------- |
118
+ | type | `str` or `[str]` | "cloudnet", "campaign", "model", "hidden" | `None` |
119
+
120
+ ### `APIClient().products()` &rarr; `[Product]`
121
+
122
+ Fetch cloudnet products.
123
+
124
+ Parameters:
125
+
126
+ | name | type | Choices | default |
127
+ | ---- | ---------------- | ----------------------------------------- | ------- |
128
+ | type | `str` or `[str]` | "instrument", "geophysical", "evaluation" | `None` |
129
+
130
+ ### `APIClient().instruments()` &rarr; `[Instrument]`
131
+
132
+ Fetch cloudnet instruments.
133
+
101
134
  ### `cloudnet_api_client.download([Metadata])`
102
135
 
103
- Function to download files from fetched metadata.
136
+ Download files from the fetched metadata.
104
137
 
105
138
  Parameters:
106
139
 
107
140
  | name | type | default |
108
141
  | ----------------- | -------------------------------------- | ------- |
109
142
  | metadata | `[RawMetadata]` or `[ProductMetadata]` | |
110
- | output_directory | `PathLike` | |
143
+ | output_directory | `PathLike` or `str` | |
111
144
  | concurrency_limit | `int` | 5 |
112
145
 
113
146
  ## License
@@ -0,0 +1,123 @@
1
+ [![CI](https://github.com/actris-cloudnet/cloudnet-api-client/actions/workflows/test.yml/badge.svg)](https://github.com/actris-cloudnet/cloudnet-api-client/actions/workflows/test.yml)
2
+
3
+ # cloudnet-api-client
4
+
5
+ Official Python client for the [Cloudnet data portal API](https://docs.cloudnet.fmi.fi/api/data-portal.html).
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ python3 -m pip install cloudnet-api-client
11
+ ```
12
+
13
+ ## Quickstart
14
+
15
+ ```python
16
+ import cloudnet_api_client as cac
17
+
18
+ client = cac.APIClient()
19
+
20
+ sites = client.sites(type="cloudnet")
21
+ products = client.products()
22
+
23
+ metadata = client.metadata("hyytiala", "2021-01-01", product=["mwr", "radar"])
24
+ cac.download(metadata, "data/")
25
+
26
+ raw_metadata = client.raw_metadata("granada", date="2024-01", instrument_id="parsivel")
27
+ cac.download(raw_metadata, "data_raw/")
28
+ ```
29
+
30
+ ## Documentation
31
+
32
+ ### `APIClient().metadata()` and `raw_metadata()` &rarr; `[Metadata]`
33
+
34
+ Fetch product and raw file metadata from the Cloudnet data portal.
35
+
36
+ Parameters:
37
+
38
+ | name | type | default | example |
39
+ | --------------- | ------------------------ | ------- | ---------------------------------------------------- |
40
+ | site_id | `str` | | "hyytiala" |
41
+ | date | `str` or `datetime.date` | `None` | "2024-01-01" |
42
+ | date_from | `str` or `datetime.date` | `None` | "2025-01-01" |
43
+ | date_to | `str` or `datetime.date` | `None` | "2025-01-01" |
44
+ | updated_at_from | `str` or `datetime.date` | `None` | "2025-01-01" |
45
+ | updated_at_to | `str` or `datetime.date` | `None` | "2025-01-01" |
46
+ | instrument_id | `str` or `[str]` | `None` | "rpg-fmcw-94" |
47
+ | instrument_pid | `str` or `[str]` | `None` | "https://hdl.handle.net/21.12132/3.191564170f8a4686" |
48
+ | product\* | `str` or `[str]` | `None` | "classification" |
49
+ | show_legacy\* | `bool` | `False` | |
50
+
51
+ \* = only in `metadata()`
52
+
53
+ **Date Handling**
54
+
55
+ The `date` parameter supports:
56
+
57
+ - "YYYY-MM-DD" — a specific date
58
+ - "YYYY-MM" — the entire month
59
+ - "YYYY" — the entire year
60
+ - Or directly as `datetime.date` object
61
+
62
+ The `date_from`, `date_to`, `updated_at_from` and `updated_at_to` parameters
63
+ should be of form "YYYY-MM-DD" or `datetime.date`. Note that, if `date` is defined, `date_from` and `date_to` have no effect.
64
+
65
+ **Return value**
66
+
67
+ Both methods return a list of `dataclass` instances, `ProductMetadata` and `RawMetadata`, respectively.
68
+
69
+ ### `APIClient().filter([Metadata])` &rarr; `[Metadata]`
70
+
71
+ Additional filtering of fetched metadata.
72
+
73
+ Parameters:
74
+
75
+ | name | type | default |
76
+ | ------------------ | -------------------------------------- | ------- |
77
+ | metadata | `[RawMetadata]` or `[ProductMetadata]` | |
78
+ | include_pattern | `str` | `None` |
79
+ | exclude_pattern | `str` | `None` |
80
+ | filename_prefix | `str` | `None` |
81
+ | filename_suffix | `str` | `None` |
82
+ | include_tag_subset | `{str}` | `None` |
83
+ | exclude_tag_subset | `{str}` | `None` |
84
+
85
+ ### `APIClient().sites()` &rarr; `[Site]`
86
+
87
+ Fetch cloudnet sites.
88
+
89
+ Parameters:
90
+
91
+ | name | type | Choices | default |
92
+ | ---- | ---------------- | ----------------------------------------- | ------- |
93
+ | type | `str` or `[str]` | "cloudnet", "campaign", "model", "hidden" | `None` |
94
+
95
+ ### `APIClient().products()` &rarr; `[Product]`
96
+
97
+ Fetch cloudnet products.
98
+
99
+ Parameters:
100
+
101
+ | name | type | Choices | default |
102
+ | ---- | ---------------- | ----------------------------------------- | ------- |
103
+ | type | `str` or `[str]` | "instrument", "geophysical", "evaluation" | `None` |
104
+
105
+ ### `APIClient().instruments()` &rarr; `[Instrument]`
106
+
107
+ Fetch cloudnet instruments.
108
+
109
+ ### `cloudnet_api_client.download([Metadata])`
110
+
111
+ Download files from the fetched metadata.
112
+
113
+ Parameters:
114
+
115
+ | name | type | default |
116
+ | ----------------- | -------------------------------------- | ------- |
117
+ | metadata | `[RawMetadata]` or `[ProductMetadata]` | |
118
+ | output_directory | `PathLike` or `str` | |
119
+ | concurrency_limit | `int` | 5 |
120
+
121
+ ## License
122
+
123
+ MIT
@@ -50,12 +50,30 @@ class APIClient:
50
50
  data = [obj for obj in data if any(t in obj.type for t in type)]
51
51
  return data
52
52
 
53
+ def instruments(self) -> list[Instrument]:
54
+ res = self._get_response("instrument-pids")
55
+ return [
56
+ Instrument(
57
+ instrument_id=obj["instrument"]["id"],
58
+ model=obj["model"],
59
+ type=obj["type"],
60
+ uuid=obj["uuid"],
61
+ pid=obj["pid"],
62
+ owners=obj["owners"],
63
+ serial_number=obj["serialNumber"],
64
+ name=obj["name"],
65
+ )
66
+ for obj in res
67
+ ]
68
+
53
69
  def metadata(
54
70
  self,
55
71
  site_id: str,
56
72
  date: DateParam = None,
57
73
  date_from: DateParam = None,
58
74
  date_to: DateParam = None,
75
+ updated_at_from: DateParam = None,
76
+ updated_at_to: DateParam = None,
59
77
  instrument_id: QueryParam = None,
60
78
  instrument_pid: QueryParam = None,
61
79
  product: QueryParam = None,
@@ -68,7 +86,9 @@ class APIClient:
68
86
  "product": product,
69
87
  "showLegacy": show_legacy,
70
88
  }
71
- date_params = self._mangle_dates(date, date_from, date_to)
89
+ date_params = self._mangle_dates(
90
+ date, date_from, date_to, updated_at_from, updated_at_to
91
+ )
72
92
  params.update(date_params)
73
93
  res = self._get_response("files", params)
74
94
  return _build_objects(res, ProductMetadata)
@@ -79,6 +99,8 @@ class APIClient:
79
99
  date: DateParam = None,
80
100
  date_from: DateParam = None,
81
101
  date_to: DateParam = None,
102
+ updated_at_from: DateParam = None,
103
+ updated_at_to: DateParam = None,
82
104
  instrument_id: QueryParam = None,
83
105
  instrument_pid: QueryParam = None,
84
106
  ) -> list[RawMetadata]:
@@ -87,7 +109,9 @@ class APIClient:
87
109
  "instrument": instrument_id,
88
110
  "instrumentPid": instrument_pid,
89
111
  }
90
- date_params = self._mangle_dates(date, date_from, date_to)
112
+ date_params = self._mangle_dates(
113
+ date, date_from, date_to, updated_at_from, updated_at_to
114
+ )
91
115
  params.update(date_params)
92
116
  res = self._get_response("raw-files", params)
93
117
  return _build_raw_meta_objects(res)
@@ -139,10 +163,17 @@ class APIClient:
139
163
  return res.json()
140
164
 
141
165
  def _mangle_dates(
142
- self, date: DateParam, date_from: DateParam, date_to: DateParam
166
+ self,
167
+ date: DateParam,
168
+ date_from: DateParam,
169
+ date_to: DateParam,
170
+ updated_at_from: DateParam,
171
+ updated_at_to: DateParam,
143
172
  ) -> dict:
144
173
  params = {}
145
- if isinstance(date, str):
174
+ if isinstance(date, datetime.date):
175
+ params["date"] = date
176
+ elif isinstance(date, str):
146
177
  if re.fullmatch(r"\d{4}-\d{2}-\d{2}", date):
147
178
  params["date"] = self._parse_date(date)
148
179
  elif re.fullmatch(r"\d{4}-\d{2}", date):
@@ -155,13 +186,15 @@ class APIClient:
155
186
  params["dateTo"] = datetime.date(int(date), 12, 31)
156
187
  else:
157
188
  raise ValueError("Invalid date format")
158
- elif isinstance(date, datetime.date):
159
- params["date"] = date
160
189
  else:
161
190
  if date_from:
162
191
  params["dateFrom"] = self._parse_date(date_from)
163
192
  if date_to:
164
193
  params["dateTo"] = self._parse_date(date_to)
194
+ if updated_at_from:
195
+ params["updatedAtFrom"] = self._parse_date(updated_at_from)
196
+ if updated_at_to:
197
+ params["updatedAtTo"] = self._parse_date(updated_at_to)
165
198
  return params
166
199
 
167
200
  @staticmethod
@@ -0,0 +1 @@
1
+ __version__ = "0.1.2"
@@ -1,90 +0,0 @@
1
- [![CI](https://github.com/actris-cloudnet/cloudnet-api-client/actions/workflows/test.yml/badge.svg)](https://github.com/actris-cloudnet/cloudnet-api-client/actions/workflows/test.yml)
2
-
3
- # cloudnet-api-client
4
-
5
- Official Python package for using Cloudnet API
6
-
7
- ## Quickstart
8
-
9
- ```python
10
- import cloudnet_api_client as cac
11
-
12
- client = cac.APIClient()
13
-
14
- sites = client.sites(type="cloudnet")
15
- products = client.products()
16
-
17
- metadata = client.metadata("hyytiala", "2021-01-01", product=["mwr", "radar"])
18
- cac.download(metadata, "data")
19
-
20
- raw_metadata = client.metadata("hyytiala", "2021-01-01")
21
- cac.download(raw_metadata, "data_raw")
22
- ```
23
-
24
- ## Documentation
25
-
26
- ### `APIClient().metadata()` and `raw_metadata()` &rarr; `[Metadata]`
27
-
28
- Fetch product and raw file metadata from the Cloudnet data portal.
29
-
30
- Parameters:
31
-
32
- | name | type | default | example |
33
- | -------------- | ------------------------ | ------- | ---------------------------------------------------- |
34
- | site_id | `str` | | "hyytiala" |
35
- | date | `str` or `datetime.date` | `None` | "2024-01-01" |
36
- | date_from | `str` or `datetime.date` | `None` | "2025-01-01" |
37
- | date_to | `str` or `datetime.date` | `None` | "2025-01-01" |
38
- | instrument_id | `str` or `[str]` | `None` | "rpg-fmcw-94" |
39
- | instrument_pid | `str` or `[str]` | `None` | "https://hdl.handle.net/21.12132/3.191564170f8a4686" |
40
- | product\* | `str` or `[str]` | `None` | "classification" |
41
- | show_legacy\* | `bool` | `False` | |
42
-
43
- \* = only in `metadata()`
44
-
45
- **Date Handling**
46
-
47
- The `date` parameter supports:
48
-
49
- - "YYYY-MM-DD" — a specific date
50
- - "YYYY-MM" — the entire month
51
- - "YYYY" — the entire year
52
- - Or directly as `datetime.date` object
53
-
54
- The `date_from` and `date_to` parameters should be "YYYY-MM-DD" or `datetime.date`. If `date` is defined, `date_from` and `date_to` have no effect.
55
-
56
- **Return value**
57
-
58
- Both methods return a list of `dataclass` instances, `ProductMetadata` and `RawMetadata`, respectively.
59
-
60
- ### `APIClient().filter([Metadata])` &rarr; `[Metadata]`
61
-
62
- Additional filtering of fetched metadata.
63
-
64
- Parameters:
65
-
66
- | name | type | default |
67
- | ------------------ | -------------------------------------- | ------- |
68
- | metadata | `[RawMetadata]` or `[ProductMetadata]` | |
69
- | include_pattern | `str` | `None` |
70
- | exclude_pattern | `str` | `None` |
71
- | filename_prefix | `str` | `None` |
72
- | filename_suffix | `str` | `None` |
73
- | include_tag_subset | `{str}` | `None` |
74
- | exclude_tag_subset | `{str}` | `None` |
75
-
76
- ### `cloudnet_api_client.download([Metadata])`
77
-
78
- Function to download files from fetched metadata.
79
-
80
- Parameters:
81
-
82
- | name | type | default |
83
- | ----------------- | -------------------------------------- | ------- |
84
- | metadata | `[RawMetadata]` or `[ProductMetadata]` | |
85
- | output_directory | `PathLike` | |
86
- | concurrency_limit | `int` | 5 |
87
-
88
- ## License
89
-
90
- MIT
@@ -1 +0,0 @@
1
- __version__ = "0.1.0"