terrakio-core 0.1.9__tar.gz

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.

Potentially problematic release.


This version of terrakio-core might be problematic. Click here for more details.

@@ -0,0 +1,36 @@
1
+ Metadata-Version: 2.4
2
+ Name: terrakio-core
3
+ Version: 0.1.9
4
+ Summary: Core components for Terrakio API clients
5
+ Home-page: https://github.com/HaizeaAnalytics/terrakio-python-api
6
+ Author: Yupeng Chao
7
+ Author-email: Yupeng Chao <yupeng@haizea.com.au>
8
+ Project-URL: Homepage, https://github.com/HaizeaAnalytics/terrakio-python-api
9
+ Project-URL: Bug Tracker, https://github.com/HaizeaAnalytics/terrakio-python-api/issues
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.7
12
+ Classifier: Programming Language :: Python :: 3.8
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Development Status :: 4 - Beta
18
+ Requires-Python: >=3.7
19
+ Description-Content-Type: text/markdown
20
+ Requires-Dist: requests>=2.25.0
21
+ Requires-Dist: pyyaml>=5.1
22
+ Requires-Dist: xarray>=2023.1.0
23
+ Requires-Dist: shapely>=2.0.0
24
+ Dynamic: author
25
+ Dynamic: home-page
26
+ Dynamic: requires-python
27
+
28
+ # Terrakio Core
29
+
30
+ Core components for Terrakio API clients. This package provides the foundational classes and utilities used by both the regular and admin API clients.
31
+
32
+ This package is typically not used directly but is a dependency for:
33
+ - `terrakio-api`: Regular user client
34
+ - `terrakio-admin-api`: Administrative client
35
+
36
+ For documentation and usage examples, see the [main repository](https://github.com/HaizeaAnalytics/terrakio-python-api).
@@ -0,0 +1,9 @@
1
+ # Terrakio Core
2
+
3
+ Core components for Terrakio API clients. This package provides the foundational classes and utilities used by both the regular and admin API clients.
4
+
5
+ This package is typically not used directly but is a dependency for:
6
+ - `terrakio-api`: Regular user client
7
+ - `terrakio-admin-api`: Administrative client
8
+
9
+ For documentation and usage examples, see the [main repository](https://github.com/HaizeaAnalytics/terrakio-python-api).
@@ -0,0 +1,33 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "terrakio-core"
7
+ version = "0.1.9"
8
+ authors = [
9
+ {name = "Yupeng Chao", email = "yupeng@haizea.com.au"},
10
+ ]
11
+ description = "Core components for Terrakio API clients"
12
+ readme = "README.md"
13
+ requires-python = ">=3.7"
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "Programming Language :: Python :: 3.7",
17
+ "Programming Language :: Python :: 3.8",
18
+ "Programming Language :: Python :: 3.9",
19
+ "Programming Language :: Python :: 3.10",
20
+ "License :: OSI Approved :: MIT License",
21
+ "Operating System :: OS Independent",
22
+ "Development Status :: 4 - Beta",
23
+ ]
24
+ dependencies = [
25
+ "requests>=2.25.0",
26
+ "pyyaml>=5.1",
27
+ "xarray>=2023.1.0",
28
+ "shapely>=2.0.0",
29
+ ]
30
+
31
+ [project.urls]
32
+ "Homepage" = "https://github.com/HaizeaAnalytics/terrakio-python-api"
33
+ "Bug Tracker" = "https://github.com/HaizeaAnalytics/terrakio-python-api/issues"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,29 @@
1
+ from setuptools import setup, find_packages # Make sure to import find_packages
2
+
3
+ setup(
4
+ name="terrakio_core",
5
+ version="0.1.9",
6
+ author="Yupeng Chao",
7
+ author_email="yupeng@haizea.com.au",
8
+ description="Core components for Terrakio API clients",
9
+ url="https://github.com/HaizeaAnalytics/terrakio-python-api",
10
+ packages = find_packages(),
11
+ classifiers=[
12
+ "Programming Language :: Python :: 3",
13
+ "Programming Language :: Python :: 3.7",
14
+ "Programming Language :: Python :: 3.8",
15
+ "Programming Language :: Python :: 3.9",
16
+ "Programming Language :: Python :: 3.10",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Operating System :: OS Independent",
19
+ "Development Status :: 4 - Beta",
20
+ ],
21
+ python_requires=">=3.7",
22
+ install_requires=[
23
+ "requests>=2.25.0",
24
+ "pyyaml>=5.1",
25
+ "xarray>=2023.1.0",
26
+ "shapely>=2.0.0",
27
+ ],
28
+ metadata_version='2.2'
29
+ )
File without changes
@@ -0,0 +1,237 @@
1
+ import requests
2
+ from typing import Optional, Dict, Any
3
+ from .exceptions import APIError, ConfigurationError
4
+
5
+ class AuthClient:
6
+ def __init__(self, base_url: str = "https://dev-au.terrak.io",
7
+ verify: bool = True, timeout: int = 60):
8
+ """
9
+ Initialize the Authentication Client for Terrakio API.
10
+
11
+ Args:
12
+ base_url: Authentication API base URL
13
+ verify: Verify SSL certificates
14
+ timeout: Request timeout in seconds
15
+ """
16
+ self.base_url = base_url.rstrip('/')
17
+ self.verify = verify
18
+ self.timeout = timeout
19
+ self.session = requests.Session()
20
+ self.session.headers.update({
21
+ 'Content-Type': 'application/json'
22
+ })
23
+ self.token = None
24
+ self.api_key = None
25
+
26
+ def signup(self, email: str, password: str) -> Dict[str, Any]:
27
+ """
28
+ Register a new user account.
29
+
30
+ Args:
31
+ email: User email address
32
+ password: User password
33
+
34
+ Returns:
35
+ API response data
36
+
37
+ Raises:
38
+ APIError: If signup fails
39
+ """
40
+ endpoint = f"{self.base_url}/users/signup"
41
+
42
+ payload = {
43
+ "email": email,
44
+ "password": password
45
+ }
46
+
47
+ try:
48
+ response = self.session.post(
49
+ endpoint,
50
+ json=payload,
51
+ verify=self.verify,
52
+ timeout=self.timeout
53
+ )
54
+
55
+ if not response.ok:
56
+ error_msg = f"Signup failed: {response.status_code} {response.reason}"
57
+ try:
58
+ error_data = response.json()
59
+ if "detail" in error_data:
60
+ error_msg += f" - {error_data['detail']}"
61
+ except:
62
+ pass
63
+ raise APIError(error_msg)
64
+
65
+ return response.json()
66
+ except requests.RequestException as e:
67
+ raise APIError(f"Signup request failed: {str(e)}")
68
+
69
+ def login(self, email: str, password: str) -> str:
70
+ """
71
+ Log in and obtain authentication token.
72
+
73
+ Args:
74
+ email: User email address
75
+ password: User password
76
+
77
+ Returns:
78
+ Authentication token
79
+
80
+ Raises:
81
+ APIError: If login fails
82
+ """
83
+ endpoint = f"{self.base_url}/users/login"
84
+
85
+ payload = {
86
+ "email": email,
87
+ "password": password
88
+ }
89
+
90
+ try:
91
+ response = self.session.post(
92
+ endpoint,
93
+ json=payload,
94
+ verify=self.verify,
95
+ timeout=self.timeout
96
+ )
97
+
98
+ if not response.ok:
99
+ error_msg = f"Login failed: {response.status_code} {response.reason}"
100
+ try:
101
+ error_data = response.json()
102
+ if "detail" in error_data:
103
+ error_msg += f" - {error_data['detail']}"
104
+ except:
105
+ pass
106
+ raise APIError(error_msg)
107
+
108
+ result = response.json()
109
+ self.token = result.get("token")
110
+
111
+ # Update session with authorization header
112
+ if self.token:
113
+ self.session.headers.update({
114
+ "Authorization": self.token
115
+ })
116
+
117
+ return self.token
118
+ except requests.RequestException as e:
119
+ raise APIError(f"Login request failed: {str(e)}")
120
+
121
+ def refresh_api_key(self) -> str:
122
+ """
123
+ Generate or refresh API key.
124
+
125
+ Returns:
126
+ API key
127
+
128
+ Raises:
129
+ ConfigurationError: If not authenticated
130
+ APIError: If refresh fails
131
+ """
132
+ if not self.token:
133
+ raise ConfigurationError("Not authenticated. Call login() first.")
134
+
135
+ endpoint = f"{self.base_url}/users/refresh_key"
136
+
137
+ try:
138
+ # Use session with updated headers from login
139
+ response = self.session.post(
140
+ endpoint,
141
+ verify=self.verify,
142
+ timeout=self.timeout
143
+ )
144
+
145
+ if not response.ok:
146
+ error_msg = f"API key generation failed: {response.status_code} {response.reason}"
147
+ try:
148
+ error_data = response.json()
149
+ if "detail" in error_data:
150
+ error_msg += f" - {error_data['detail']}"
151
+ except:
152
+ pass
153
+ raise APIError(error_msg)
154
+
155
+ result = response.json()
156
+ self.api_key = result.get("apiKey")
157
+ return self.api_key
158
+ except requests.RequestException as e:
159
+ raise APIError(f"API key refresh request failed: {str(e)}")
160
+
161
+ def view_api_key(self) -> str:
162
+ """
163
+ Retrieve current API key.
164
+
165
+ Returns:
166
+ API key
167
+
168
+ Raises:
169
+ ConfigurationError: If not authenticated
170
+ APIError: If retrieval fails
171
+ """
172
+ if not self.token:
173
+ raise ConfigurationError("Not authenticated. Call login() first.")
174
+
175
+ endpoint = f"{self.base_url}/users/key"
176
+
177
+ try:
178
+ # Use session with updated headers from login
179
+ response = self.session.get(
180
+ endpoint,
181
+ verify=self.verify,
182
+ timeout=self.timeout
183
+ )
184
+
185
+ if not response.ok:
186
+ error_msg = f"Failed to retrieve API key: {response.status_code} {response.reason}"
187
+ try:
188
+ error_data = response.json()
189
+ if "detail" in error_data:
190
+ error_msg += f" - {error_data['detail']}"
191
+ except:
192
+ pass
193
+ raise APIError(error_msg)
194
+
195
+ result = response.json()
196
+ self.api_key = result.get("apiKey")
197
+ return self.api_key
198
+ except requests.RequestException as e:
199
+ raise APIError(f"API key retrieval request failed: {str(e)}")
200
+
201
+ def get_user_info(self) -> Dict[str, Any]:
202
+ """
203
+ Retrieve the current user's information.
204
+
205
+ Returns:
206
+ User information data
207
+
208
+ Raises:
209
+ ConfigurationError: If not authenticated
210
+ APIError: If retrieval fails
211
+ """
212
+ if not self.token:
213
+ raise ConfigurationError("Not authenticated. Call login() first.")
214
+
215
+ endpoint = f"{self.base_url}/users/info"
216
+
217
+ try:
218
+ # Use session with updated headers from login
219
+ response = self.session.get(
220
+ endpoint,
221
+ verify=self.verify,
222
+ timeout=self.timeout
223
+ )
224
+
225
+ if not response.ok:
226
+ error_msg = f"Failed to retrieve user info: {response.status_code} {response.reason}"
227
+ try:
228
+ error_data = response.json()
229
+ if "detail" in error_data:
230
+ error_msg += f" - {error_data['detail']}"
231
+ except:
232
+ pass
233
+ raise APIError(error_msg)
234
+
235
+ return response.json()
236
+ except requests.RequestException as e:
237
+ raise APIError(f"User info retrieval request failed: {str(e)}")