https://github.com/ruotianluo/lmdbdict
A simple wrapper for lmdb. Support dict-like operations.
https://github.com/ruotianluo/lmdbdict
Last synced: 5 months ago
JSON representation
A simple wrapper for lmdb. Support dict-like operations.
- Host: GitHub
- URL: https://github.com/ruotianluo/lmdbdict
- Owner: ruotianluo
- License: mit
- Created: 2020-07-10T20:23:26.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-04-20T09:27:43.000Z (over 2 years ago)
- Last Synced: 2025-03-31T21:51:32.164Z (7 months ago)
- Language: Python
- Homepage:
- Size: 67.4 KB
- Stars: 23
- Watchers: 0
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lmdbdict

[](https://badge.fury.io/py/lmdbdict)
[](https://lmdbdict.readthedocs.io/en/latest/?badge=latest)This is a lib trying to make lmdb behaved like a python dict.
Many adopted from https://github.com/Lyken17/Efficient-PyTorch.
# Install
```pip install lmdbdict```or build from master:
```pip install git+https://github.com/ruotianluo/lmdbdict.git```
# How to use
```
from lmdbdict import lmdbdictlmdbpath = 'tmplmdb.lmdb'
# In write mode, you can modify keys
# keys and values can be any pickable objects
d = lmdbdict(lmdbpath, mode = 'w')
d[1] = 2; d[2] = 3
list(d.keys())
d.values() # not supported
del d[2]
# you can flush the d to make sure the data is written to the disk
d.flush()
# delete the d will also flush
del d# In read mode, you can only read
d = lmdbdict(lmdbpath, mode = 'r')
d[1]
```Learn more at the [documentation](https://lmdbdict.readthedocs.io/).
# Folder to lmdb
For directory structure like this.
```
folder1
- folder2
- x.txt
- y.txt
```
run
```
python folder2lmdb.py -f folder1 --lmdb folder1.lmdb
```
You will get keys to be `['folder2/x.txt', 'y.txt']`.