erioon 0.0.2__py3-none-any.whl → 0.0.3__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.
erioon/client.py CHANGED
@@ -4,7 +4,29 @@ import requests
4
4
  from erioon.database import Database
5
5
 
6
6
  class ErioonClient:
7
- def __init__(self, email, password, base_url="http://127.0.0.1:5000"):
7
+ """
8
+ Client SDK for interacting with the Erioon API.
9
+
10
+ Handles user authentication, token caching, and accessing user databases.
11
+
12
+ Attributes:
13
+ email (str): User email for login.
14
+ password (str): User password for login.
15
+ base_url (str): Base URL of the Erioon API.
16
+ user_id (str | None): Authenticated user ID.
17
+ error (str | None): Stores error messages if login fails.
18
+ token_path (str): Local path to cached authentication token.
19
+ """
20
+
21
+ def __init__(self, email, password, base_url="https://sdk.erioon.com"):
22
+ """
23
+ Initialize ErioonClient instance, attempts to load cached token or perform login.
24
+
25
+ Args:
26
+ email (str): User email for authentication.
27
+ password (str): User password for authentication.
28
+ base_url (str, optional): Base API URL. Defaults to "https://sdk.erioon.com".
29
+ """
8
30
  self.email = email
9
31
  self.password = password
10
32
  self.base_url = base_url
@@ -18,27 +40,61 @@ class ErioonClient:
18
40
  self.error = str(e)
19
41
 
20
42
  def _safe_filename(self, text):
43
+ """
44
+ Converts a string into a safe filename by replacing non-alphanumeric chars with underscores.
45
+
46
+ Args:
47
+ text (str): Input string to convert.
48
+
49
+ Returns:
50
+ str: Sanitized filename-safe string.
51
+ """
21
52
  return "".join(c if c.isalnum() else "_" for c in text)
22
53
 
23
54
  def _load_or_login(self):
24
- # Try to load from local cache
55
+ """
56
+ Load cached user_id token from local storage or perform login if not cached.
57
+
58
+ Returns:
59
+ str: User ID from token or fresh login.
60
+
61
+ Raises:
62
+ Exception: If login fails.
63
+ """
25
64
  if os.path.exists(self.token_path):
26
65
  with open(self.token_path, "r") as f:
27
66
  token_data = json.load(f)
28
67
  user_id = token_data.get("user_id")
29
68
  if user_id:
30
- return user_id # ✅ Use cached value without API call
69
+ return user_id
31
70
 
32
- # Fallback: login and cache
33
71
  return self._do_login_and_cache()
34
72
 
35
73
  def _do_login_and_cache(self):
74
+ """
75
+ Perform login to API and cache the user_id token locally.
76
+
77
+ Returns:
78
+ str: User ID from successful login.
79
+
80
+ Raises:
81
+ Exception: If login fails.
82
+ """
36
83
  user_id = self._login()
37
84
  with open(self.token_path, "w") as f:
38
85
  json.dump({"user_id": user_id}, f)
39
86
  return user_id
40
87
 
41
88
  def _login(self):
89
+ """
90
+ Authenticate with Erioon API using email and password.
91
+
92
+ Returns:
93
+ str: User ID on successful authentication.
94
+
95
+ Raises:
96
+ Exception: If credentials are invalid.
97
+ """
42
98
  url = f"{self.base_url}/login_with_credentials"
43
99
  payload = {"email": self.email, "password": self.password}
44
100
  headers = {"Content-Type": "application/json"}
@@ -50,11 +106,31 @@ class ErioonClient:
50
106
  raise Exception("Invalid account")
51
107
 
52
108
  def _clear_cached_token(self):
109
+ """
110
+ Remove cached token file and reset user_id to None.
111
+ """
53
112
  if os.path.exists(self.token_path):
54
113
  os.remove(self.token_path)
55
114
  self.user_id = None
56
115
 
57
116
  def __getitem__(self, db_id):
117
+ """
118
+ Access a Database object by database ID.
119
+
120
+ Args:
121
+ db_id (str): The ID of the database to access.
122
+
123
+ Returns:
124
+ Database: An instance representing the database.
125
+
126
+ Raises:
127
+ ValueError: If client is not authenticated.
128
+ Exception: For other API errors not related to database existence.
129
+
130
+ Handles:
131
+ On database-related errors, tries to relogin once. If relogin fails, returns "Login error".
132
+ If database still not found after relogin, returns a formatted error message.
133
+ """
58
134
  if not self.user_id:
59
135
  raise ValueError("Client not authenticated. Cannot access database.")
60
136
 
@@ -62,28 +138,33 @@ class ErioonClient:
62
138
  return self._get_database_info(db_id)
63
139
  except Exception as e:
64
140
  err_msg = str(e).lower()
65
- # Check if error is a database error mentioning the db_id
66
141
  if f"database with {db_id.lower()}" in err_msg or "database" in err_msg:
67
- # Try relogin once
68
142
  self._clear_cached_token()
69
143
  try:
70
144
  self.user_id = self._do_login_and_cache()
