geobox 1.4.2__py3-none-any.whl → 2.0.1__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 (66) hide show
  1. geobox/__init__.py +2 -2
  2. geobox/aio/__init__.py +63 -0
  3. geobox/aio/api.py +2640 -0
  4. geobox/aio/apikey.py +263 -0
  5. geobox/aio/attachment.py +339 -0
  6. geobox/aio/base.py +262 -0
  7. geobox/aio/basemap.py +196 -0
  8. geobox/aio/dashboard.py +342 -0
  9. geobox/aio/feature.py +527 -0
  10. geobox/aio/field.py +321 -0
  11. geobox/aio/file.py +522 -0
  12. geobox/aio/layout.py +341 -0
  13. geobox/aio/log.py +145 -0
  14. geobox/aio/map.py +1034 -0
  15. geobox/aio/model3d.py +415 -0
  16. geobox/aio/mosaic.py +696 -0
  17. geobox/aio/plan.py +315 -0
  18. geobox/aio/query.py +693 -0
  19. geobox/aio/raster.py +869 -0
  20. geobox/aio/route.py +63 -0
  21. geobox/aio/scene.py +342 -0
  22. geobox/aio/settings.py +194 -0
  23. geobox/aio/task.py +402 -0
  24. geobox/aio/tile3d.py +339 -0
  25. geobox/aio/tileset.py +672 -0
  26. geobox/aio/usage.py +243 -0
  27. geobox/aio/user.py +507 -0
  28. geobox/aio/vectorlayer.py +1363 -0
  29. geobox/aio/version.py +273 -0
  30. geobox/aio/view.py +983 -0
  31. geobox/aio/workflow.py +341 -0
  32. geobox/api.py +14 -15
  33. geobox/apikey.py +28 -1
  34. geobox/attachment.py +27 -1
  35. geobox/base.py +4 -4
  36. geobox/basemap.py +30 -1
  37. geobox/dashboard.py +27 -0
  38. geobox/feature.py +33 -13
  39. geobox/field.py +33 -21
  40. geobox/file.py +40 -46
  41. geobox/layout.py +28 -1
  42. geobox/log.py +31 -7
  43. geobox/map.py +34 -2
  44. geobox/model3d.py +31 -37
  45. geobox/mosaic.py +28 -7
  46. geobox/plan.py +29 -3
  47. geobox/query.py +39 -14
  48. geobox/raster.py +26 -13
  49. geobox/scene.py +26 -0
  50. geobox/settings.py +30 -1
  51. geobox/task.py +28 -6
  52. geobox/tile3d.py +27 -1
  53. geobox/tileset.py +26 -5
  54. geobox/usage.py +32 -1
  55. geobox/user.py +62 -6
  56. geobox/utils.py +34 -0
  57. geobox/vectorlayer.py +40 -4
  58. geobox/version.py +25 -1
  59. geobox/view.py +37 -17
  60. geobox/workflow.py +27 -1
  61. {geobox-1.4.2.dist-info → geobox-2.0.1.dist-info}/METADATA +4 -1
  62. geobox-2.0.1.dist-info/RECORD +68 -0
  63. geobox-1.4.2.dist-info/RECORD +0 -38
  64. {geobox-1.4.2.dist-info → geobox-2.0.1.dist-info}/WHEEL +0 -0
  65. {geobox-1.4.2.dist-info → geobox-2.0.1.dist-info}/licenses/LICENSE +0 -0
  66. {geobox-1.4.2.dist-info → geobox-2.0.1.dist-info}/top_level.txt +0 -0
