geobox 2.0.1__py3-none-any.whl → 2.2.0__py3-none-any.whl

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.
Files changed (70) hide show
  1. geobox/__init__.py +61 -63
  2. geobox/aio/__init__.py +61 -63
  3. geobox/aio/api.py +489 -473
  4. geobox/aio/apikey.py +263 -263
  5. geobox/aio/attachment.py +341 -339
  6. geobox/aio/base.py +261 -262
  7. geobox/aio/basemap.py +196 -196
  8. geobox/aio/dashboard.py +340 -342
  9. geobox/aio/feature.py +23 -33
  10. geobox/aio/field.py +315 -321
  11. geobox/aio/file.py +72 -72
  12. geobox/aio/layout.py +340 -341
  13. geobox/aio/log.py +23 -23
  14. geobox/aio/map.py +1033 -1034
  15. geobox/aio/model3d.py +415 -415
  16. geobox/aio/mosaic.py +696 -696
  17. geobox/aio/plan.py +314 -314
  18. geobox/aio/query.py +693 -693
  19. geobox/aio/raster.py +907 -869
  20. geobox/aio/raster_analysis.py +740 -0
  21. geobox/aio/route.py +4 -4
  22. geobox/aio/scene.py +340 -342
  23. geobox/aio/settings.py +18 -18
  24. geobox/aio/task.py +404 -402
  25. geobox/aio/tile3d.py +337 -339
  26. geobox/aio/tileset.py +102 -103
  27. geobox/aio/usage.py +52 -51
  28. geobox/aio/user.py +506 -507
  29. geobox/aio/vector_tool.py +1968 -0
  30. geobox/aio/vectorlayer.py +315 -306
  31. geobox/aio/version.py +272 -273
  32. geobox/aio/view.py +1019 -983
  33. geobox/aio/workflow.py +340 -341
  34. geobox/api.py +18 -2
  35. geobox/apikey.py +262 -262
  36. geobox/attachment.py +336 -337
  37. geobox/base.py +384 -384
  38. geobox/basemap.py +194 -194
  39. geobox/dashboard.py +339 -341
  40. geobox/enums.py +432 -348
  41. geobox/feature.py +5 -5
  42. geobox/field.py +320 -320
  43. geobox/file.py +4 -4
  44. geobox/layout.py +339 -340
  45. geobox/log.py +4 -4
  46. geobox/map.py +1031 -1032
  47. geobox/model3d.py +410 -410
  48. geobox/mosaic.py +696 -696
  49. geobox/plan.py +313 -313
  50. geobox/query.py +691 -691
  51. geobox/raster.py +907 -863
  52. geobox/raster_analysis.py +737 -0
  53. geobox/scene.py +341 -342
  54. geobox/settings.py +194 -194
  55. geobox/task.py +399 -400
  56. geobox/tile3d.py +337 -338
  57. geobox/tileset.py +4 -4
  58. geobox/usage.py +3 -3
  59. geobox/user.py +503 -503
  60. geobox/vector_tool.py +1968 -0
  61. geobox/vectorlayer.py +5 -5
  62. geobox/version.py +272 -272
  63. geobox/view.py +981 -981
  64. geobox/workflow.py +338 -339
  65. {geobox-2.0.1.dist-info → geobox-2.2.0.dist-info}/METADATA +15 -1
  66. geobox-2.2.0.dist-info/RECORD +72 -0
  67. geobox-2.0.1.dist-info/RECORD +0 -68
  68. {geobox-2.0.1.dist-info → geobox-2.2.0.dist-info}/WHEEL +0 -0
  69. {geobox-2.0.1.dist-info → geobox-2.2.0.dist-info}/licenses/LICENSE +0 -0
  70. {geobox-2.0.1.dist-info → geobox-2.2.0.dist-info}/top_level.txt +0 -0
