https://github.com/sailist/dbrecord
A pure-python, light-weight, sqlite based, persistent list and dict.
https://github.com/sailist/dbrecord
persistent-storage sqlite
Last synced: 3 months ago
JSON representation
A pure-python, light-weight, sqlite based, persistent list and dict.
- Host: GitHub
- URL: https://github.com/sailist/dbrecord
- Owner: sailist
- License: gpl-3.0
- Created: 2021-11-27T05:59:01.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T06:57:55.000Z (about 2 years ago)
- Last Synced: 2025-01-31T18:56:32.089Z (3 months ago)
- Topics: persistent-storage, sqlite
- Language: Python
- Homepage:
- Size: 80.1 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dbrecord
dbrecord provides a light-weight, sqlite based, persistent list and dict.
## install
```shell
pip install dbrecord -U
```# how to use
## PDict
create a pdict
```python
from dbrecord import PDictdic = PDict('./disk.sqlite')
for i in range(5000):
dic[f'{i}'] = i
assert len(dic) == 5000dic2 = PDict('./disk.sqlite')
assert len(dic2) == 5000res, missing = dic.gets([f'{i}' for i in range(5001)]) # type: dict, set
assert len(missing) == 1
print(missing)
for i in range(5000):
assert res[f'{i}'] == i
```## PList
```python
from dbrecord import PListlis = PList('./disk.sqlite')
for i in range(20):
lis.append(i)lsl = lis[2:16:2]
assert list(lsl) == list(range(20)[2:16:2])
assert list(lsl[0:20]) == list(range(20))
assert lsl[0] == lis[2]
assert len(lsl) == (14 // 2)try:
_ = lsl[8]
assert False
except IndexError:
passfor i, j in zip(lis, range(20)):
assert i == jres, missing = lis.select([1, 1, 2, 3])
assert (res, missing) == ([1, 1, 2, 3], set())try:
_ = lis[100]
assert False
except IndexError:
pass
```# With other backend
```python
dic = PDict('./temp.sqlite', cache_size=test_size // 2,
backend_dump='quickle',
backend_load='quickle')
``````python
import jsondic = PDict('./temp.sqlite', cache_size=test_size // 2,
backend_dump=json.dumps,
backend_load=json.loads)
```# benchmark
see logs in [benchmark.md](./benchmark.md) or run
```shell
git clone https://github.com/sailist/dbrecord
cd dbrecord
cd example
python benchmark.py
```# Reference
- https://gist.github.com/joseafga/ff798d340d79107ace14fd232abc4376
- [sqlitedict](https://github.com/piskvorky/sqlitedict)
- [quickle](https://github.com/jcrist/quickle)