shibudb-client 1.0.0__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.
- shibudb_client-1.0.0/LICENSE +21 -0
- shibudb_client-1.0.0/PKG-INFO +384 -0
- shibudb_client-1.0.0/README.md +351 -0
- shibudb_client-1.0.0/setup.cfg +4 -0
- shibudb_client-1.0.0/setup.py +67 -0
- shibudb_client-1.0.0/shibudb_client.egg-info/PKG-INFO +384 -0
- shibudb_client-1.0.0/shibudb_client.egg-info/SOURCES.txt +10 -0
- shibudb_client-1.0.0/shibudb_client.egg-info/dependency_links.txt +1 -0
- shibudb_client-1.0.0/shibudb_client.egg-info/entry_points.txt +2 -0
- shibudb_client-1.0.0/shibudb_client.egg-info/requires.txt +7 -0
- shibudb_client-1.0.0/shibudb_client.egg-info/top_level.txt +1 -0
- shibudb_client-1.0.0/shibudb_client.py +598 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Podcopic Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: shibudb-client
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A comprehensive Python client for ShibuDb database
|
|
5
|
+
Home-page: https://github.com/Podcopic-Labs/ShibuDb
|
|
6
|
+
Author: ShibuDb Team
|
|
7
|
+
Author-email: support@shibudb.com
|
|
8
|
+
Project-URL: Bug Reports, https://github.com/Podcopic-Labs/ShibuDb/issues
|
|
9
|
+
Project-URL: Source, https://github.com/Podcopic-Labs/ShibuDb
|
|
10
|
+
Project-URL: Documentation, https://github.com/Podcopic-Labs/ShibuDb/tree/main/python_client
|
|
11
|
+
Keywords: database,key-value,vector,similarity-search,embedded
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Topic :: Database
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Requires-Python: >=3.7
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: pytest>=6.0; extra == "dev"
|
|
29
|
+
Requires-Dist: pytest-cov>=2.0; extra == "dev"
|
|
30
|
+
Requires-Dist: black>=21.0; extra == "dev"
|
|
31
|
+
Requires-Dist: flake8>=3.8; extra == "dev"
|
|
32
|
+
Requires-Dist: mypy>=0.800; extra == "dev"
|
|
33
|
+
|
|
34
|
+
# shibudb-client-python
|
|
35
|
+
ShibuDb client library for python
|
|
36
|
+
|
|
37
|
+
# ShibuDb Python Client
|
|
38
|
+
|
|
39
|
+
A comprehensive Python client for ShibuDb database that supports authentication, key-value operations, vector similarity search, and space management.
|
|
40
|
+
|
|
41
|
+
## Features
|
|
42
|
+
|
|
43
|
+
- 🔐 **Authentication & User Management**: Secure login with role-based access control
|
|
44
|
+
- 🔑 **Key-Value Operations**: Traditional key-value storage with PUT, GET, DELETE operations
|
|
45
|
+
- 🧮 **Vector Similarity Search**: Advanced vector operations with multiple index types
|
|
46
|
+
- 🗂️ **Space Management**: Create, delete, and manage different storage spaces
|
|
47
|
+
- 🛡️ **Error Handling**: Comprehensive error handling with custom exceptions
|
|
48
|
+
- 📊 **Connection Management**: Automatic connection handling with context managers
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
|
|
52
|
+
### Prerequisites
|
|
53
|
+
|
|
54
|
+
1. **ShibuDb Server**: Ensure the ShibuDb server is running
|
|
55
|
+
```bash
|
|
56
|
+
# Start the server (requires sudo)
|
|
57
|
+
sudo shibudb start 9090
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
2. **Python Requirements**: The client uses only standard library modules
|
|
61
|
+
- Python 3.7+
|
|
62
|
+
- No external dependencies required
|
|
63
|
+
|
|
64
|
+
### Setup
|
|
65
|
+
|
|
66
|
+
1. **Clone or download the client files**:
|
|
67
|
+
```bash
|
|
68
|
+
# Copy the client files to your project
|
|
69
|
+
cp shibudb_client.py your_project/
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
2. **Import the client**:
|
|
73
|
+
```python
|
|
74
|
+
from shibudb_client import ShibuDbClient, User, connect
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Quick Start
|
|
78
|
+
|
|
79
|
+
### Basic Connection and Authentication
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
from shibudb_client import ShibuDbClient
|
|
83
|
+
|
|
84
|
+
# Create client and authenticate
|
|
85
|
+
client = ShibuDbClient("localhost", 9090)
|
|
86
|
+
client.authenticate("admin", "password")
|
|
87
|
+
|
|
88
|
+
# Use context manager for automatic cleanup
|
|
89
|
+
with ShibuDbClient("localhost", 9090) as client:
|
|
90
|
+
client.authenticate("admin", "password")
|
|
91
|
+
# Your operations here
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Key-Value Operations
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
# Create and use a space
|
|
98
|
+
client.create_space("mytable", "key-value")
|
|
99
|
+
client.use_space("mytable")
|
|
100
|
+
|
|
101
|
+
# Basic operations
|
|
102
|
+
client.put("name", "John Doe")
|
|
103
|
+
response = client.get("name")
|
|
104
|
+
print(response["value"]) # "John Doe"
|
|
105
|
+
|
|
106
|
+
client.delete("name")
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Vector Operations
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
# Create a vector space
|
|
113
|
+
client.create_space("vectors", "vector", dimension=128, index_type="Flat", metric="L2")
|
|
114
|
+
client.use_space("vectors")
|
|
115
|
+
|
|
116
|
+
# Insert vectors
|
|
117
|
+
client.insert_vector(1, [0.1, 0.2, 0.3, ...])
|
|
118
|
+
client.insert_vector(2, [0.4, 0.5, 0.6, ...])
|
|
119
|
+
|
|
120
|
+
# Search for similar vectors
|
|
121
|
+
results = client.search_topk([0.1, 0.2, 0.3, ...], k=5)
|
|
122
|
+
print(results["message"]) # Search results
|
|
123
|
+
|
|
124
|
+
# Range search
|
|
125
|
+
results = client.range_search([0.1, 0.2, 0.3, ...], radius=0.5)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## API Reference
|
|
129
|
+
|
|
130
|
+
### ShibuDbClient
|
|
131
|
+
|
|
132
|
+
#### Constructor
|
|
133
|
+
```python
|
|
134
|
+
ShibuDbClient(host="localhost", port=9090, timeout=30)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
#### Authentication
|
|
138
|
+
```python
|
|
139
|
+
client.authenticate(username: str, password: str) -> Dict[str, Any]
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
#### Space Management
|
|
143
|
+
```python
|
|
144
|
+
client.create_space(name: str, engine_type: str, dimension: Optional[int] = None,
|
|
145
|
+
index_type: str = "Flat", metric: str = "L2") -> Dict[str, Any]
|
|
146
|
+
client.delete_space(name: str) -> Dict[str, Any]
|
|
147
|
+
client.list_spaces() -> Dict[str, Any]
|
|
148
|
+
client.use_space(name: str) -> Dict[str, Any]
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
#### Key-Value Operations
|
|
152
|
+
```python
|
|
153
|
+
client.put(key: str, value: str, space: Optional[str] = None) -> Dict[str, Any]
|
|
154
|
+
client.get(key: str, space: Optional[str] = None) -> Dict[str, Any]
|
|
155
|
+
client.delete(key: str, space: Optional[str] = None) -> Dict[str, Any]
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
#### Vector Operations
|
|
159
|
+
```python
|
|
160
|
+
client.insert_vector(vector_id: int, vector: List[float], space: Optional[str] = None) -> Dict[str, Any]
|
|
161
|
+
client.search_topk(query_vector: List[float], k: int = 1, space: Optional[str] = None) -> Dict[str, Any]
|
|
162
|
+
client.range_search(query_vector: List[float], radius: float, space: Optional[str] = None) -> Dict[str, Any]
|
|
163
|
+
client.get_vector(vector_id: int, space: Optional[str] = None) -> Dict[str, Any]
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
#### User Management (Admin Only)
|
|
167
|
+
```python
|
|
168
|
+
client.create_user(user: User) -> Dict[str, Any]
|
|
169
|
+
client.update_user_password(username: str, new_password: str) -> Dict[str, Any]
|
|
170
|
+
client.update_user_role(username: str, new_role: str) -> Dict[str, Any]
|
|
171
|
+
client.update_user_permissions(username: str, permissions: Dict[str, str]) -> Dict[str, Any]
|
|
172
|
+
client.delete_user(username: str) -> Dict[str, Any]
|
|
173
|
+
client.get_user(username: str) -> Dict[str, Any]
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Data Models
|
|
177
|
+
|
|
178
|
+
#### User
|
|
179
|
+
```python
|
|
180
|
+
@dataclass
|
|
181
|
+
class User:
|
|
182
|
+
username: str
|
|
183
|
+
password: str
|
|
184
|
+
role: str = "user"
|
|
185
|
+
permissions: Dict[str, str] = None
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
#### SpaceInfo
|
|
189
|
+
```python
|
|
190
|
+
@dataclass
|
|
191
|
+
class SpaceInfo:
|
|
192
|
+
name: str
|
|
193
|
+
engine_type: str
|
|
194
|
+
dimension: Optional[int] = None
|
|
195
|
+
index_type: Optional[str] = None
|
|
196
|
+
metric: Optional[str] = None
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Exceptions
|
|
200
|
+
|
|
201
|
+
- `ShibuDbError`: Base exception for all client errors
|
|
202
|
+
- `AuthenticationError`: Raised when authentication fails
|
|
203
|
+
- `ConnectionError`: Raised when connection fails
|
|
204
|
+
- `QueryError`: Raised when query execution fails
|
|
205
|
+
|
|
206
|
+
## Examples
|
|
207
|
+
|
|
208
|
+
### Complete Example
|
|
209
|
+
|
|
210
|
+
```python
|
|
211
|
+
from shibudb_client import ShibuDbClient, User
|
|
212
|
+
|
|
213
|
+
def main():
|
|
214
|
+
# Connect and authenticate
|
|
215
|
+
with ShibuDbClient("localhost", 9090) as client:
|
|
216
|
+
client.authenticate("admin", "password")
|
|
217
|
+
|
|
218
|
+
# Create spaces
|
|
219
|
+
client.create_space("users", "key-value")
|
|
220
|
+
client.create_space("embeddings", "vector", dimension=128)
|
|
221
|
+
|
|
222
|
+
# Store user data
|
|
223
|
+
client.use_space("users")
|
|
224
|
+
client.put("user1", "Alice Johnson")
|
|
225
|
+
client.put("user2", "Bob Smith")
|
|
226
|
+
|
|
227
|
+
# Store embeddings
|
|
228
|
+
client.use_space("embeddings")
|
|
229
|
+
client.insert_vector(1, [0.1, 0.2, 0.3, ...])
|
|
230
|
+
client.insert_vector(2, [0.4, 0.5, 0.6, ...])
|
|
231
|
+
|
|
232
|
+
# Search for similar embeddings
|
|
233
|
+
results = client.search_topk([0.1, 0.2, 0.3, ...], k=5)
|
|
234
|
+
print(f"Search results: {results}")
|
|
235
|
+
|
|
236
|
+
if __name__ == "__main__":
|
|
237
|
+
main()
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### Error Handling
|
|
241
|
+
|
|
242
|
+
```python
|
|
243
|
+
from shibudb_client import ShibuDbClient, AuthenticationError, ConnectionError, QueryError
|
|
244
|
+
|
|
245
|
+
try:
|
|
246
|
+
client = ShibuDbClient("localhost", 9090)
|
|
247
|
+
client.authenticate("admin", "password")
|
|
248
|
+
|
|
249
|
+
# Your operations here
|
|
250
|
+
|
|
251
|
+
except AuthenticationError as e:
|
|
252
|
+
print(f"Authentication failed: {e}")
|
|
253
|
+
except ConnectionError as e:
|
|
254
|
+
print(f"Connection failed: {e}")
|
|
255
|
+
except QueryError as e:
|
|
256
|
+
print(f"Query failed: {e}")
|
|
257
|
+
finally:
|
|
258
|
+
client.close()
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### Advanced Usage
|
|
262
|
+
|
|
263
|
+
```python
|
|
264
|
+
from shibudb_client import ShibuDbClient, User
|
|
265
|
+
|
|
266
|
+
# Create admin user
|
|
267
|
+
admin_user = User(
|
|
268
|
+
username="admin",
|
|
269
|
+
password="adminpass",
|
|
270
|
+
role="admin"
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
# Create regular user with permissions
|
|
274
|
+
user = User(
|
|
275
|
+
username="user1",
|
|
276
|
+
password="userpass",
|
|
277
|
+
role="user",
|
|
278
|
+
permissions={"mytable": "read", "vectortable": "write"}
|
|
279
|
+
)
|
|
280
|
+
|
|
281
|
+
with ShibuDbClient("localhost", 9090) as client:
|
|
282
|
+
client.authenticate("admin", "password")
|
|
283
|
+
|
|
284
|
+
# Create users
|
|
285
|
+
client.create_user(user)
|
|
286
|
+
|
|
287
|
+
# Create spaces for different purposes
|
|
288
|
+
client.create_space("users", "key-value")
|
|
289
|
+
client.create_space("products", "key-value")
|
|
290
|
+
client.create_space("embeddings", "vector", dimension=256)
|
|
291
|
+
client.create_space("recommendations", "vector", dimension=512)
|
|
292
|
+
|
|
293
|
+
# Store data in different spaces
|
|
294
|
+
client.use_space("users")
|
|
295
|
+
client.put("user1", "Alice Johnson")
|
|
296
|
+
|
|
297
|
+
client.use_space("embeddings")
|
|
298
|
+
client.insert_vector(1, [0.1, 0.2, 0.3, ...])
|
|
299
|
+
|
|
300
|
+
# Search for recommendations
|
|
301
|
+
query_vector = [0.1, 0.2, 0.3, ...]
|
|
302
|
+
results = client.search_topk(query_vector, k=10)
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
## Running Examples
|
|
306
|
+
|
|
307
|
+
### Simple Test
|
|
308
|
+
```bash
|
|
309
|
+
python simple_test.py
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
### Comprehensive Examples
|
|
313
|
+
```bash
|
|
314
|
+
python example.py
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
## Engine Types
|
|
318
|
+
|
|
319
|
+
### Key-Value Engine
|
|
320
|
+
- Traditional key-value storage
|
|
321
|
+
- Supports PUT, GET, DELETE operations
|
|
322
|
+
- No dimension required
|
|
323
|
+
|
|
324
|
+
### Vector Engine
|
|
325
|
+
- Vector similarity search
|
|
326
|
+
- Multiple index types:
|
|
327
|
+
- **Flat**: Exact search (default)
|
|
328
|
+
- **HNSW**: Hierarchical Navigable Small World
|
|
329
|
+
- **IVF**: Inverted File Index
|
|
330
|
+
- **IVF with PQ**: Product Quantization
|
|
331
|
+
- Distance metrics:
|
|
332
|
+
- **L2**: Euclidean distance (default)
|
|
333
|
+
- **IP**: Inner product
|
|
334
|
+
- **COS**: Cosine similarity
|
|
335
|
+
|
|
336
|
+
## Security
|
|
337
|
+
|
|
338
|
+
- **Authentication Required**: All operations require valid credentials
|
|
339
|
+
- **Role-Based Access**: Admin and user roles with different permissions
|
|
340
|
+
- **Space-Level Permissions**: Read/write permissions per space
|
|
341
|
+
- **Connection Security**: TCP-based communication with timeout handling
|
|
342
|
+
|
|
343
|
+
## Troubleshooting
|
|
344
|
+
|
|
345
|
+
### Common Issues
|
|
346
|
+
|
|
347
|
+
1. **Connection Failed**
|
|
348
|
+
- Ensure ShibuDb server is running: `sudo shibudb start 9090`
|
|
349
|
+
- Check server port and host settings
|
|
350
|
+
- Verify firewall settings
|
|
351
|
+
|
|
352
|
+
2. **Authentication Failed**
|
|
353
|
+
- Verify username and password
|
|
354
|
+
- Ensure user exists in the system
|
|
355
|
+
- Check user permissions
|
|
356
|
+
|
|
357
|
+
3. **Space Not Found**
|
|
358
|
+
- Use `list_spaces()` to see available spaces
|
|
359
|
+
- Create space before using: `create_space()`
|
|
360
|
+
- Use `use_space()` to switch to a space
|
|
361
|
+
|
|
362
|
+
4. **Vector Dimension Mismatch**
|
|
363
|
+
- Ensure vector dimension matches space dimension
|
|
364
|
+
- Check space creation parameters
|
|
365
|
+
- Verify vector format (comma-separated floats)
|
|
366
|
+
|
|
367
|
+
### Debug Mode
|
|
368
|
+
|
|
369
|
+
Enable debug logging:
|
|
370
|
+
```python
|
|
371
|
+
import logging
|
|
372
|
+
logging.basicConfig(level=logging.DEBUG)
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
## Contributing
|
|
376
|
+
|
|
377
|
+
1. Fork the repository
|
|
378
|
+
2. Create a feature branch
|
|
379
|
+
3. Add tests for new functionality
|
|
380
|
+
4. Submit a pull request
|
|
381
|
+
|
|
382
|
+
## License
|
|
383
|
+
|
|
384
|
+
This client is provided as-is for use with ShibuDb database.
|