geobox/aio/base.py CHANGED
@@ -1,262 +1,261 @@
1
- from typing import Any, List, Dict, Callable, TYPE_CHECKING, Union
2
- from urllib.parse import urljoin, urlencode
3
- from datetime import datetime
4
-
5
- from ..utils import clean_data
6
- from ..base import Base as SyncBase
7
-
8
- if TYPE_CHECKING:
9
- from .user import User
10
- from .task import Task
11
- from . import AsyncGeoboxClient
12
-
13
-
14
- class AsyncBase(SyncBase):
15
- BASE_ENDPOINT = ''
16
-
17
- def __init__(self, api, **kwargs):
18
- """
19
- Initialize the Base class.
20
-
21
- Args:
22
- api (AsyncGeoboxClient): The AsyncGeoboxClient client
23
- uuid (str, optional): The UUID of the resource
24
- data (dict, optional): The data of the resource
25
- """
26
- super().__init__(api, **kwargs)
27
-
28
-
29
- @classmethod
30
- async def _get_list(cls, api: 'AsyncGeoboxClient', endpoint: str, params: dict = {},
31
- factory_func: Callable = None, geojson: bool = False) -> Union[List['Base'], int]:
32
- """Get a list of resources with optional filtering and pagination"""
33
- query_string = urlencode(clean_data(params)) if params else ''
34
- endpoint = urljoin(endpoint, f'?{query_string}')
35
- response = await api.get(endpoint)
36
-
37
- if params.get('return_count'):
38
- return cls._get_count(response)
39
-
40
- if not response:
41
- return []
42
-
43
- if geojson:
44
- return cls._handle_geojson_response(api, response, factory_func)
45
-
46
- return [factory_func(api, item) for item in response]
47
-
48
-
49
- @classmethod
50
- async def _get_list_by_ids(cls, api: 'AsyncGeoboxClient', endpoint: str, params: dict = None, factory_func: Callable = None) -> List['Base']:
51
- """
52
- Internal method to get a list of resources by their IDs.
53
-
54
- Args:
55
- api (AsyncGeoboxClient): The AsyncGeoboxClient client
56
- endpoint (str): The endpoint of the resource
57
- params (dict): Additional parameters for filtering and pagination
58
- factory_func (Callable): A function to create the resource object
59
-
60
- Returns:
61
- List[Base]: The list of resource objects
62
- """
63
- params = clean_data(params)
64
- query_string = urlencode(params)
65
- endpoint = urljoin(endpoint, f'?{query_string}')
66
- response = await api.get(endpoint)
67
- return [factory_func(api, item) for item in response]
68
-
69
-
70
- @classmethod
71
- async def _get_detail(cls, api: 'AsyncGeoboxClient', endpoint: str, uuid: str, params: dict = {}, factory_func: Callable = None) -> 'Base':
72
- """
73
- Internal method to get a single resource by UUID.
74
-
75
- Args:
76
- api (AsyncGeoboxClient): The AsyncGeoboxClient client
77
- uuid (str): The UUID of the resource
78
- params (dict): Additional parameters for filtering and pagination
79
- factory_func (Callable): A function to create the resource object
80
-
81
- Returns:
82
- Base: The resource object
83
- """
84
- query_strings = urlencode(clean_data(params))
85
- endpoint = urljoin(endpoint, f'{uuid}/?{query_strings}')
86
- response = await api.get(endpoint)
87
- return factory_func(api, response)
88
-
89
-
90
- @classmethod
91
- async def _create(cls, api: 'AsyncGeoboxClient', endpoint: str, data: dict, factory_func: Callable = None) -> 'Base':
92
- """
93
- Internal method to create a resource.
94
-
95
- Args:
96
- api (AsyncGeoboxClient): The AsyncGeoboxClient client
97
- data (dict): The data to create the resource with
98
- factory_func (Callable): A function to create the resource object
99
-
100
- Returns:
101
- Base: The created resource object
102
- """
103
- data = clean_data(data)
104
- response = await api.post(endpoint, data)
105
- return factory_func(api, response)
106
-
107
-
108
- async def _update(self, endpoint: str, data: dict, clean: bool = True) -> Dict:
109
- """
110
- Update the resource.
111
-
112
- Args:
113
- data (dict): The data to update the resource with
114
- """
115
- if clean:
116
- data = clean_data(data)
117
-
118
- response = await self.api.put(endpoint, data)
119
- self._update_properties(response)
120
- return response
121
-
122
-
123
- async def delete(self, endpoint: str) -> None:
124
- """
125
- Delete the resource.
126
- """
127
- await self.api.delete(endpoint)
128
- self.uuid = None
129
- self.endpoint = None
130
-
131
-
132
- async def _share(self, endpoint: str, users: List['User']) -> None:
133
- """
134
- Internal method to share the resource with the given user IDs.
135
-
136
- Args:
137
- users (List[User]): The user objects to share the resource with
138
- """
139
- data = {"user_ids": [user.user_id for user in users]}
140
- endpoint = urljoin(endpoint, f'share/')
141
- await self.api.post(endpoint, data, is_json=False)
142
-
143
-
144
- async def _unshare(self, endpoint: str, users: List['User']) -> None:
145
- """
146
- Internal method to unshare the resource with the given user IDs.
147
-
148
- Args:
149
- users (List[User]): The user objects to unshare the resource with
150
- """
151
- data = {"user_ids": [user.user_id for user in users]}
152
- endpoint = urljoin(endpoint, f'unshare/')
153
- await self.api.post(endpoint, data, is_json=False)
154
-
155
-
156
- async def _get_shared_users(self, endpoint: str, params: dict = None) -> List['User']:
157
- """
158
- Internal method to get the users that the resource is shared with.
159
-
160
- Args:
161
- endpoint (str): resource endpoint
162
- params (dict): Additional parameters for filtering and pagination
163
-
164
- Returns:
165
- List[User]: The users that the resource is shared with
166
- """
167
- from .user import User
168
-
169
- params = clean_data(params)
170
- query_strings = urlencode(params)
171
- endpoint = urljoin(endpoint, f'shared-with-users/?{query_strings}')
172
- response = await self.api.get(endpoint)
173
- return [User(self.api, item['id'], item) for item in response]
174
-
175
-
176
- async def _get_settings(self, endpoint: str) -> Dict:
177
- """
178
- Internal method to get the settings of the resource.
179
-
180
- Args:
181
- endpoint (str): The endpoint of the resource
182
- """
183
- endpoint = urljoin(endpoint, f'settings/?f=json')
184
- return await self.api.get(endpoint)
185
-
186
-
187
- async def _set_settings(self, endpoint: str, data: dict) -> None:
188
- """
189
- Internal method to set the settings of the resource.
190
-
191
- Args:
192
- endpoint (str): The endpoint of the resource
193
- data (dict): The data to set the settings with
194
- """
195
- endpoint = urljoin(endpoint, f'settings/')
196
- return await self.api.put(endpoint, data)
197
-
198
-
199
- async def _get_task(self, response, error_message: str) -> List['Task']:
200
- from .task import Task # avoid circular dependency
201
-
202
- if len(response) == 1 and isinstance(response, list) and response[0].get('task_id'):
203
- result = [await self.api.get_task(response[0].get('task_id'))]
204
- elif len(response) == 2 and isinstance(response, list) and (response[0].get('task_id') and response[1].get('task_id')):
205
- result = [await self.api.get_task(item.get('task_id')) for item in response]
206
- elif len(response) == 1 and isinstance(response, dict) and response.get('task_id'):
207
- result = [await self.api.get_task(response.get('task_id'))]
208
- else:
209
- raise ValueError(error_message)
210
-
211
- return result
212
-
213
-
214
- async def _seed_cache(self, endpoint: str, data: dict) -> List['Task']:
215
- """
216
- Internal method to cache seed the resource.
217
-
218
- Args:
219
- endpoint (str): The endpoint of the resource
220
- data (dict): The data to cache seed with
221
- """
222
- if data['workers'] not in [1, 2, 4, 8, 12, 16, 20, 24]:
223
- raise ValueError("workers must be in [1, 2, 4, 8, 12, 16, 20, 24]")
224
-
225
- data = clean_data(data)
226
- endpoint = urljoin(endpoint, f'cache/seed/')
227
- response = await self.api.post(endpoint, data)
228
- return await self._get_task(response, 'Failed to seed cache')
229
-
230
- async def _clear_cache(self, endpoint: str) -> None:
231
- """
232
- Internal method to clear the cache of the resource.
233
-
234
- Args:
235
- endpoint (str): The endpoint of the resource
236
- """
237
- endpoint = urljoin(endpoint, f'cache/clear/')
238
- await self.api.post(endpoint)
239
-
240
-
241
- async def _cache_size(self, endpoint: str) -> int:
242
- """
243
- Internal method to get the size of the cache of the resource.
244
-
245
- Args:
246
- endpoint (str): The endpoint of the resource
247
- """
248
- endpoint = urljoin(endpoint, f'cache/size/')
249
- return await self.api.post(endpoint)
250
-
251
-
252
- async def _update_cache(self, endpoint: str, data: Dict = {}) -> List['Task']:
253
- """
254
- Internal method to update the cache of the resource.
255
-
256
- Args:
257
- endpoint (str): The endpoint of the resource
258
- """
259
- data = clean_data(data)
260
- endpoint = urljoin(endpoint, 'cache/update/')
261
- response = await self.api.post(endpoint, data)
262
- return await self._get_task(response, 'Failed to update cache')
1
+ from typing import List, Dict, Callable, TYPE_CHECKING, Union
2
+ from urllib.parse import urljoin, urlencode
3
+
4
+ from ..utils import clean_data
5
+ from ..base import Base
6
+
7
+ if TYPE_CHECKING:
8
+ from .user import AsyncUser
9
+ from .task import AsyncTask
10
+ from . import AsyncGeoboxClient
11
+
12
+
13
+ class AsyncBase(Base):
14
+ BASE_ENDPOINT = ''
15
+
16
+ def __init__(self, api, **kwargs):
17
+ """
18
+ Initialize the Base class.
19
+
20
+ Args:
21
+ api (AsyncGeoboxClient): The AsyncGeoboxClient client
22
+ uuid (str, optional): The UUID of the resource
23
+ data (dict, optional): The data of the resource
24
+ """
25
+ super().__init__(api, **kwargs)
26
+
27
+
28
+ @classmethod
29
+ async def _get_list(cls, api: 'AsyncGeoboxClient', endpoint: str, params: dict = {}, factory_func: Callable = None, geojson: bool = False) -> Union[List['Base'], int]:
30
+ """Get a list of resources with optional filtering and pagination"""
31
+ query_string = urlencode(clean_data(params)) if params else ''
32
+ endpoint = urljoin(endpoint, f'?{query_string}')
33
+ response = await api.get(endpoint)
34
+
35
+ if params.get('return_count'):
36
+ return cls._get_count(response)
37
+
38
+ if not response:
39
+ return []
40
+
41
+ if geojson:
42
+ return cls._handle_geojson_response(api, response, factory_func)
43
+
44
+ return [factory_func(api, item) for item in response]
45
+
46
+
47
+ @classmethod
48
+ async def _get_list_by_ids(cls, api: 'AsyncGeoboxClient', endpoint: str, params: dict = None, factory_func: Callable = None) -> List['Base']:
49
+ """
50
+ Internal method to get a list of resources by their IDs.
51
+
52
+ Args:
53
+ api (AsyncGeoboxClient): The AsyncGeoboxClient client
54
+ endpoint (str): The endpoint of the resource
55
+ params (dict): Additional parameters for filtering and pagination
56
+ factory_func (Callable): A function to create the resource object
57
+
58
+ Returns:
59
+ List[Base]: The list of resource objects
60
+ """
61
+ params = clean_data(params)
62
+ query_string = urlencode(params)
63
+ endpoint = urljoin(endpoint, f'?{query_string}')
64
+ response = await api.get(endpoint)
65
+ return [factory_func(api, item) for item in response]
66
+
67
+
68
+ @classmethod
69
+ async def _get_detail(cls, api: 'AsyncGeoboxClient', endpoint: str, uuid: str, params: dict = {}, factory_func: Callable = None) -> 'Base':
70
+ """
71
+ Internal method to get a single resource by UUID.
72
+
73
+ Args:
74
+ api (AsyncGeoboxClient): The AsyncGeoboxClient client
75
+ uuid (str): The UUID of the resource
76
+ params (dict): Additional parameters for filtering and pagination
77
+ factory_func (Callable): A function to create the resource object
78
+
79
+ Returns:
80
+ Base: The resource object
81
+ """
82
+ query_strings = urlencode(clean_data(params))
83
+ endpoint = urljoin(endpoint, f'{uuid}/?{query_strings}')
84
+ response = await api.get(endpoint)
85
+ return factory_func(api, response)
86
+
87
+
88
+ @classmethod
89
+ async def _create(cls, api: 'AsyncGeoboxClient', endpoint: str, data: dict, factory_func: Callable = None) -> 'Base':
90
+ """
91
+ Internal method to create a resource.
92
+
93
+ Args:
94
+ api (AsyncGeoboxClient): The AsyncGeoboxClient client
95
+ data (dict): The data to create the resource with
96
+ factory_func (Callable): A function to create the resource object
97
+
98
+ Returns:
99
+ Base: The created resource object
100
+ """
101
+ data = clean_data(data)
102
+ response = await api.post(endpoint, data)
103
+ return factory_func(api, response)
104
+
105
+
106
+ async def _update(self, endpoint: str, data: dict, clean: bool = True) -> Dict:
107
+ """
108
+ Update the resource.
109
+
110
+ Args:
111
+ data (dict): The data to update the resource with
112
+ """
113
+ if clean:
114
+ data = clean_data(data)
115
+
116
+ response = await self.api.put(endpoint, data)
117
+ self._update_properties(response)
118
+ return response
119
+
120
+
121
+ async def _delete(self, endpoint: str) -> None:
122
+ """
123
+ Delete the resource.
124
+ """
125
+ await self.api.delete(endpoint)
126
+ self.uuid = None
127
+ self.endpoint = None
128
+
129
+
130
+ async def _share(self, endpoint: str, users: List['AsyncUser']) -> None:
131
+ """
132
+ Internal method to share the resource with the given user IDs.
133
+
134
+ Args:
135
+ users (List[AsyncUser]): The user objects to share the resource with
136
+ """
137
+ data = {"user_ids": [user.user_id for user in users]}
138
+ endpoint = urljoin(endpoint, f'share/')
139
+ await self.api.post(endpoint, data, is_json=False)
140
+
141
+
142
+ async def _unshare(self, endpoint: str, users: List['AsyncUser']) -> None:
143
+ """
144
+ Internal method to unshare the resource with the given user IDs.
145
+
146
+ Args:
147
+ users (List[AsyncUser]): The user objects to unshare the resource with
148
+ """
149
+ data = {"user_ids": [user.user_id for user in users]}
150
+ endpoint = urljoin(endpoint, f'unshare/')
151
+ await self.api.post(endpoint, data, is_json=False)
152
+
153
+
154
+ async def _get_shared_users(self, endpoint: str, params: dict = None) -> List['AsyncUser']:
155
+ """
156
+ Internal method to get the users that the resource is shared with.
157
+
158
+ Args:
159
+ endpoint (str): resource endpoint
160
+ params (dict): Additional parameters for filtering and pagination
161
+
162
+ Returns:
163
+ List[AsyncUser]: The users that the resource is shared with
164
+ """
165
+ from .user import AsyncUser
166
+
167
+ params = clean_data(params)
168
+ query_strings = urlencode(params)
169
+ endpoint = urljoin(endpoint, f'shared-with-users/?{query_strings}')
170
+ response = await self.api.get(endpoint)
171
+ return [AsyncUser(self.api, item['id'], item) for item in response]
172
+
173
+
174
+ async def _get_settings(self, endpoint: str) -> Dict:
175
+ """
176
+ Internal method to get the settings of the resource.
177
+
178
+ Args:
179
+ endpoint (str): The endpoint of the resource
180
+ """
181
+ endpoint = urljoin(endpoint, f'settings/?f=json')
182
+ return await self.api.get(endpoint)
183
+
184
+
185
+ async def _set_settings(self, endpoint: str, data: dict) -> None:
186
+ """
187
+ Internal method to set the settings of the resource.
188
+
189
+ Args:
190
+ endpoint (str): The endpoint of the resource
191
+ data (dict): The data to set the settings with
192
+ """
193
+ endpoint = urljoin(endpoint, f'settings/')
194
+ return await self.api.put(endpoint, data)
195
+
196
+
197
+ async def _get_task(self, response, error_message: str) -> List['AsyncUser']:
198
+ from .task import AsyncTask # avoid circular dependency
199
+
200
+ if len(response) == 1 and isinstance(response, list) and response[0].get('task_id'):
201
+ result = [await self.api.get_task(response[0].get('task_id'))]
202
+ elif len(response) == 2 and isinstance(response, list) and (response[0].get('task_id') and response[1].get('task_id')):
203
+ result = [await self.api.get_task(item.get('task_id')) for item in response]
204
+ elif len(response) == 1 and isinstance(response, dict) and response.get('task_id'):
205
+ result = [await self.api.get_task(response.get('task_id'))]
206
+ else:
207
+ raise ValueError(error_message)
208
+
209
+ return result
210
+
211
+
212
+ async def _seed_cache(self, endpoint: str, data: dict) -> List['AsyncTask']:
213
+ """
214
+ Internal method to cache seed the resource.
215
+
216
+ Args:
217
+ endpoint (str): The endpoint of the resource
218
+ data (dict): The data to cache seed with
219
+ """
220
+ if data['workers'] not in [1, 2, 4, 8, 12, 16, 20, 24]:
221
+ raise ValueError("workers must be in [1, 2, 4, 8, 12, 16, 20, 24]")
222
+
223
+ data = clean_data(data)
224
+ endpoint = urljoin(endpoint, f'cache/seed/')
225
+ response = await self.api.post(endpoint, data)
226
+ return await self._get_task(response, 'Failed to seed cache')
227
+
228
+
229
+ async def _clear_cache(self, endpoint: str) -> None:
230
+ """
231
+ Internal method to clear the cache of the resource.
232
+
233
+ Args:
234
+ endpoint (str): The endpoint of the resource
235
+ """
236
+ endpoint = urljoin(endpoint, f'cache/clear/')
237
+ await self.api.post(endpoint)
238
+
239
+
240
+ async def _cache_size(self, endpoint: str) -> int:
241
+ """
242
+ Internal method to get the size of the cache of the resource.
243
+
244
+ Args:
245
+ endpoint (str): The endpoint of the resource
246
+ """
247
+ endpoint = urljoin(endpoint, f'cache/size/')
248
+ return await self.api.post(endpoint)
249
+
250
+
251
+ async def _update_cache(self, endpoint: str, data: Dict = {}) -> List['AsyncTask']:
252
+ """
253
+ Internal method to update the cache of the resource.
254
+
255
+ Args:
256
+ endpoint (str): The endpoint of the resource
257
+ """
258
+ data = clean_data(data)
259
+ endpoint = urljoin(endpoint, 'cache/update/')
260
+ response = await self.api.post(endpoint, data)
261
+ return await self._get_task(response, 'Failed to update cache')