71
145
  except Exception:
72
146
  return "Login error"
73
147
 
74
- # Retry fetching database info
75
148
  try:
76
149
  return self._get_database_info(db_id)
77
- except Exception as e2:
78
- print(f"❌ Database with _id {db_id} ...")
79
- # Optionally you could also return or raise the error here
150
+ except Exception:
80
151
  return f"❌ Database with _id {db_id} ..."
81
152
  else:
82
- # Not a DB-related error, just propagate or raise
83
153
  raise e
84
154
 
85
-
86
155
  def _get_database_info(self, db_id):
156
+ """
157
+ Helper method to fetch database info from API and instantiate a Database object.
158
+
159
+ Args:
160
+ db_id (str): The database ID to fetch.
161
+
162
+ Returns:
163
+ Database: Database instance with the fetched info.
164
+
165
+ Raises:
166
+ Exception: If API returns an error.
167
+ """
87
168
  payload = {"user_id": self.user_id, "db_id": db_id}
88
169
  headers = {"Content-Type": "application/json"}
89
170
 
@@ -93,7 +174,6 @@ class ErioonClient:
93
174
  db_info = response.json()
94
175
  return Database(self.user_id, db_info)
95
176
  else:
96
- # Try parse error json
97
177
  try:
98
178
  error_json = response.json()
99
179
  error_msg = error_json.get("error", response.text)
@@ -102,7 +182,13 @@ class ErioonClient:
102
182
  raise Exception(error_msg)
103
183
 
104
184
  def __str__(self):
185
+ """
186
+ String representation: returns user_id if authenticated, else the error message.
187
+ """
105
188
  return self.user_id if self.user_id else self.error
106
189
 
107
190
  def __repr__(self):
191
+ """
192
+ Developer-friendly string representation of the client instance.
193
+ """
108
194
  return f"<ErioonClient user_id={self.user_id}>" if self.user_id else f"<ErioonClient error='{self.error}'>"
erioon/collection.py CHANGED
@@ -11,7 +11,7 @@ class Collection:
11
11
  db_id,
12
12
  coll_id,
13
13
  metadata,
14
- base_url: str = "http://127.0.0.1:5000",
14
+ base_url: str = "https://sdk.erioon.com",
15
15
  ):
16
16
  """
17
17
  Initialize a Collection instance.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: erioon
3
- Version: 0.0.2
3
+ Version: 0.0.3
4
4
  Summary: Erioon SDF for Python
5
5
  Author: Zyber Pireci
6
6
  Author-email: zyber.pireci@erioon.com
@@ -0,0 +1,9 @@
1
+ erioon/auth.py,sha256=-a8g7JZKsQ_yir_iZMYbfhiBJT0hYDmfJSj6B1u3M84,704
2
+ erioon/client.py,sha256=5VKxfHUdChwFRA1bRWCt6p10y1SF7XR1PWp6wt7qQgg,6532
3
+ erioon/collection.py,sha256=AiL035fGt-SQ_MovqEDSo1M9cz20xKYutfLEq74GYGM,6924
4
+ erioon/database.py,sha256=n3arbUCYzJ1WAIh_1hgjJjUuCpyRVRP1quXGkTVgrsQ,953
5
+ erioon-0.0.3.dist-info/LICENSE,sha256=xwnq3DNlZpQyteOK9HvtHRhMdYviXTTaCDljEodFRnQ,569
6
+ erioon-0.0.3.dist-info/METADATA,sha256=ERc8TC1vVGzp2vNuvZQzrr89jApRhIV2oHnqGNrA67k,715
7
+ erioon-0.0.3.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
8
+ erioon-0.0.3.dist-info/top_level.txt,sha256=yjKEg85X5Q5ot46IMML_xukvIGG5YfdrLWcemjalItc,7
9
+ erioon-0.0.3.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- erioon/auth.py,sha256=-a8g7JZKsQ_yir_iZMYbfhiBJT0hYDmfJSj6B1u3M84,704
2
- erioon/client.py,sha256=D5QHIdEL-13-dAoT5CITqbW9RqKUGEfswtTY8kTZH8w,3990
3
- erioon/collection.py,sha256=55CXEdB7ZmuqyHzHa39-SVRk2WJN-n_Yovb9rSlL-fg,6923
4
- erioon/database.py,sha256=n3arbUCYzJ1WAIh_1hgjJjUuCpyRVRP1quXGkTVgrsQ,953
5
- erioon-0.0.2.dist-info/LICENSE,sha256=xwnq3DNlZpQyteOK9HvtHRhMdYviXTTaCDljEodFRnQ,569
6
- erioon-0.0.2.dist-info/METADATA,sha256=0KLMfL0VvGu3Z9igmof68t5jip8CRyUi2zOVmlqLF9Q,715
7
- erioon-0.0.2.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
8
- erioon-0.0.2.dist-info/top_level.txt,sha256=yjKEg85X5Q5ot46IMML_xukvIGG5YfdrLWcemjalItc,7
9
- erioon-0.0.2.dist-info/RECORD,,
File without changes