synadb 0.1.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.
- synadb-0.1.0/PKG-INFO +30 -0
- synadb-0.1.0/README.md +294 -0
- synadb-0.1.0/setup.cfg +4 -0
- synadb-0.1.0/setup.py +40 -0
- synadb-0.1.0/synadb/__init__.py +30 -0
- synadb-0.1.0/synadb/experience.py +568 -0
- synadb-0.1.0/synadb/wrapper.py +631 -0
- synadb-0.1.0/synadb.egg-info/PKG-INFO +30 -0
- synadb-0.1.0/synadb.egg-info/SOURCES.txt +13 -0
- synadb-0.1.0/synadb.egg-info/dependency_links.txt +1 -0
- synadb-0.1.0/synadb.egg-info/requires.txt +13 -0
- synadb-0.1.0/synadb.egg-info/top_level.txt +2 -0
- synadb-0.1.0/tests/__init__.py +2 -0
- synadb-0.1.0/tests/test_pandas.py +152 -0
- synadb-0.1.0/tests/test_wrapper.py +237 -0
synadb-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: synadb
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python wrapper for Syna embedded database
|
|
5
|
+
Author: Syna Team
|
|
6
|
+
Classifier: Development Status :: 3 - Alpha
|
|
7
|
+
Classifier: Intended Audience :: Developers
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Requires-Python: >=3.8
|
|
15
|
+
Requires-Dist: numpy>=1.21.0
|
|
16
|
+
Provides-Extra: ml
|
|
17
|
+
Requires-Dist: torch>=2.0.0; extra == "ml"
|
|
18
|
+
Requires-Dist: datasets>=2.14.0; extra == "ml"
|
|
19
|
+
Requires-Dist: transformers>=4.30.0; extra == "ml"
|
|
20
|
+
Provides-Extra: pandas
|
|
21
|
+
Requires-Dist: pandas>=1.3.0; extra == "pandas"
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
24
|
+
Requires-Dist: hypothesis>=6.0.0; extra == "dev"
|
|
25
|
+
Dynamic: author
|
|
26
|
+
Dynamic: classifier
|
|
27
|
+
Dynamic: provides-extra
|
|
28
|
+
Dynamic: requires-dist
|
|
29
|
+
Dynamic: requires-python
|
|
30
|
+
Dynamic: summary
|
synadb-0.1.0/README.md
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
# Syna Python Demos
|
|
2
|
+
|
|
3
|
+
This directory contains Python examples demonstrating Syna's Python wrapper and integrations.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
### 1. Build the Syna Library
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# From repository root
|
|
11
|
+
cargo build --release
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
### 2. Install Python Dependencies
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
cd demos/python
|
|
18
|
+
pip install -r requirements.txt
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### 3. Set Library Path (if needed)
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# Linux
|
|
25
|
+
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../../target/release
|
|
26
|
+
|
|
27
|
+
# macOS
|
|
28
|
+
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:../../target/release
|
|
29
|
+
|
|
30
|
+
# Or copy the library to this directory
|
|
31
|
+
cp ../../target/release/libsynadb.so . # Linux
|
|
32
|
+
cp ../../target/release/libsynadb.dylib . # macOS
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Running Demos
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
cd demos/python
|
|
39
|
+
|
|
40
|
+
# Basic usage
|
|
41
|
+
python basic_usage.py
|
|
42
|
+
|
|
43
|
+
# NumPy integration
|
|
44
|
+
python numpy_integration.py
|
|
45
|
+
|
|
46
|
+
# Pandas integration
|
|
47
|
+
python pandas_integration.py
|
|
48
|
+
|
|
49
|
+
# Async operations
|
|
50
|
+
python async_operations.py
|
|
51
|
+
|
|
52
|
+
# Context manager patterns
|
|
53
|
+
python context_manager.py
|
|
54
|
+
|
|
55
|
+
# RL experience replay
|
|
56
|
+
python rl_experience_demo.py
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Demo Descriptions
|
|
60
|
+
|
|
61
|
+
| Demo | File | Description |
|
|
62
|
+
|------|------|-------------|
|
|
63
|
+
| Basic Usage | `basic_usage.py` | Library loading, CRUD operations, error handling |
|
|
64
|
+
| NumPy | `numpy_integration.py` | Zero-copy tensor extraction to numpy arrays |
|
|
65
|
+
| Pandas | `pandas_integration.py` | DataFrame loading and time-series indexing |
|
|
66
|
+
| Async | `async_operations.py` | Non-blocking operations with asyncio |
|
|
67
|
+
| Context Manager | `context_manager.py` | Resource management with `with` statements |
|
|
68
|
+
| RL Experience | `rl_experience_demo.py` | Reinforcement learning experience replay |
|
|
69
|
+
|
|
70
|
+
## Demo Details
|
|
71
|
+
|
|
72
|
+
### 1. Basic Usage (`basic_usage.py`)
|
|
73
|
+
|
|
74
|
+
Comprehensive introduction to the Python wrapper:
|
|
75
|
+
- Library loading and path discovery
|
|
76
|
+
- Database open/close patterns
|
|
77
|
+
- All write operations (put_float, put_int, put_text, put_bytes)
|
|
78
|
+
- All read operations (get_float, get_int, get_text, get_bytes)
|
|
79
|
+
- Delete operations and key listing
|
|
80
|
+
- Error handling patterns
|
|
81
|
+
- Database compaction
|
|
82
|
+
- Data persistence
|
|
83
|
+
|
|
84
|
+
### 2. NumPy Integration (`numpy_integration.py`)
|
|
85
|
+
|
|
86
|
+
ML-focused tensor operations:
|
|
87
|
+
- Extract history as numpy arrays
|
|
88
|
+
- Zero-copy when possible
|
|
89
|
+
- Memory efficiency comparison
|
|
90
|
+
- Batch operations
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
from Syna import synadb
|
|
94
|
+
import numpy as np
|
|
95
|
+
|
|
96
|
+
with synadb("sensors.db") as db:
|
|
97
|
+
# Store time-series data
|
|
98
|
+
for temp in temperatures:
|
|
99
|
+
db.put_float("sensor/temp", temp)
|
|
100
|
+
|
|
101
|
+
# Extract as numpy array for ML
|
|
102
|
+
tensor = db.get_history_tensor("sensor/temp")
|
|
103
|
+
print(f"Shape: {tensor.shape}, dtype: {tensor.dtype}")
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### 3. Pandas Integration (`pandas_integration.py`)
|
|
107
|
+
|
|
108
|
+
DataFrame operations:
|
|
109
|
+
- Load time-series into DataFrame with timestamp index
|
|
110
|
+
- Store DataFrame back to Syna
|
|
111
|
+
- Query patterns using pandas
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
# Load to DataFrame
|
|
115
|
+
df = db.to_dataframe("sensor/*")
|
|
116
|
+
|
|
117
|
+
# Store from DataFrame
|
|
118
|
+
db.from_dataframe(df, key_prefix="data/")
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### 4. Async Operations (`async_operations.py`)
|
|
122
|
+
|
|
123
|
+
Non-blocking database access:
|
|
124
|
+
- Uses `asyncio` with thread pool executor
|
|
125
|
+
- Concurrent async reads
|
|
126
|
+
- Non-blocking writes
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
import asyncio
|
|
130
|
+
from Syna import synadb
|
|
131
|
+
|
|
132
|
+
async def async_write(db, key, value):
|
|
133
|
+
loop = asyncio.get_event_loop()
|
|
134
|
+
await loop.run_in_executor(None, db.put_float, key, value)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### 5. Context Manager (`context_manager.py`)
|
|
138
|
+
|
|
139
|
+
Resource management patterns:
|
|
140
|
+
- `with` statement usage
|
|
141
|
+
- Automatic cleanup on exception
|
|
142
|
+
- Nested context managers for multiple DBs
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
# Recommended pattern
|
|
146
|
+
with synadb("my.db") as db:
|
|
147
|
+
db.put_float("key", 3.14)
|
|
148
|
+
# Database automatically closed here
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### 6. RL Experience Replay (`rl_experience_demo.py`)
|
|
152
|
+
|
|
153
|
+
Reinforcement learning patterns:
|
|
154
|
+
- Store experience tuples (state, action, reward, next_state)
|
|
155
|
+
- Efficient batch sampling
|
|
156
|
+
- Prioritized replay support
|
|
157
|
+
|
|
158
|
+
## Python Wrapper API
|
|
159
|
+
|
|
160
|
+
### synadb Class
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
from Syna import synadb, SynaError
|
|
164
|
+
|
|
165
|
+
# Open database
|
|
166
|
+
db = synadb("my.db")
|
|
167
|
+
|
|
168
|
+
# Write operations
|
|
169
|
+
offset = db.put_float("key", 3.14)
|
|
170
|
+
offset = db.put_int("key", 42)
|
|
171
|
+
offset = db.put_text("key", "hello")
|
|
172
|
+
offset = db.put_bytes("key", b"\x00\x01\x02")
|
|
173
|
+
|
|
174
|
+
# Read operations
|
|
175
|
+
value = db.get_float("key") # Optional[float]
|
|
176
|
+
value = db.get_int("key") # Optional[int]
|
|
177
|
+
value = db.get_text("key") # Optional[str]
|
|
178
|
+
value = db.get_bytes("key") # Optional[bytes]
|
|
179
|
+
|
|
180
|
+
# History extraction (for ML)
|
|
181
|
+
tensor = db.get_history_tensor("key") # np.ndarray
|
|
182
|
+
|
|
183
|
+
# Key operations
|
|
184
|
+
exists = db.exists("key") # bool
|
|
185
|
+
keys = db.keys() # List[str]
|
|
186
|
+
db.delete("key")
|
|
187
|
+
|
|
188
|
+
# Maintenance
|
|
189
|
+
db.compact()
|
|
190
|
+
db.close()
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Error Handling
|
|
194
|
+
|
|
195
|
+
```python
|
|
196
|
+
from Syna import synadb, SynaError
|
|
197
|
+
|
|
198
|
+
try:
|
|
199
|
+
with synadb("my.db") as db:
|
|
200
|
+
db.put_float("key", 3.14)
|
|
201
|
+
except SynaError as e:
|
|
202
|
+
print(f"Error {e.code}: {e.message}")
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Error Codes
|
|
206
|
+
|
|
207
|
+
| Code | Meaning |
|
|
208
|
+
|------|---------|
|
|
209
|
+
| 0 | Generic error |
|
|
210
|
+
| -1 | Database not found in registry |
|
|
211
|
+
| -2 | Invalid path or UTF-8 |
|
|
212
|
+
| -3 | I/O error |
|
|
213
|
+
| -4 | Serialization error |
|
|
214
|
+
| -5 | Key not found |
|
|
215
|
+
| -6 | Type mismatch |
|
|
216
|
+
| -7 | Empty key not allowed |
|
|
217
|
+
| -8 | Key too long |
|
|
218
|
+
| -100 | Internal panic |
|
|
219
|
+
|
|
220
|
+
## Testing
|
|
221
|
+
|
|
222
|
+
Run the test suite:
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
cd demos/python
|
|
226
|
+
pytest tests/ -v
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
Run with hypothesis for property-based tests:
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
pytest tests/ -v --hypothesis-show-statistics
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## File Structure
|
|
236
|
+
|
|
237
|
+
```
|
|
238
|
+
demos/python/
|
|
239
|
+
├── Syna/ # Python package
|
|
240
|
+
│ ├── __init__.py
|
|
241
|
+
│ ├── wrapper.py # Main synadb class
|
|
242
|
+
│ └── experience.py # RL experience helpers
|
|
243
|
+
├── tests/ # Test suite
|
|
244
|
+
│ ├── test_wrapper.py
|
|
245
|
+
│ └── test_pandas.py
|
|
246
|
+
├── basic_usage.py # Basic operations demo
|
|
247
|
+
├── numpy_integration.py # NumPy demo
|
|
248
|
+
├── pandas_integration.py # Pandas demo
|
|
249
|
+
├── async_operations.py # Async demo
|
|
250
|
+
├── context_manager.py # Context manager demo
|
|
251
|
+
├── rl_experience_demo.py # RL demo
|
|
252
|
+
├── requirements.txt # Dependencies
|
|
253
|
+
├── setup.py # Package setup
|
|
254
|
+
└── pytest.ini # Test configuration
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## Troubleshooting
|
|
258
|
+
|
|
259
|
+
### Library Not Found
|
|
260
|
+
|
|
261
|
+
```
|
|
262
|
+
OSError: libsynadb.so: cannot open shared object file
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
Solution: Set `LD_LIBRARY_PATH` or copy the library:
|
|
266
|
+
```bash
|
|
267
|
+
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../../target/release
|
|
268
|
+
# or
|
|
269
|
+
cp ../../target/release/libsynadb.so .
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### Import Error
|
|
273
|
+
|
|
274
|
+
```
|
|
275
|
+
ModuleNotFoundError: No module named 'Syna'
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
Solution: Run from the `demos/python` directory or install the package:
|
|
279
|
+
```bash
|
|
280
|
+
cd demos/python
|
|
281
|
+
pip install -e .
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### NumPy Version Mismatch
|
|
285
|
+
|
|
286
|
+
```
|
|
287
|
+
RuntimeWarning: numpy.dtype size changed
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
Solution: Upgrade numpy:
|
|
291
|
+
```bash
|
|
292
|
+
pip install --upgrade numpy
|
|
293
|
+
```
|
|
294
|
+
|
synadb-0.1.0/setup.cfg
ADDED
synadb-0.1.0/setup.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""Setup script for Syna Python wrapper."""
|
|
2
|
+
|
|
3
|
+
from setuptools import setup, find_packages
|
|
4
|
+
|
|
5
|
+
setup(
|
|
6
|
+
name="synadb",
|
|
7
|
+
version="0.1.0",
|
|
8
|
+
description="Python wrapper for Syna embedded database",
|
|
9
|
+
author="Syna Team",
|
|
10
|
+
packages=find_packages(),
|
|
11
|
+
python_requires=">=3.8",
|
|
12
|
+
install_requires=[
|
|
13
|
+
"numpy>=1.21.0",
|
|
14
|
+
],
|
|
15
|
+
extras_require={
|
|
16
|
+
"ml": [
|
|
17
|
+
"torch>=2.0.0",
|
|
18
|
+
"datasets>=2.14.0",
|
|
19
|
+
"transformers>=4.30.0",
|
|
20
|
+
],
|
|
21
|
+
"pandas": [
|
|
22
|
+
"pandas>=1.3.0",
|
|
23
|
+
],
|
|
24
|
+
"dev": [
|
|
25
|
+
"pytest>=7.0.0",
|
|
26
|
+
"hypothesis>=6.0.0",
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
classifiers=[
|
|
30
|
+
"Development Status :: 3 - Alpha",
|
|
31
|
+
"Intended Audience :: Developers",
|
|
32
|
+
"License :: OSI Approved :: MIT License",
|
|
33
|
+
"Programming Language :: Python :: 3",
|
|
34
|
+
"Programming Language :: Python :: 3.8",
|
|
35
|
+
"Programming Language :: Python :: 3.9",
|
|
36
|
+
"Programming Language :: Python :: 3.10",
|
|
37
|
+
"Programming Language :: Python :: 3.11",
|
|
38
|
+
],
|
|
39
|
+
)
|
|
40
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Syna Python Wrapper
|
|
3
|
+
|
|
4
|
+
A high-level Python interface for the Syna embedded database.
|
|
5
|
+
|
|
6
|
+
Example:
|
|
7
|
+
>>> from Syna import SynaDB
|
|
8
|
+
>>> with SynaDB("my.db") as db:
|
|
9
|
+
... db.put_float("temperature", 23.5)
|
|
10
|
+
... print(db.get_float("temperature"))
|
|
11
|
+
23.5
|
|
12
|
+
|
|
13
|
+
For RL experience collection:
|
|
14
|
+
>>> from Syna import ExperienceCollector
|
|
15
|
+
>>> collector = ExperienceCollector("exp.db", machine_id="gpu_server_1")
|
|
16
|
+
>>> collector.log_transition(state, action, reward, next_state)
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from .wrapper import SynaDB, SynaError
|
|
20
|
+
from .experience import ExperienceCollector, Transition, SessionContext
|
|
21
|
+
|
|
22
|
+
__version__ = "0.1.0"
|
|
23
|
+
__all__ = [
|
|
24
|
+
"SynaDB",
|
|
25
|
+
"SynaError",
|
|
26
|
+
"ExperienceCollector",
|
|
27
|
+
"Transition",
|
|
28
|
+
"SessionContext",
|
|
29
|
+
]
|
|
30
|
+
|