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/api.py CHANGED
@@ -2,9 +2,11 @@ import requests
2
2
  import logging
3
3
  import os
4
4
  from urllib.parse import urljoin
5
- from typing import Dict, List, Union
5
+ from typing import Dict, List, Optional, Union
6
6
  from datetime import datetime
7
7
 
8
+ from geobox.enums import AnalysisDataType, AnalysisResampleMethod
9
+
8
10
  from .exception import AuthenticationError, ApiRequestError, NotFoundError, ValidationError, ServerError, AuthorizationError
9
11
  from .vectorlayer import VectorLayer, LayerType
10
12
  from .feature import Feature
@@ -418,6 +420,20 @@ class GeoboxClient:
418
420
  return self._make_request(HttpMethods.DELETE, endpoint, payload, is_json)
419
421
 
420
422
 
423
+ @property
424
+ def raster_analysis(self):
425
+ from .raster_analysis import RasterAnalysis
426
+
427
+ return RasterAnalysis(self)
428
+
429
+
430
+ @property
431
+ def vector_tool(self):
432
+ from .vector_tool import VectorTool
433
+
434
+ return VectorTool(self)
435
+
436
+
421
437
  def get_vectors(self, **kwargs) -> Union[List['VectorLayer'], int]:
422
438
  """
423
439
  Get a list of vector layers with optional filtering and pagination.
@@ -2618,4 +2634,4 @@ class GeoboxClient:
2618
2634
  >>> client = GeoboxClient()
2619
2635
  >>> client.update_usage()
2620
2636
  """
