geobox 2.1.0__py3-none-any.whl → 2.2.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 (70) hide show
  1. geobox/__init__.py +61 -63
  2. geobox/aio/__init__.py +61 -63
  3. geobox/aio/api.py +491 -574
  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 +35 -35
  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 +88 -454
  20. geobox/aio/{analysis.py → raster_analysis.py} +153 -170
  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 +316 -414
  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 +14 -98
  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 +31 -1
  41. geobox/feature.py +31 -10
  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 +5 -368
  52. geobox/{analysis.py → raster_analysis.py} +108 -128
  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 -110
  62. geobox/version.py +272 -272
  63. geobox/view.py +981 -981
  64. geobox/workflow.py +338 -339
  65. {geobox-2.1.0.dist-info → geobox-2.2.1.dist-info}/METADATA +15 -1
  66. geobox-2.2.1.dist-info/RECORD +72 -0
  67. geobox-2.1.0.dist-info/RECORD +0 -70
  68. {geobox-2.1.0.dist-info → geobox-2.2.1.dist-info}/WHEEL +0 -0
  69. {geobox-2.1.0.dist-info → geobox-2.2.1.dist-info}/licenses/LICENSE +0 -0
  70. {geobox-2.1.0.dist-info → geobox-2.2.1.dist-info}/top_level.txt +0 -0
geobox/api.py CHANGED
@@ -420,6 +420,20 @@ class GeoboxClient:
420
420
  return self._make_request(HttpMethods.DELETE, endpoint, payload, is_json)
421
421
 
422
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
+
423
437
  def get_vectors(self, **kwargs) -> Union[List['VectorLayer'], int]:
424
438
  """
425
439
  Get a list of vector layers with optional filtering and pagination.
@@ -2621,101 +2635,3 @@ class GeoboxClient:
2621
2635
  >>> client.update_usage()
2622
2636
  """
2623
2637
  return Usage.update_usage(self, user_id=user_id)
2624
-
2625
-
2626
- def raster_calculator(self,
2627
- variables: str,
2628
- expr: str,
2629
- output_raster_name: str,
2630
- match_raster_uuid: Optional[str] = None,
2631
- resample: AnalysisResampleMethod = AnalysisResampleMethod.bilinear,
2632
- out_dtype: AnalysisDataType = AnalysisDataType.float32,
2633
- dst_nodata: int = -9999,
2634
- user_id: Optional[int] = None) -> 'Task':
2635
- """
2636
- Perform raster calculator operations on multiple raster datasets.
2637
-
2638
- it allows you to perform mathematical operations on one or more raster datasets using NumPy expressions.
2639
- Variables in the expression correspond to raster datasets specified in the variables dictionary.
2640
-
2641
- Examples:
2642
- NDVI calculation: variables='{"NIR": "raster_uuid_1", "RED": "raster_uuid_2"}', expr="(NIR-RED)/(NIR+RED)"
2643
- Slope threshold: variables='{"SLOPE": "raster_uuid_1"}', expr="np.where(SLOPE>30,1,0)"
2644
- Multi-band operations: variables='{"IMG": ["raster_uuid_1", 2]}', expr="IMG*2"
2645
-
2646
- Args:
2647
- variables (str): JSON string mapping variable names to raster specifications. Format: '{"NIR": "raster_uuid_1", "RED": "raster_uuid_2"}' or '{"IMG": ["raster_uuid_1", 2]}' for multi-band operations.
2648
- expr (str): Mathematical expression using NumPy syntax. Use variable names from the variables dict, e.g., '(NIR-RED)/(NIR+RED)' or 'where(SLOPE>30,1,0)' or 'where((dist_to_highway < 1000) & (slope < 10), 1, 0)' .Supported functions: np, sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, exp, log, log10, sqrt, abs, floor, ceil, round, minimum, maximum, clip, where, isnan, isfinite, pi, e.
2649
- output_raster_name (str): Name for the output raster dataset.
2650
- match_raster_uuid (str, optional): Optional raster UUID to match the output grid and projection. If not provided, the first variable becomes the reference grid.
2651
- resample (CropResample, optional): Resampling method: 'near', 'bilinear', 'cubic', 'lanczos', etc. default: CropResample.near
2652
- out_dtype (AnalysisDataType, optional): Data type for the output raster (e.g., int16, float32). default: AnalysisDataType.float32
2653
- dst_nodata (int, optional): NoData value for the output raster. default = -9999
2654
- user_id (int, optional): specific user. priviledges required!
2655
-
2656
- Returns:
2657
- Task: task instance of the process
2658
-
2659
- Example:
2660
- >>> from geobox import GeoboxClient
2661
- >>> client = GeoboxClient()
2662
- >>> task = client.raster_calculator(api=client, variables={"NIR": "raster_uuid_1", "RED": "raster_uuid_2"},
2663
- ... expr='where(SLOPE>30,1,0)',
2664
- ... output_raster_name='test')
2665
- """
2666
- from .analysis import Analysis
2667
- return Analysis.calculator(self,
2668
- variables=variables,
2669
- expr=expr,
2670
- output_raster_name=output_raster_name,
2671
- match_raster_uuid=match_raster_uuid,
2672
- resample=resample,
2673
- out_dtype=out_dtype,
2674
- dst_nodata=dst_nodata,
2675
- user_id=user_id)
2676
-
2677
-
2678
-
2679
- def create_constant_raster(self,
2680
- output_raster_name: str,
2681
- extent: str,
2682
- value : int,
2683
- pixel_size: int = 10,
2684
- dtype: AnalysisDataType = AnalysisDataType.float32,
2685
- nodata: int = -9999,
2686
- align_to: Optional[str] = None,
2687
- user_id: Optional[int] = None) -> 'Task':
2688
- """
2689
- Create a raster filled with a constant value.
2690
-
2691
- This endpoint creates a north-up GeoTIFF filled with a constant value.
2692
- Only users with Publisher role or higher can perform this operation.
2693
-
2694
- Args:
2695
- output_raster_name (str): Name for the output constant raster dataset.
2696
- extent (str): Extent as 'minX,minY,maxX,maxY' (e.g., '0,0,100,100').
2697
- value (int): Constant value to fill the raster with.
2698
- pixel_size (int, optional): Pixel size for the output raster (must be > 0). default: 10
2699
- dtype (AnalysisDataType, optoinal): Output data type. default: AnalysisDataType.float32
2700
- nodata (int, optional): NoData value for the raster. default: -9999
2701
- align_to (str, optional): Grid origin to snap to as 'x0,y0' (e.g., '0,0').
2702
- user_id (int, optional): specific user. priviledges required!
2703
-
2704
- Returns:
2705
- Task: task instance of the process
2706
-
2707
- Example:
2708
- >>> from geobox import GeoboxClient
2709
- >>> client = GeoboxClient()
2710
- >>> task = client.create_constant_raster(output_raster_name='test', extent='0,0,100,100', value=10)
2711
- """
2712
- from .analysis import Analysis
2713
- return Analysis.constant(self,
2714
- output_raster_name=output_raster_name,
2715
- extent=extent,
2716
- value=value,
2717
- pixel_size=pixel_size,
2718
- dtype=dtype,
2719
- nodata=nodata,
2720
- align_to=align_to,
2721
- 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)