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/usage.py ADDED
@@ -0,0 +1,243 @@
1
+ from urllib.parse import urlencode, urljoin
2
+ from typing import Optional, Dict, List, Union, TYPE_CHECKING
3
+ from datetime import datetime
4
+
5
+ from .base import AsyncBase
6
+ from .user import User
7
+ from .apikey import ApiKey
8
+ from ..utils import clean_data
9
+ from ..enums import UsageScale, UsageParam
10
+
11
+ if TYPE_CHECKING:
12
+ from . import AsyncGeoboxClient
13
+ from ..api import GeoboxClient as SyncGeoboxClient
14
+ from ..usage import Usage as SyncUsage
15
+
16
+
17
+ class Usage(AsyncBase):
18
+
19
+ BASE_ENDPOINT = 'usage/'
20
+
21
+ def __init__(self,
22
+ api: 'AsyncGeoboxClient',
23
+ user: 'User'):
24
+ """
25
+ Constructs the necessary attributes for the Usage object.
26
+
27
+ Args:
28
+ api (AsyncGeoboxClient): The API instance.
29
+ user (User): the user usage object.
30
+ """
31
+ self.api = api
32
+ self.user = user
33
+
34
+
35
+ def __repr__(self) -> str:
36
+ """
37
+ Return a string representation of the Usage object.
38
+
39
+ Returns:
40
+ str: A string representation of the Usage object.
41
+ """
42
+ return f"Usage(user={self.user})"
43
+
44
+
45
+ @classmethod
46
+ async def get_api_usage(cls,
47
+ api: 'AsyncGeoboxClient',
48
+ resource: Union['User', 'ApiKey'],
49
+ scale: 'UsageScale',
50
+ param: 'UsageParam',
51
+ from_date: 'datetime' = None,
52
+ to_date: 'datetime' = None,
53
+ days_before_now: int = None,
54
+ limit: int = None) -> List:
55
+ """
56
+ [async] Get the api usage of a user
57
+
58
+ Args:
59
+ api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
60
+ resource (User | ApiKey): User or ApiKey object.
61
+ scale (UsageScale): the scale of the report.
62
+ param (UsageParam): traffic or calls.
63
+ from_date (datetime, optional): datetime object in this format: "%Y-%m-%dT%H:%M:%S".
64
+ to_date (datetime, optional): datetime object in this format: "%Y-%m-%dT%H:%M:%S".
65
+ days_before_now (int, optional): number of days befor now.
66
+ limit (int, optional): Number of items to return. default is 10.
67
+
68
+ Raises:
69
+ ValueError: one of days_before_now or from_date/to_date parameters must have value
70
+ ValueError: resource must be a 'user' or 'apikey' object
71
+
72
+ Returns:
73
+ List: usage report
74
+
75
+ Example:
76
+ >>> from geobox.aio import AsyncGeoboxClient
77
+ >>> from geobox.aio.usage import Usage
78
+ >>> async with AsyncGeoboxClient() as client:
79
+ >>> user = await client.get_user() # gets current user
80
+ >>> usage = await Usage.get_api_usage(client,
81
+ ... resource=user,
82
+ ... scale=UsageScale.Day,
83
+ ... param=UsageParam.Calls,
84
+ ... days_before_now=5)
85
+ or
86
+ >>> usage = await client.get_api_usage(resource=user,
87
+ ... scale=UsageScale.Day,
88
+ ... param=UsageParam.Calls,
89
+ ... days_before_now=5)
90
+ """
91
+ if not(from_date and to_date) and not days_before_now:
92
+ raise ValueError("one of days_before_now or from_date/to_date parameters must have value")
93
+
94
+ params = {}
95
+ if isinstance(resource, User):
96
+ params['eid'] = resource.user_id
97
+ elif isinstance(resource, ApiKey):
98
+ params['eid'] = resource.key
99
+ else:
100
+ raise ValueError("resource must be a 'user' or 'apikey' object")
101
+
102
+ params = clean_data({**params,
103
+ 'scale': scale.value if scale else None,
104
+ 'param': param.value if param else None,
105
+ 'from_date': from_date.strftime("%Y-%m-%dT%H:%M:%S.%f") if from_date else None,
106
+ 'to_date': to_date.strftime("%Y-%m-%dT%H:%M:%S.%f") if to_date else None,
107
+ 'days_before_now': days_before_now,
108
+ 'limit': limit
109
+ })
110
+ query_strings = urlencode(params)
111
+ endpoint = f"{cls.BASE_ENDPOINT}api?{query_strings}"
112
+
113
+ return await api.get(endpoint)
114
+
115
+
116
+ @classmethod
117
+ async def get_process_usage(cls,
118
+ api: 'AsyncGeoboxClient',
119
+ user_id: int = None,
120
+ from_date: datetime = None,
121
+ to_date: datetime = None,
122
+ days_before_now: int = None) -> float:
123
+ """
124
+ [async] Get process usage of a user in seconds
125
+
126
+ Args:
127
+ api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
128
+ user_id (int, optional): the id of the user. leave blank to get the current user report.
129
+ from_date (datetime, optional): datetime object in this format: "%Y-%m-%dT%H:%M:%S".
130
+ to_date (datetime, optional): datetime object in this format: "%Y-%m-%dT%H:%M:%S".
131
+ days_before_now (int, optional): number of days befor now.
132
+
133
+ Raises:
134
+ ValueError: one of days_before_now or from_date/to_date parameters must have value
135
+
136
+ Returns:
137
+ float: process usage of a user in seconds
138
+
139
+ Example:
140
+ >>> from geobox.aio import AsyncGeoboxClient
141
+ >>> from geobox.aio.usage import Usage
142
+ >>> async with AsyncGeoboxClient() as client:
143
+ >>> process_usage = await Usage.get_process_usage(client, days_before_now=5)
144
+ or
145
+ >>> process_usage = await client.get_process_usage(days_before_now=5)
146
+ """
147
+ if not(from_date and to_date) and not days_before_now:
148
+ raise ValueError("one of days_before_now or from_date/to_date parameters must have value")
149
+
150
+ params = clean_data({
151
+ 'user_id': user_id if user_id else None,
152
+ 'from_date': from_date.strftime("%Y-%m-%dT%H:%M:%S.%f") if from_date else None,
153
+ 'to_date': to_date.strftime("%Y-%m-%dT%H:%M:%S.%f") if to_date else None,
154
+ 'days_before_now': days_before_now
155
+ })
156
+ query_strings = urlencode(params)
157
+ endpoint = f"{cls.BASE_ENDPOINT}process?{query_strings}"
158
+ return await api.get(endpoint)
159
+
160
+
161
+ @classmethod
162
+ async def get_usage_summary(cls, api: 'AsyncGeoboxClient', user_id: int = None) -> Dict:
163
+ """
164
+ [async] Get the usage summary of a user
165
+
166
+ Args:
167
+ api (AsyncGeoboxClient): The API instance.
168
+ user_id (int, optional): the id of the user. leave blank to get the current user report.
169
+
170
+ Returns:
171
+ Dict: the usage summary of the users
172
+
173
+ Returns:
174
+ >>> from geobox.aio import AsyncGeoboxClient
175
+ >>> from geobox.aio.usage import Usage
176
+ >>> async with AsyncGeoboxClient() as client:
177
+ >>> usage_summary = await Usage.get_usage_summary(client)
178
+ or
179
+ >>> usage_summary = await client.get_usage_summary()
180
+ """
181
+ params = clean_data({
182
+ 'user_id': user_id if user_id else None
183
+ })
184
+ query_strings = urlencode(params)
185
+ endpoint = f"{cls.BASE_ENDPOINT}summary?{query_strings}"
186
+ return await api.get(endpoint)
187
+
188
+
189
+ @classmethod
190
+ async def update_usage(cls, api: 'AsyncGeoboxClient', user_id: int = None) -> Dict:
191
+ """
192
+ [async] Update usage of a user
193
+
194
+ Args:
195
+ api (AsyncGeoboxClient): The API instance.
196
+ user_id (int, optional): the id of the user. leave blank to get the current user report.
197
+
198
+ Returns:
199
+ Dict: the updated data
200
+
201
+ Example:
202
+ >>> from geobox.aio import AsyncGeoboxClient
203
+ >>> from geobox.aio.usage import Usage
204
+ >>> async with AsyncGeoboxClient() as client:
205
+ >>> await Usage.update_usage(client)
206
+ or
207
+ >>> await client.update_usage()
208
+ """
209
+ data = clean_data({
210
+ 'user_id': user_id if user_id else None
211
+ })
212
+ endpoint = f"{cls.BASE_ENDPOINT}update"
213
+ return await api.post(endpoint, payload=data)
214
+
215
+
216
+ def to_sync(self, sync_client: 'SyncGeoboxClient') -> 'SyncUsage':
217
+ """
218
+ Switch to sync version of the usage instance to have access to the sync methods
219
+
220
+ Args:
221
+ sync_client (SyncGeoboxClient): The sync version of the GeoboxClient instance for making requests.
222
+
223
+ Returns:
224
+ geobox.usage.Usage: the sync instance of the usage.
225
+
226
+ Example:
227
+ >>> from geobox import Geoboxclient
228
+ >>> from geobox.aio import AsyncGeoboxClient
229
+ >>> from geobox.aio.usage import Usage
230
+ >>> client = GeoboxClient()
231
+ >>> async with AsyncGeoboxClient() as async_client:
232
+ >>> user = await async_client.get_user()
233
+ >>> usage = await Usage.get_api_usage(async_client,
234
+ ... resource=user,
235
+ ... scale=UsageScale.Day,
236
+ ... param=UsageParam.Calls,
237
+ ... days_before_now=5)
238
+ >>> sync_usage = await usage.to_sync(client)
239
+ """
240
+ from ..usage import Usage as SyncUsage
241
+
242
+ user = self.user.to_sync(sync_client)
243
+ return SyncUsage(api=sync_client, user=user)