2621
- return Usage.update_usage(self, user_id=user_id)
2637
+ return Usage.update_usage(self, user_id=user_id)
geobox/apikey.py CHANGED
@@ -1,263 +1,263 @@
1
- from typing import List, Dict, Optional, TYPE_CHECKING
2
- from urllib.parse import urljoin
3
-
4
- from .base import Base
5
- from .utils import clean_data
6
-
7
- if TYPE_CHECKING:
8
- from . import GeoboxClient
9
- from .aio import AsyncGeoboxClient
10
- from .aio.apikey import ApiKey as AsyncApikey
11
-
12
-
13
- class ApiKey(Base):
14
-
15
- BASE_ENDPOINT = 'apikeys/'
16
-
17
- def __init__(self,
18
- api: 'GeoboxClient',
19
- key_id: int,
20
- data: Optional[Dict] = {}):
21
- """
22
- Initialize an apikey instance.
23
-
24
- Args:
25
- api (GeoboxClient): The GeoboxClient instance for making requests.
26
- key_id (int): The unique identifier for the apikey.
27
- data (Dict, optional): The data of the apikey.
28
- """
29
- super().__init__(api, data=data)
30
- self.key_id = key_id
31
- self.endpoint = urljoin(self.BASE_ENDPOINT, str(self.id))
32
-
33
-
34
- def __repr__(self) -> str:
35
- """
36
- Return a string representation of the attachment.
37
-
38
- Returns:
39
- str: The string representation of the attachment.
40
- """
41
- return f'ApiKey(id={self.key_id}, name={self.name}, revoked={self.revoked})'
42
-
43
-
44
- @classmethod
45
- def get_apikeys(cls, api: 'GeoboxClient', **kwargs) -> List['ApiKey']:
46
- """
47
- Get a list of apikeys
48
-
49
- Args:
50
- api (GeoboxClient): The GeoboxClient instance for making requests.
51
-
52
- Keyword Args:
53
- search (str): search term for keyword-based searching among all textual fields.
54
- 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.
55
- skip (int): Number of layers to skip. default is 0.
56
- limit (int): Maximum number of layers to return. default is 10.
57
- user_id (int): Specific user. privileges required.
58
-
59
- Example:
60
- >>> from geobox import GeoboxClient
61
- >>> from geobox.apikey import ApiKey
62
- >>> client = GeoboxClient()
63
- >>> apikeys = ApiKey.get_apikeys(client)
64
- or
65
- >>> apikeys = client.get_apikeys()
66
- """
67
- params = {
68
- 'search': kwargs.get('search'),
69
- 'order_by': kwargs.get('order_by'),
70
- 'skip': kwargs.get('skip'),
71
- 'limit': kwargs.get('limit'),
72
- 'user_id': kwargs.get('user_id')
73
- }
74
- return super()._get_list(api, cls.BASE_ENDPOINT, params, factory_func=lambda api, item: ApiKey(api, item['id'], item))
75
-
76
-
77
- @classmethod
78
- def create_apikey(cls, api: 'GeoboxClient', name: str, user_id: int = None) -> 'ApiKey':
79
- """
80
- Create an ApiKey
81
-
82
- Args:
83
- api (GeoboxClient): The GeoboxClient instance for making requests.
84
- name (str): name of the key.
85
- user_id (int, optional): Specific user. privileges required.
86
-
87
- Returns:
88
- ApiKey: the apikey object
89
-
90
- Example:
91
- >>> from geobox import GeoboxClient
92
- >>> from geobox.apikey import ApiKey
93
- >>> client = GeoboxClient()
94
- >>> apikey = ApiKey.create_apikey(client, name='test')
95
- or
96
- >>> apikey = client.create_apikey(name='test')
97
- """
98
- data = clean_data({
99
- 'name': name,
100
- 'user_id': user_id
101
- })
102
- response = api.post(cls.BASE_ENDPOINT, payload=data, is_json=False)
103
- return ApiKey(api, response['id'], response)
104
-
105
-
106
- @classmethod
107
- def get_apikey(cls, api: 'GeoboxClient', key_id: int) -> 'ApiKey':
108
- """
109
- Get an ApiKey
110
-
111
- Args:
112
- api (GeoboxClient): The GeoboxClient instance for making requests.
113
- key_id (str): the id of the apikey.
114
-
115
- Returns:
116
- ApiKey: the ApiKey object
117
-
118
- Example:
119
- >>> from geobox import GeoboxClient
120
- >>> from geobox.apikey import ApiKey
121
- >>> client = GeoboxClient()
122
- >>> apikey = ApiKey.get_apikey(client, key_id=1)
123
- or
124
- >>> apikey = client.get_apikey(key_id=1)
125
- """
126
- params = {
127
- 'f': 'json'
128
- }
129
- return super()._get_detail(api=api,
130
- endpoint=cls.BASE_ENDPOINT,
131
- uuid=key_id,
132
- params=params,
133
- factory_func=lambda api, item: ApiKey(api, item['id'], item))
134
-
135
-
136
- @classmethod
137
- def get_apikey_by_name(cls, api: 'GeoboxClient', name: str, user_id: int = None) -> 'ApiKey':
138
- """
139
- Get an ApiKey by name
140
-
141
- Args:
142
- api (GeoboxClient): The GeoboxClient instance for making requests.
143
- name (str): the name of the key to get
144
- user_id (int, optional): specific user. privileges required.
145
-
146
- Returns:
147
- ApiKey | None: returns the key if a key matches the given name, else None
148
-
149
- Example:
150
- >>> from geobox import GeoboxClient
151
- >>> from geobox.apikey import ApiKey
152
- >>> client = GeoboxClient()
153
- >>> apikey = ApiKey.get_apikey_by_name(client, name='test')
154
- or
155
- >>> apikey = client.get_apikey_by_name(name='test')
156
- """
157
- apikeys = cls.get_apikeys(api, search=name, user_id=user_id)
158
- if apikeys and apikeys[0].name == name:
159
- return apikeys[0]
160
- else:
161
- return None
162
-
163
-
164
- def update(self, name: str, user_id: int = None) -> Dict:
165
- """
166
- Update an ApiKey
167
-
168
- Args:
169
- name (str): the name of the key
170
- user_id (int, optional): Specific user. privileges required.
171
-
172
- Returns:
173
- Dict: Updated ApiKey data
174
-
175
- Example:
176
- >>> from geobox import GeoboxClient
177
- >>> from geobox.apikey import ApiKey
178
- >>> client = GeoboxClient()
179
- >>> apikey = ApiKey.get_apikey(client, key_id=1)
180
- >>> apikey.update(name="updated_name")
181
- """
182
- data = clean_data({
183
- "name": name,
184
- "user_id": user_id
185
- })
186
-
187
- response = self.api.put(self.endpoint, data, is_json=False)
188
- self._update_properties(response)
189
- return response
190
-
191
-
192
- def delete(self) -> None:
193
- """
194
- Delete the ApiKey.
195
-
196
- Returns:
197
- None
198
-
199
- Example:
200
- >>> from geobox import GeoboxClient
201
- >>> from geobox.apikey import ApiKey
202
- >>> client = GeoboxClient()
203
- >>> apikey = ApiKey.get_apikey(client, key_id=1)
204
- >>> apikey.delete()
205
- """
206
- super().delete(self.endpoint)
207
- self.key_id = None
208
-
209
-
210
- def revoke(self) -> None:
211
- """
212
- Revoke an ApiKey
213
-
214
- Example:
215
- >>> from geobox import GeoboxClient
216
- >>> from geobox.apikey import ApiKey
217
- >>> client = GeoboxClient()
218
- >>> apikey = ApiKey.get_apikey(client, key_id=1)
219
- >>> apikey.revoke()
220
- """
221
- endpoint = f"{self.endpoint}/revoke"
222
- self.api.post(endpoint)
223
- self.data['revoked'] = True
224
-
225
-
226
- def grant(self) -> None:
227
- """
228
- Grant an ApiKey
229
-
230
- Example:
231
- >>> from geobox import GeoboxClient
232
- >>> from geobox.apikey import ApiKey
233
- >>> client = GeoboxClient()
234
- >>> apikey = ApiKey.get_apikey(client, key_id=1)
235
- >>> apikey.grant()
236
- """
237
- endpoint = f"{self.endpoint}/grant"
238
- self.api.post(endpoint)
239
- self.data['revoked'] = False
240
-
241
-
242
- def to_async(self, async_client: 'AsyncGeoboxClient') -> 'AsyncApikey':
243
- """
244
- Switch to async version of the apikey instance to have access to the async methods
245
-
246
- Args:
247
- async_client (AsyncGeoboxClient): The async version of the GeoboxClient instance for making requests.
248
-
249
- Returns:
250
- geobox.aio.apikey.Apikey: the async instance of the apikey.
251
-
252
- Example:
253
- >>> from geobox import Geoboxclient
254
- >>> from geobox.aio import AsyncGeoboxClient
255
- >>> from geobox.apikey import ApiKey
256
- >>> client = GeoboxClient()
257
- >>> apikey = ApiKey.get_apikey(client, key_id=1)
258
- >>> async with AsyncGeoboxClient() as async_client:
259
- >>> async_apikey = apikey.to_async(async_client)
260
- """
261
- from .aio.apikey import ApiKey as AsyncApiKey
262
-
1
+ from typing import List, Dict, Optional, TYPE_CHECKING
2
+ from urllib.parse import urljoin
3
+
4
+ from .base import Base
5
+ from .utils import clean_data
6
+
7
+ if TYPE_CHECKING:
8
+ from . import GeoboxClient
9
+ from .aio import AsyncGeoboxClient
10
+ from .aio.apikey import AsyncApiKey
11
+
12
+
13
+ class ApiKey(Base):
14
+
15
+ BASE_ENDPOINT = 'apikeys/'
16
+
17
+ def __init__(self,
18
+ api: 'GeoboxClient',
19
+ key_id: int,
20
+ data: Optional[Dict] = {}):
21
+ """
22
+ Initialize an apikey instance.
23
+
24
+ Args:
25
+ api (GeoboxClient): The GeoboxClient instance for making requests.
26
+ key_id (int): The unique identifier for the apikey.
27
+ data (Dict, optional): The data of the apikey.
28
+ """
29
+ super().__init__(api, data=data)
30
+ self.key_id = key_id
31
+ self.endpoint = urljoin(self.BASE_ENDPOINT, str(self.id))
32
+
33
+
34
+ def __repr__(self) -> str:
35
+ """
36
+ Return a string representation of the attachment.
37
+
38
+ Returns:
39
+ str: The string representation of the attachment.
40
+ """
41
+ return f'ApiKey(id={self.key_id}, name={self.name}, revoked={self.revoked})'
42
+
43
+
44
+ @classmethod
45
+ def get_apikeys(cls, api: 'GeoboxClient', **kwargs) -> List['ApiKey']:
46
+ """
47
+ Get a list of apikeys
48
+
49
+ Args:
50
+ api (GeoboxClient): The GeoboxClient instance for making requests.
51
+
52
+ Keyword Args:
53
+ search (str): search term for keyword-based searching among all textual fields.
54
+ 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.
55
+ skip (int): Number of layers to skip. default is 0.
56
+ limit (int): Maximum number of layers to return. default is 10.
57
+ user_id (int): Specific user. privileges required.
58
+
59
+ Example:
60
+ >>> from geobox import GeoboxClient
61
+ >>> from geobox.apikey import ApiKey
62
+ >>> client = GeoboxClient()
63
+ >>> apikeys = ApiKey.get_apikeys(client)
64
+ or
65
+ >>> apikeys = client.get_apikeys()
66
+ """
67
+ params = {
68
+ 'search': kwargs.get('search'),
69
+ 'order_by': kwargs.get('order_by'),
70
+ 'skip': kwargs.get('skip'),
71
+ 'limit': kwargs.get('limit'),
72
+ 'user_id': kwargs.get('user_id')
73
+ }
74
+ return super()._get_list(api, cls.BASE_ENDPOINT, params, factory_func=lambda api, item: ApiKey(api, item['id'], item))
75
+
76
+
77
+ @classmethod
78
+ def create_apikey(cls, api: 'GeoboxClient', name: str, user_id: int = None) -> 'ApiKey':
79
+ """
80
+ Create an ApiKey
81
+
82
+ Args:
83
+ api (GeoboxClient): The GeoboxClient instance for making requests.
84
+ name (str): name of the key.
85
+ user_id (int, optional): Specific user. privileges required.
86
+
87
+ Returns:
88
+ ApiKey: the apikey object
89
+
90
+ Example:
91
+ >>> from geobox import GeoboxClient
92
+ >>> from geobox.apikey import ApiKey
93
+ >>> client = GeoboxClient()
94
+ >>> apikey = ApiKey.create_apikey(client, name='test')
95
+ or
96
+ >>> apikey = client.create_apikey(name='test')
97
+ """
98
+ data = clean_data({
99
+ 'name': name,
100
+ 'user_id': user_id
101
+ })
102
+ response = api.post(cls.BASE_ENDPOINT, payload=data, is_json=False)
103
+ return ApiKey(api, response['id'], response)
104
+
105
+
106
+ @classmethod
107
+ def get_apikey(cls, api: 'GeoboxClient', key_id: int) -> 'ApiKey':
108
+ """
109
+ Get an ApiKey
110
+
111
+ Args:
112
+ api (GeoboxClient): The GeoboxClient instance for making requests.
113
+ key_id (str): the id of the apikey.
114
+
115
+ Returns:
116
+ ApiKey: the ApiKey object
117
+
118
+ Example:
119
+ >>> from geobox import GeoboxClient
120
+ >>> from geobox.apikey import ApiKey
121
+ >>> client = GeoboxClient()
122
+ >>> apikey = ApiKey.get_apikey(client, key_id=1)
123
+ or
124
+ >>> apikey = client.get_apikey(key_id=1)
125
+ """
126
+ params = {
127
+ 'f': 'json'
128
+ }
129
+ return super()._get_detail(api=api,
130
+ endpoint=cls.BASE_ENDPOINT,
131
+ uuid=key_id,
132
+ params=params,
133
+ factory_func=lambda api, item: ApiKey(api, item['id'], item))
134
+
135
+
136
+ @classmethod
137
+ def get_apikey_by_name(cls, api: 'GeoboxClient', name: str, user_id: int = None) -> 'ApiKey':
138
+ """
139
+ Get an ApiKey by name
140
+
141
+ Args:
142
+ api (GeoboxClient): The GeoboxClient instance for making requests.
143
+ name (str): the name of the key to get
144
+ user_id (int, optional): specific user. privileges required.
145
+
146
+ Returns:
147
+ ApiKey | None: returns the key if a key matches the given name, else None
148
+
149
+ Example:
150
+ >>> from geobox import GeoboxClient
151
+ >>> from geobox.apikey import ApiKey
152
+ >>> client = GeoboxClient()
153
+ >>> apikey = ApiKey.get_apikey_by_name(client, name='test')
154
+ or
155
+ >>> apikey = client.get_apikey_by_name(name='test')
156
+ """
157
+ apikeys = cls.get_apikeys(api, search=name, user_id=user_id)
158
+ if apikeys and apikeys[0].name == name:
159
+ return apikeys[0]
160
+ else:
161
+ return None
162
+
163
+
164
+ def update(self, name: str, user_id: int = None) -> Dict:
165
+ """
166
+ Update an ApiKey
167
+
168
+ Args:
169
+ name (str): the name of the key
170
+ user_id (int, optional): Specific user. privileges required.
171
+
172
+ Returns:
173
+ Dict: Updated ApiKey data
174
+
175
+ Example:
176
+ >>> from geobox import GeoboxClient
177
+ >>> from geobox.apikey import ApiKey
178
+ >>> client = GeoboxClient()
179
+ >>> apikey = ApiKey.get_apikey(client, key_id=1)
180
+ >>> apikey.update(name="updated_name")
181
+ """
182
+ data = clean_data({
183
+ "name": name,
184
+ "user_id": user_id
185
+ })
186
+
187
+ response = self.api.put(self.endpoint, data, is_json=False)
188
+ self._update_properties(response)
189
+ return response
190
+
191
+
192
+ def delete(self) -> None:
193
+ """
194
+ Delete the ApiKey.
195
+
196
+ Returns:
197
+ None
198
+
199
+ Example:
200
+ >>> from geobox import GeoboxClient
201
+ >>> from geobox.apikey import ApiKey
202
+ >>> client = GeoboxClient()
203
+ >>> apikey = ApiKey.get_apikey(client, key_id=1)
204
+ >>> apikey.delete()
205
+ """
206
+ super()._delete(self.endpoint)
207
+ self.key_id = None
208
+
209
+
210
+ def revoke(self) -> None:
211
+ """
212
+ Revoke an ApiKey
213
+
214
+ Example:
215
+ >>> from geobox import GeoboxClient
216
+ >>> from geobox.apikey import ApiKey
217
+ >>> client = GeoboxClient()
218
+ >>> apikey = ApiKey.get_apikey(client, key_id=1)
219
+ >>> apikey.revoke()
220
+ """
221
+ endpoint = f"{self.endpoint}/revoke"
222
+ self.api.post(endpoint)
223
+ self.data['revoked'] = True
224
+
225
+
226
+ def grant(self) -> None:
227
+ """
228
+ Grant an ApiKey
229
+
230
+ Example:
231
+ >>> from geobox import GeoboxClient
232
+ >>> from geobox.apikey import ApiKey
233
+ >>> client = GeoboxClient()
234
+ >>> apikey = ApiKey.get_apikey(client, key_id=1)
235
+ >>> apikey.grant()
236
+ """
237
+ endpoint = f"{self.endpoint}/grant"
238
+ self.api.post(endpoint)
239
+ self.data['revoked'] = False
240
+
241
+
242
+ def to_async(self, async_client: 'AsyncGeoboxClient') -> 'AsyncApiKey':
243
+ """
244
+ Switch to async version of the apikey instance to have access to the async methods
245
+
246
+ Args:
247
+ async_client (AsyncGeoboxClient): The async version of the GeoboxClient instance for making requests.
248
+
249
+ Returns:
250
+ AsyncApiKey: the async instance of the apikey.
251
+
252
+ Example:
253
+ >>> from geobox import Geoboxclient
254
+ >>> from geobox.aio import AsyncGeoboxClient
255
+ >>> from geobox.apikey import ApiKey
256
+ >>> client = GeoboxClient()
257
+ >>> apikey = ApiKey.get_apikey(client, key_id=1)
258
+ >>> async with AsyncGeoboxClient() as async_client:
259
+ >>> async_apikey = apikey.to_async(async_client)
260
+ """
261
+ from .aio.apikey import AsyncApiKey
262
+
263
263
  return AsyncApiKey(api=async_client, key_id=self.key_id, data=self.data)