getme-python-sdk 1.0.0__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.
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from .core.client import GetMeClient
|
|
2
|
+
|
|
3
|
+
__all__ = ["GetMeClient"]
|
|
4
|
+
|
|
5
|
+
# ==========================================
|
|
6
|
+
# Example Usage (Flask Server integration):
|
|
7
|
+
# ==========================================
|
|
8
|
+
# from flask import Flask, request
|
|
9
|
+
# from getme import GetMeClient
|
|
10
|
+
#
|
|
11
|
+
# server = Flask(__name__)
|
|
12
|
+
# getMeClient = GetMeClient()
|
|
13
|
+
#
|
|
14
|
+
# @server.route('/get', methods=['GET'])
|
|
15
|
+
# def get_value():
|
|
16
|
+
# key = request.args.get('key')
|
|
17
|
+
# if not key:
|
|
18
|
+
# return "Key parameter is required", 400
|
|
19
|
+
# return getMeClient.get(key), 200
|
|
20
|
+
#
|
|
21
|
+
# if __name__ == '__main__':
|
|
22
|
+
# server.run(port=3001, debug=True)
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
import requests_unixsocket
|
|
4
|
+
from dotenv import load_dotenv
|
|
5
|
+
import json
|
|
6
|
+
from urllib.parse import quote_plus
|
|
7
|
+
|
|
8
|
+
from .constants import Constants
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class GetMeClient:
|
|
12
|
+
"""
|
|
13
|
+
A client for interacting with the getMe daemon over a Unix Domain Socket.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
def __init__(self):
|
|
17
|
+
load_dotenv()
|
|
18
|
+
self.unix_session = requests_unixsocket.Session()
|
|
19
|
+
self.sock_path = quote_plus(
|
|
20
|
+
os.getenv("GETME_SOCK_PATH", "/tmp/getMeStore/sockDir/getMe.sock")
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
def put(self, key, value):
|
|
24
|
+
"""
|
|
25
|
+
Puts a key-value pair into the store. The value is sent in the request body.
|
|
26
|
+
|
|
27
|
+
:param key: The key for the entry.
|
|
28
|
+
:param value: The value to store.
|
|
29
|
+
:raises Exception: If the server returns a non-200 status code.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
url = f"{Constants.BaseUrl}{self.sock_path}/put"
|
|
33
|
+
|
|
34
|
+
payload = {"key": key, "value": value}
|
|
35
|
+
headers = {"Content-Type": "application/json"}
|
|
36
|
+
|
|
37
|
+
response = self.unix_session.post(
|
|
38
|
+
url, data=json.dumps(payload), headers=headers
|
|
39
|
+
)
|
|
40
|
+
if response.status_code != 200:
|
|
41
|
+
raise Exception(f"Failed to put key-value pair: {response.text}")
|
|
42
|
+
|
|
43
|
+
return response.json()
|
|
44
|
+
|
|
45
|
+
def put_json(self, key, value):
|
|
46
|
+
"""Serializes value as JSON and stores it under the given key."""
|
|
47
|
+
|
|
48
|
+
json_string = json.dumps(value, separators=(",", ":"))
|
|
49
|
+
return self.put(key, json_string)
|
|
50
|
+
|
|
51
|
+
def get(self, key) -> str:
|
|
52
|
+
"""
|
|
53
|
+
Gets a value for a given key from the store.
|
|
54
|
+
|
|
55
|
+
:param key: The key to retrieve.
|
|
56
|
+
:return: The value associated with the key as a string.
|
|
57
|
+
:raises Exception: If the server returns a non-200 status code.
|
|
58
|
+
"""
|
|
59
|
+
resp = self.unix_session.get(
|
|
60
|
+
f"{Constants.BaseUrl}{self.sock_path}/get", params={"key": key}
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
if resp.status_code != 200:
|
|
64
|
+
raise Exception(f"Failed to get value for key '{key}': {resp.text}")
|
|
65
|
+
|
|
66
|
+
print(resp.content.decode("utf-8"))
|
|
67
|
+
return resp.content.decode("utf-8")
|
|
68
|
+
|
|
69
|
+
def get_json(self, key):
|
|
70
|
+
"""Gets the value for key and parses it as JSON."""
|
|
71
|
+
|
|
72
|
+
raw = self.get(key)
|
|
73
|
+
try:
|
|
74
|
+
return json.loads(raw)
|
|
75
|
+
except json.JSONDecodeError as exc:
|
|
76
|
+
raise Exception(f"value for key '{key}' is not valid JSON: {exc}") from exc
|
|
77
|
+
|
|
78
|
+
def delete(self, key):
|
|
79
|
+
"""
|
|
80
|
+
Deletes a key from the store.
|
|
81
|
+
|
|
82
|
+
:param key: The key to delete.
|
|
83
|
+
:raises Exception: If the server returns a non-200 status code.
|
|
84
|
+
"""
|
|
85
|
+
url = f"{Constants.BaseUrl}{self.sock_path}/delete"
|
|
86
|
+
response = self.unix_session.delete(url, params={"key": key})
|
|
87
|
+
if response.status_code != 200:
|
|
88
|
+
raise Exception(f"Failed to delete key-value pair: {response.text}")
|
|
89
|
+
|
|
90
|
+
def clearStore(self):
|
|
91
|
+
"""
|
|
92
|
+
Clears the entire store.
|
|
93
|
+
|
|
94
|
+
:raises Exception: If the server returns a non-200 status code.
|
|
95
|
+
"""
|
|
96
|
+
url = f"{Constants.BaseUrl}{self.sock_path}/clearStore"
|
|
97
|
+
response = self.unix_session.delete(url)
|
|
98
|
+
if response.status_code != 200:
|
|
99
|
+
raise Exception(f"Failed to clear store: {response.text}")
|
|
100
|
+
|
|
101
|
+
def batch_put(self, batch: dict):
|
|
102
|
+
"""
|
|
103
|
+
Puts multiple key-value pairs into the store.
|
|
104
|
+
|
|
105
|
+
:param batch: A dict of key-value pairs to store.
|
|
106
|
+
:raises Exception: If the server returns a non-200 status code.
|
|
107
|
+
"""
|
|
108
|
+
url = f"{Constants.BaseUrl}{self.sock_path}/batchPut"
|
|
109
|
+
headers = {"Content-Type": "application/json"}
|
|
110
|
+
|
|
111
|
+
response = self.unix_session.post(url, data=json.dumps(batch), headers=headers)
|
|
112
|
+
if response.status_code != 200:
|
|
113
|
+
raise Exception(f"Failed to batch put key-value pairs: {response.text}")
|
|
114
|
+
|
|
115
|
+
return response.json()
|
|
116
|
+
|
|
117
|
+
def batch_get(self, keys: list):
|
|
118
|
+
"""
|
|
119
|
+
Gets multiple values for given keys from the store.
|
|
120
|
+
|
|
121
|
+
:param keys: A list of keys to retrieve.
|
|
122
|
+
:return: A dictionary mapping the requested keys to their retrieved values.
|
|
123
|
+
:raises Exception: If the server returns a non-200 status code.
|
|
124
|
+
"""
|
|
125
|
+
url = f"{Constants.BaseUrl}{self.sock_path}/batchGet"
|
|
126
|
+
payload = {"keys": keys}
|
|
127
|
+
headers = {"Content-Type": "application/json"}
|
|
128
|
+
|
|
129
|
+
response = self.unix_session.post(
|
|
130
|
+
url, data=json.dumps(payload), headers=headers
|
|
131
|
+
)
|
|
132
|
+
if response.status_code != 200:
|
|
133
|
+
raise Exception(f"Failed to batch get keys: {response.text}")
|
|
134
|
+
|
|
135
|
+
return response.json()
|
|
136
|
+
|
|
137
|
+
def batch_delete(self, keys: list):
|
|
138
|
+
"""
|
|
139
|
+
Deletes multiple keys from the store.
|
|
140
|
+
|
|
141
|
+
:param keys: A list of keys to delete.
|
|
142
|
+
:raises Exception: If the server returns a non-200 status code.
|
|
143
|
+
"""
|
|
144
|
+
url = f"{Constants.BaseUrl}{self.sock_path}/batchDelete"
|
|
145
|
+
payload = {"keys": keys}
|
|
146
|
+
headers = {"Content-Type": "application/json"}
|
|
147
|
+
|
|
148
|
+
response = self.unix_session.delete(
|
|
149
|
+
url, data=json.dumps(payload), headers=headers
|
|
150
|
+
)
|
|
151
|
+
if response.status_code != 200:
|
|
152
|
+
raise Exception(f"Failed to batch delete keys: {response.text}")
|
|
153
|
+
|
|
154
|
+
return response.json()
|
|
File without changes
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: getme-python-sdk
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Add your description here
|
|
5
|
+
Author: AatirNadim
|
|
6
|
+
Author-email: AatirNadim <aatir.nadim@gmail.com>
|
|
7
|
+
Requires-Dist: certifi==2025.8.3
|
|
8
|
+
Requires-Dist: charset-normalizer==3.4.3
|
|
9
|
+
Requires-Dist: idna==3.10
|
|
10
|
+
Requires-Dist: python-dotenv==1.1.1
|
|
11
|
+
Requires-Dist: requests==2.32.5
|
|
12
|
+
Requires-Dist: requests-unixsocket==0.4.1
|
|
13
|
+
Requires-Dist: urllib3==2.5.0
|
|
14
|
+
Requires-Python: >=3.12
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
getme_python_sdk/__init__.py,sha256=vcR-vBr_d9Wq7BBfIdKfGWlpg88cgSBgIefkpKzfe9M,601
|
|
2
|
+
getme_python_sdk/core/client.py,sha256=hQXDIx6H832WSJcur6EO_DhbZ3v9-v4bu_E9vDHswR0,5184
|
|
3
|
+
getme_python_sdk/core/constants.py,sha256=7WpHnjHNXUzJBheIc-_FOU9j7uSFVXFVYpJvIkG9tVk,107
|
|
4
|
+
getme_python_sdk/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
getme_python_sdk-1.0.0.dist-info/WHEEL,sha256=f5fWSvWsg5Knq5GWa6t1nJIug0Tqo69GqAWD_9LbBKw,81
|
|
6
|
+
getme_python_sdk-1.0.0.dist-info/METADATA,sha256=5QRPwYF5NA4QL9VOKYPJavLRt3hAItK_uUxnJqouSaw,468
|
|
7
|
+
getme_python_sdk-1.0.0.dist-info/RECORD,,
|