geobox/aio/layout.py ADDED
@@ -0,0 +1,341 @@
1
+ from typing import List, Dict, Optional, TYPE_CHECKING, Union
2
+
3
+ from .base import AsyncBase
4
+
5
+ if TYPE_CHECKING:
6
+ from . import AsyncGeoboxClient
7
+ from .user import User
8
+ from ..api import GeoboxClient as SyncGeoboxClient
9
+ from ..layout import Layout as SyncLayout
10
+
11
+
12
+ class Layout(AsyncBase):
13
+
14
+ BASE_ENDPOINT = 'layouts/'
15
+
16
+ def __init__(self,
17
+ api: 'AsyncGeoboxClient',
18
+ uuid: str,
19
+ data: Optional[Dict] = {}):
20
+ """
21
+ Initialize a layout instance.
22
+
23
+ Args:
24
+ api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
25
+ uuid (str): The unique identifier for the layout.
26
+ data (Dict): The data of the layout.
27
+ """
28
+ super().__init__(api, uuid=uuid, data=data)
29
+
30
+
31
+ @classmethod
32
+ async def get_layouts(cls, api: 'AsyncGeoboxClient', **kwargs) -> Union[List['Layout'], int]:
33
+ """
34
+ Get list of layouts with optional filtering and pagination.
35
+
36
+ Args:
37
+ api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
38
+
39
+ Keyword Args:
40
+ q (str): query filter based on OGC CQL standard. e.g. "field1 LIKE '%GIS%' AND created_at > '2021-01-01'"
41
+ search (str): search term for keyword-based searching among search_fields or all textual fields if search_fields does not have value. NOTE: if q param is defined this param will be ignored.
42
+ search_fields (str): comma separated list of fields for searching.
43
+ order_by (str): comma separated list of fields for sorting results [field1 A|D, field2 A|D, …]. e.g. name A, type D. NOTE: "A" denotes ascending order and "D" denotes descending order.
44
+ return_count (bool): Whether to return total count. default is False.
45
+ skip (int): Number of items to skip. default is 0.
46
+ limit (int): Number of items to return. default is 10.
47
+ user_id (int): Specific user. privileges required.
48
+ shared (bool): Whether to return shared layouts. default is False.
49
+
50
+ Returns:
51
+ List[Layout] | int: A list of layout instances or the total number of layouts.
52
+
53
+ Example:
54
+ >>> from geobox.aio import AsyncGeoboxClient
55
+ >>> from geobox.aio.layout import Layout
56
+ >>> async with AsyncGeoboxClient() as client:
57
+ >>> layouts = await Layout.get_layout(client, q="name LIKE '%My layout%'")
58
+ or
59
+ >>> layouts = await client.get_layout(q="name LIKE '%My layout%'")
60
+ """
61
+ params = {
62
+ 'f': 'json',
63
+ 'q': kwargs.get('q'),
64
+ 'search': kwargs.get('search'),
65
+ 'search_fields': kwargs.get('search_fields'),
66
+ 'order_by': kwargs.get('order_by'),
67
+ 'return_count': kwargs.get('return_count', False),
68
+ 'skip': kwargs.get('skip', 0),
69
+ 'limit': kwargs.get('limit', 10),
70
+ 'user_id': kwargs.get('user_id'),
71
+ 'shared': kwargs.get('shared', False)
72
+ }
73
+ return await super()._get_list(api, cls.BASE_ENDPOINT, params, factory_func=lambda api, item: Layout(api, item['uuid'], item))
74
+
75
+
76
+ @classmethod
77
+ async def create_layout(cls,
78
+ api: 'AsyncGeoboxClient',
79
+ name: str,
80
+ display_name: str = None,
81
+ description: str = None,
82
+ settings: Dict = {},
83
+ thumbnail: str = None,
84
+ user_id: int = None) -> 'Layout':
85
+ """
86
+ Create a new layout.
87
+
88
+ Args:
89
+ api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
90
+ name (str): The name of the Layout.
91
+ display_name (str): The display name of the layout.
92
+ description (str): The description of the layout.
93
+ settings (Dict): The settings of the layout.
94
+ thumbnail (str): The thumbnail of the layout.
95
+ user_id (int): Specific user. privileges layout.
96
+
97
+ Returns:
98
+ Layout: The newly created layout instance.
99
+
100
+ Raises:
101
+ ValidationError: If the layout data is invalid.
102
+
103
+ Example:
104
+ >>> from geobox.aio import AsyncGeoboxClient
105
+ >>> from geobox.aio.layout import Layout
106
+ >>> async with AsyncGeoboxClient() as client:
107
+ >>> layout = await Layout.create_layout(client, name="my_layout")
108
+ or
109
+ >>> layout = await client.create_layout(name="my_layout")
110
+ """
111
+ data = {
112
+ "name": name,
113
+ "display_name": display_name,
114
+ "description": description,
115
+ "settings": settings,
116
+ "thumbnail": thumbnail,
117
+ "user_id": user_id,
118
+ }
119
+ return await super()._create(api, cls.BASE_ENDPOINT, data, factory_func=lambda api, item: Layout(api, item['uuid'], item))
120
+
121
+
122
+ @classmethod
123
+ async def get_layout(cls, api: 'AsyncGeoboxClient', uuid: str, user_id: int = None) -> 'Layout':
124
+ """
125
+ Get a layout by its UUID.
126
+
127
+ Args:
128
+ api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
129
+ uuid (str): The UUID of the layout to get.
130
+ user_id (int): Specific user. privileges required.
131
+
132
+ Returns:
133
+ Layout: The layout object.
134
+
135
+ Raises:
136
+ NotFoundError: If the layout with the specified UUID is not found.
137
+
138
+ Example:
139
+ >>> from geobox.aio import AsyncGeoboxClient
140
+ >>> from geobox.aio.layout import Layout
141
+ >>> async with AsyncGeoboxClient() as client:
142
+ >>> layout = await Layout.get_layout(client, uuid="12345678-1234-5678-1234-567812345678")
143
+ or
144
+ >>> layout = await client.get_layout(uuid="12345678-1234-5678-1234-567812345678")
145
+ """
146
+ params = {
147
+ 'f': 'json',
148
+ 'user_id': user_id,
149
+ }
150
+ return await super()._get_detail(api, cls.BASE_ENDPOINT, uuid, params, factory_func=lambda api, item: Layout(api, item['uuid'], item))
151
+
152
+
153
+ @classmethod
154
+ async def get_layout_by_name(cls, api: 'AsyncGeoboxClient', name: str, user_id: int = None) -> Union['Layout', None]:
155
+ """
156
+ Get a layout by name
157
+
158
+ Args:
159
+ api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
160
+ name (str): the name of the layout to get
161
+ user_id (int, optional): specific user. privileges required.
162
+
163
+ Returns:
164
+ Layout | None: returns the layout if a layout matches the given name, else None
165
+
166
+ Example:
167
+ >>> from geobox.aio import AsyncGeoboxClient
168
+ >>> from geobox.aio.layout import Layout
169
+ >>> async with AsyncGeoboxClient() as client:
170
+ >>> layout = await Layout.get_layout_by_name(client, name='test')
171
+ or
172
+ >>> layout = await client.get_layout_by_name(name='test')
173
+ """
174
+ layouts = await cls.get_layouts(api, q=f"name = '{name}'", user_id=user_id)
175
+ if layouts and layouts[0].name == name:
176
+ return layouts[0]
177
+ else:
178
+ return None
179
+
180
+
181
+ async def update(self, **kwargs) -> Dict:
182
+ """
183
+ Update the layout.
184
+
185
+ Keyword Args:
186
+ name (str): The name of the layout.
187
+ display_name (str): The display name of the layout.
188
+ description (str): The description of the layout.
189
+ settings (Dict): The settings of the layout.
190
+ thumbnail (str): The thumbnail of the layout.
191
+
192
+ Returns:
193
+ Dict: The updated layout data.
194
+
195
+ Raises:
196
+ ValidationError: If the layout data is invalid.
197
+
198
+ Example:
199
+ >>> from geobox.aio import AsyncGeoboxClient
200
+ >>> from geobox.aio.layout import Layout
201
+ >>> async with AsyncGeoboxClient() as client:
202
+ >>> layout = await Layout.get_layout(client, uuid="12345678-1234-5678-1234-567812345678")
203
+ >>> await layout.update(display_name="New Display Name")
204
+ """
205
+ data = {
206
+ "name": kwargs.get('name'),
207
+ "display_name": kwargs.get('display_name'),
208
+ "description": kwargs.get('description'),
209
+ "settings": kwargs.get('settings'),
210
+ "thumbnail": kwargs.get('thumbnail')
211
+ }
212
+ return await super()._update(self.endpoint, data)
213
+
214
+
215
+ async def delete(self) -> None:
216
+ """
217
+ Delete the Layout.
218
+
219
+ Returns:
220
+ None
221
+
222
+ Example:
223
+ >>> from geobox.aio import AsyncGeoboxClient
224
+ >>> from geobox.aio.layout import Layout
225
+ >>> async with AsyncGeoboxClient() as client:
226
+ >>> layout = await Layout.get_layout(client, uuid="12345678-1234-5678-1234-567812345678")
227
+ >>> await layout.delete()
228
+ """
229
+ await super().delete(self.endpoint)
230
+
231
+
232
+ @property
233
+ def thumbnail(self) -> str:
234
+ """
235
+ Get the thumbnail URL of the Layout.
236
+
237
+ Returns:
238
+ str: The thumbnail of the Layout.
239
+
240
+ Example:
241
+ >>> from geobox.aio import AsyncGeoboxClient
242
+ >>> from geobox.aio.layout import Layout
243
+ >>> async with AsyncGeoboxClient() as client:
244
+ >>> layout = await Layout.get_layout(client, uuid="12345678-1234-5678-1234-567812345678")
245
+ >>> layout.thumbnail
246
+ 'https://example.com/thumbnail.png'
247
+ """
248
+ return super().thumbnail()
249
+
250
+
251
+ async def share(self, users: List['User']) -> None:
252
+ """
253
+ Shares the layout with specified users.
254
+
255
+ Args:
256
+ users (List[User]): The list of user objects to share the layout with.
257
+
258
+ Returns:
259
+ None
260
+
261
+ Example:
262
+ >>> from geobox.aio import AsyncGeoboxClient
263
+ >>> from geobox.aio.layout import Layout
264
+ >>> async with AsyncGeoboxClient() as client:
265
+ >>> layout = await Layout.get_layout(client, uuid="12345678-1234-5678-1234-567812345678")
266
+ >>> await users = client.search_users(search='John')
267
+ >>> await layout.share(users=users)
268
+ """
269
+ await super()._share(self.endpoint, users)
270
+
271
+
272
+ async def unshare(self, users: List['User']) -> None:
273
+ """
274
+ Unshares the layout with specified users.
275
+
276
+ Args:
277
+ users (List[User]): The list of user objects to unshare the layout with.
278
+
279
+ Returns:
280
+ None
281
+
282
+ Example:
283
+ >>> from geobox.aio import AsyncGeoboxClient
284
+ >>> from geobox.aio.layout import Layout
285
+ >>> async with AsyncGeoboxClient() as client:
286
+ >>> layout = await Layout.get_layout(client, uuid="12345678-1234-5678-1234-567812345678")
287
+ >>> users = await client.search_users(search='John')
288
+ >>> await layout.unshare(users=users)
289
+ """
290
+ await super()._unshare(self.endpoint, users)
291
+
292
+
293
+ async def get_shared_users(self, search: str = None, skip: int = 0, limit: int = 10) -> List['User']:
294
+ """
295
+ Retrieves the list of users the layout is shared with.
296
+
297
+ Args:
298
+ search (str, optional): The search query.
299
+ skip (int, optional): The number of users to skip.
300
+ limit (int, optional): The maximum number of users to retrieve.
301
+
302
+ Returns:
303
+ List[User]: The list of shared users.
304
+
305
+ Example:
306
+ >>> from geobox.aio import AsyncGeoboxClient
307
+ >>> from geobox.aio.layout import Layout
308
+ >>> async with AsyncGeoboxClient() as client:
309
+ >>> layout = await Layout.get_layout(client, uuid="12345678-1234-5678-1234-567812345678")
310
+ >>> await layout.get_shared_users(search='John', skip=0, limit=10)
311
+ """
312
+ params = {
313
+ 'search': search,
314
+ 'skip': skip,
315
+ 'limit': limit
316
+ }
317
+ return await super()._get_shared_users(self.endpoint, params)
318
+
319
+
320
+ def to_sync(self, sync_client: 'SyncGeoboxClient') -> 'SyncLayout':
321
+ """
322
+ Switch to sync version of the layout instance to have access to the sync methods
323
+
324
+ Args:
325
+ sync_client (SyncGeoboxClient): The sync version of the GeoboxClient instance for making requests.
326
+
327
+ Returns:
328
+ geobox.layout.Layout: the sync instance of the layout.
329
+
330
+ Example:
331
+ >>> from geobox import Geoboxclient
332
+ >>> from geobox.aio import AsyncGeoboxClient
333
+ >>> from geobox.aio.layout import Layout
334
+ >>> client = GeoboxClient()
335
+ >>> async with AsyncGeoboxClient() as async_client:
336
+ >>> layout = await Layout.get_layout(async_client, uuid="12345678-1234-5678-1234-567812345678")
337
+ >>> sync_layout = layout.to_sync(client)
338
+ """
339
+ from ..layout import Layout as SyncLayout
340
+
341
+ return SyncLayout(api=sync_client, uuid=self.uuid, data=self.data)
geobox/aio/log.py ADDED
@@ -0,0 +1,145 @@
1
+ from typing import Optional, Dict, List, Union, TYPE_CHECKING
2
+
3
+ from .base import AsyncBase
4
+
5
+ if TYPE_CHECKING:
6
+ from . import AsyncGeoboxClient
7
+ from .user import User
8
+ from ..api import GeoboxClient as SyncGeoboxClient
9
+ from ..log import Log as SyncLog
10
+
11
+
12
+ class Log(AsyncBase):
13
+
14
+ BASE_ENDPOINT = 'logs/'
15
+
16
+ def __init__(self,
17
+ api: 'AsyncGeoboxClient',
18
+ log_id: int,
19
+ data: Optional[Dict] = {}):
20
+ """
21
+ Constructs all the necessary attributes for the Log object.
22
+
23
+ Args:
24
+ api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
25
+ log_id (int): The id of the log.
26
+ data (Dict, optional): The data of the log.
27
+ """
28
+ super().__init__(api, data=data)
29
+ self.log_id = log_id
30
+ self.endpoint = f"{self.BASE_ENDPOINT}{self.log_id}"
31
+
32
+
33
+ def __repr__(self) -> str:
34
+ """
35
+ Return a string representation of the Log object.
36
+
37
+ Returns:
38
+ str: A string representation of the Log object.
39
+ """
40
+ return f"Log(id={self.log_id}, activity_type={self.activity_type})"
41
+
42
+
43
+ @classmethod
44
+ async def get_logs(cls, api: 'AsyncGeoboxClient', **kwargs) -> List['Log']:
45
+ """
46
+ [async] Get a list of Logs
47
+
48
+ Args:
49
+ api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
50
+
51
+ Keyword Args:
52
+ search (str): search term for keyword-based searching among all textual fields
53
+ order_by (str): comma separated list of fields for sorting results [field1 A|D, field2 A|D, …]. e.g. name A, type D. NOTE: "A" denotes ascending order and "D" denotes descending order.
54
+ skip (int): Number of items to skip. default is 0.
55
+ limit (int): Number of items to return. default is 10.
56
+ user_id (int): Specific user. Privileges required.
57
+ from_date (datetime): datetime object in this format: "%Y-%m-%dT%H:%M:%S.%f".
58
+ to_date (datetime): datetime object in this format: "%Y-%m-%dT%H:%M:%S.%f".
59
+ user_identity (str): the user identity in this format: username - firstname lastname - email .
60
+ activity_type (str): the user activity type.
61
+
62
+ Returns:
63
+ List[Log]: a list of logs
64
+
65
+ Example:
66
+ >>> from geobox.aio import AsyncGeoboxClient
67
+ >>> from geopox.aio.log import Log
68
+ >>> async with AsyncGeoboxClient() as client:
69
+ >>> logs = await Log.get_logs(client)
70
+ or
71
+ >>> logs = await client.get_logs()
72
+ """
73
+ params = {
74
+ 'search': kwargs.get('search'),
75
+ 'order_by': kwargs.get('order_by'),
76
+ 'skip': kwargs.get('skip'),
77
+ 'limit': kwargs.get('limit'),
78
+ 'user_id': kwargs.get('user_id'),
79
+ 'from_date': kwargs.get('from_date').strftime("%Y-%m-%dT%H:%M:%S.%f") if kwargs.get('from_date') else None,
80
+ 'to_date': kwargs.get('to_date').strftime("%Y-%m-%dT%H:%M:%S.%f") if kwargs.get('to_date') else None,
81
+ 'user_identity': kwargs.get('user_identity'),
82
+ 'activity_type': kwargs.get('activity_type')
83
+ }
84
+ return await super()._get_list(api, cls.BASE_ENDPOINT, params, factory_func=lambda api, item: Log(api, item['id'], item))
85
+
86
+
87
+ async def delete(self) -> None:
88
+ """
89
+ [async] Delete a log (privileges required)
90
+
91
+ Returns:
92
+ None
93
+
94
+ Example:
95
+ >>> from geobox.aio import AsyncGeoboxClient
96
+ >>> from geopox.aio.log import Log
97
+ >>> async with AsyncGeoboxClient() as client:
98
+ >>> log = await Log.get_logs(client)[0]
99
+ >>> await log.delete()
100
+ """
101
+ await super().delete(self.endpoint)
102
+ self.log_id = None
103
+
104
+
105
+ @property
106
+ async def user(self) -> Union['User', None]:
107
+ """
108
+ [async] Get the owner user for the log
109
+
110
+ Returns:
111
+ User | None: if the log has owner user
112
+
113
+ Example:
114
+ >>> from geobox.aio import AsyncGeoboxClient
115
+ >>> from geopox.aio.log import Log
116
+ >>> async with AsyncGeoboxClient() as client:
117
+ >>> log = await Log.get_logs(client)[0]
118
+ >>> await log.user
119
+ """
120
+ return await self.api.get_user(self.owner_id)
121
+
122
+
123
+ def to_sync(self, sync_client: 'SyncGeoboxClient') -> 'SyncLog':
124
+ """
125
+ Switch to sync version of the log instance to have access to the sync methods
126
+
127
+ Args:
128
+ sync_client (SyncGeoboxClient): The sync version of the GeoboxClient instance for making requests.
129
+
130
+ Returns:
131
+ geobox.log.Log: the sync instance of the log.
132
+
133
+ Example:
134
+ >>> from geobox import Geoboxclient
135
+ >>> from geobox.aio import AsyncGeoboxClient
136
+ >>> from geopox.aio.log import Log
137
+ >>> client = GeoboxClient()
138
+ >>> async with AsyncGeoboxClient() as async_client:
139
+ >>> logs = await Log.get_logs(async_client)
140
+ >>> log = logs[0]
141
+ >>> sync_log = log.to_sync(client)
142
+ """
143
+ from ..log import Log as SyncLog
144
+
145
+ return SyncLog(api=sync_client, log_id=self.log_id, data=self.data)