erioon 0.0.3__py3-none-any.whl → 0.0.5__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
@@ -35,7 +35,11 @@ class ErioonClient:
35
35
  self.token_path = os.path.expanduser(f"~/.erioon_token_{self._safe_filename(email)}")
36
36
 
37
37
  try:
38
- self.user_id = self._load_or_login()
38
+ metadata = self._load_or_login()
39
+ self.user_id = metadata.get("_id")
40
+ self.database = metadata.get("database")
41
+ self.cluster = metadata.get("cluster")
42
+ self.login_metadata = metadata
39
43
  except Exception as e:
40
44
  self.error = str(e)
41
45
 
@@ -51,49 +55,39 @@ class ErioonClient:
51
55
  """
52
56
  return "".join(c if c.isalnum() else "_" for c in text)
53
57
 
54
- def _load_or_login(self):
58
+ def _do_login_and_cache(self):
55
59
  """
56
- Load cached user_id token from local storage or perform login if not cached.
60
+ Perform login to API and cache the metadata locally.
57
61
 
58
62
  Returns:
59
- str: User ID from token or fresh login.
60
-
61
- Raises:
62
- Exception: If login fails.
63
+ dict: Login metadata including user_id, database, cluster.
63
64
  """
64
- if os.path.exists(self.token_path):
65
- with open(self.token_path, "r") as f:
66
- token_data = json.load(f)
67
- user_id = token_data.get("user_id")
68
- if user_id:
69
- return user_id
70
-
71
- return self._do_login_and_cache()
65
+ metadata = self._login()
66
+ with open(self.token_path, "w") as f:
67
+ json.dump(metadata, f)
68
+ return metadata
72
69
 
73
- def _do_login_and_cache(self):
70
+ def _load_or_login(self):
74
71
  """
75
- Perform login to API and cache the user_id token locally.
72
+ Load cached metadata or perform login.
76
73
 
77
74
  Returns:
78
- str: User ID from successful login.
79
-
80
- Raises:
81
- Exception: If login fails.
75
+ dict: Login metadata.
82
76
  """
83
- user_id = self._login()
84
- with open(self.token_path, "w") as f:
85
- json.dump({"user_id": user_id}, f)
86
- return user_id
77
+ if os.path.exists(self.token_path):
78
+ with open(self.token_path, "r") as f:
79
+ metadata = json.load(f)
80
+ if "user_id" in metadata:
81
+ return metadata
82
+
83
+ return self._do_login_and_cache()
87
84
 
88
85
  def _login(self):
89
86
  """
90
- Authenticate with Erioon API using email and password.
87
+ Authenticate and return full login metadata.
91
88
 
92
89
  Returns:
93
- str: User ID on successful authentication.
94
-
95
- Raises:
96
- Exception: If credentials are invalid.
90
+ dict: Metadata with user_id, database, cluster, etc.
97
91
  """
98
92
  url = f"{self.base_url}/login_with_credentials"
99
93
  payload = {"email": self.email, "password": self.password}
@@ -101,10 +95,13 @@ class ErioonClient:
101
95
 
102
96
  response = requests.post(url, json=payload, headers=headers)
103
97
  if response.status_code == 200:
104
- return response.text.strip()
98
+ data = response.json()
99
+ self.login_metadata = data
100
+ return data
105
101
  else:
106
102
  raise Exception("Invalid account")
107
103
 
104
+
108
105
  def _clear_cached_token(self):
109
106
  """
110
107
  Remove cached token file and reset user_id to None.
@@ -172,7 +169,12 @@ class ErioonClient:
172
169
 
173
170
  if response.status_code == 200:
174
171
  db_info = response.json()
175
- return Database(self.user_id, db_info)
172
+ return Database(
173
+ user_id=self.user_id,
174
+ metadata=db_info,
175
+ database=self.database,
176
+ cluster=self.cluster
177
+ )
176
178
  else:
177
179
  try:
178
180
  error_json = response.json()
erioon/collection.py CHANGED
@@ -1,8 +1,5 @@
1
1
  import json
2
2
  import requests
3
- from colorama import Fore, Style, init
4
-
5
- init(autoreset=True)
6
3
 
7
4
  class Collection:
8
5
  def __init__(
@@ -11,6 +8,8 @@ class Collection:
11
8
  db_id,
12
9
  coll_id,
13
10
  metadata,
11
+ database,
12
+ cluster,
14
13
  base_url: str = "https://sdk.erioon.com",
15
14
  ):
16
15
  """
@@ -27,11 +26,17 @@ class Collection:
27
26
  self.db_id = db_id
28
27
  self.coll_id = coll_id
29
28
  self.metadata = metadata
29
+ self.database = database
30
+ self.cluster = cluster
30
31
  self.base_url = base_url.rstrip("/")
31
32
 
32
33
  def _print_loading(self) -> None:
33
34
  """Print a green loading message to the terminal."""
34
- print(Fore.CYAN + "Erioon is loading..." + Style.RESET_ALL)
35
+ print("Erioon is loading...")
36
+
37
+ def _is_read_only(self):
38
+ return self.database == "read"
39
+
35
40
 
36
41
  # ---------- READ ---------- #
37
42
  def get_all(self):
@@ -90,6 +95,9 @@ class Collection:
90
95
  result = collection.insert_one(new_doc)
91
96
  """
92
97
  self._print_loading()
98
+ if self._is_read_only():
99
+ return {"status": "KO", "error": "Method not allowed. Access is only read."}
100
+
93
101
  url = f"{self.base_url}/{self.user_id}/{self.db_id}/{self.coll_id}/insert_one"
94
102
  response = requests.post(url, json=document, headers={"Content-Type": "application/json"})
95
103
  try:
@@ -110,6 +118,9 @@ class Collection:
110
118
  result = collection.insert_many(docs)
111
119
  """
112
120
  self._print_loading()
121
+ if self._is_read_only():
122
+ return {"status": "KO", "error": "Method not allowed. Access is only read."}
123
+
113
124
  url = f"{self.base_url}/{self.user_id}/{self.db_id}/{self.coll_id}/insert_many"
114
125
  response = requests.post(url, json={"records": documents})
115
126
  try:
@@ -130,6 +141,9 @@ class Collection:
130
141
  result = collection.delete_one({"name": "John"})
131
142
  """
132
143
  self._print_loading()
144
+ if self._is_read_only():
145
+ return {"status": "KO", "error": "Method not allowed. Access is only read."}
146
+
133
147
  url = f"{self.base_url}/{self.user_id}/{self.db_id}/{self.coll_id}/delete_one"
134
148
  response = requests.delete(url, json=filter_query)
135
149
  try:
@@ -149,6 +163,9 @@ class Collection:
149
163
  result = collection.delete_many({"status": "inactive"})
150
164
  """
151
165
  self._print_loading()
166
+ if self._is_read_only():
167
+ return {"status": "KO", "error": "Method not allowed. Access is only read."}
168
+
152
169
  url = f"{self.base_url}/{self.user_id}/{self.db_id}/{self.coll_id}/delete_many"
153
170
  response = requests.delete(url, json=filter_query)
154
171
  try:
@@ -173,6 +190,9 @@ class Collection:
173
190
  )
174
191
  """
175
192
  self._print_loading()
193
+ if self._is_read_only():
194
+ return {"status": "KO", "error": "Method not allowed. Access is only read."}
195
+
176
196
  url = f"{self.base_url}/{self.user_id}/{self.db_id}/{self.coll_id}/update_query"
177
197
  response = requests.patch(url, json={"filter_query": filter_query, "update_query": update_query})
178
198
  try:
erioon/database.py CHANGED
@@ -2,10 +2,12 @@ import json
2
2
  from erioon.collection import Collection
3
3
 
4
4
  class Database:
5
- def __init__(self, user_id, metadata):
5
+ def __init__(self, user_id, metadata, database=None, cluster=None):
6
6
  self.user_id = user_id
7
7
  self.metadata = metadata
8
8
  self.db_id = metadata.get("database_info", {}).get("_id")
9
+ self.database = database
10
+ self.cluster = cluster
9
11
 
10
12
  def __getitem__(self, collection_id):
11
13
  try:
@@ -19,7 +21,9 @@ class Database:
19
21
  user_id=self.user_id,
20
22
  db_id=self.db_id,
21
23
  coll_id=collection_id,
22
- metadata=coll_meta
24
+ metadata=coll_meta,
25
+ database = self.database,
26
+ cluster = self.cluster
23
27
  )
24
28
  except Exception:
25
29
  return "Connection error"
@@ -28,4 +32,5 @@ class Database:
28
32
  return json.dumps(self.metadata, indent=4)
29
33
 
30
34
  def __repr__(self):
31
- return f"<Database db_id={self.db_id}>"
35
+ return f"<Database db_id={self.db_id}, cluster={self.cluster}, database={self.database}>"
36
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: erioon
3
- Version: 0.0.3
3
+ Version: 0.0.5
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=Xlxi9QFwJglvhWp7V8F5yovTWSTXdn1sKT7hTHziG9Q,6656
3
+ erioon/collection.py,sha256=i0mmOj79D02suXhTtfJA8yH-oM7JiHyehh574JHlJn0,7686
4
+ erioon/database.py,sha256=IjtZYJtQ-8shojxYwNKnN1ZaRwwWZfOhw3PDAgapE8w,1185
5
+ erioon-0.0.5.dist-info/LICENSE,sha256=xwnq3DNlZpQyteOK9HvtHRhMdYviXTTaCDljEodFRnQ,569
6
+ erioon-0.0.5.dist-info/METADATA,sha256=uoQvqO_Yj0iNU2Eea5lQRa7f_Ss2XIQZ8WkOrxDe0B8,715
7
+ erioon-0.0.5.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
8
+ erioon-0.0.5.dist-info/top_level.txt,sha256=yjKEg85X5Q5ot46IMML_xukvIGG5YfdrLWcemjalItc,7
9
+ erioon-0.0.5.dist-info/RECORD,,
@@ -1,9 +0,0 @@
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,,
File without changes