A python package that implements a static dictionary as a file system.
Project description
Py Filestore
This is a simple package meant to create a static data structure similar to a dictionary that exists as a group of files.
If you have used any previous versions prior to 1.1.0, you should update as the last few updates changed how items were saved in the index and how things got hashed.
Example usage
First, download it using pip:
pip install py-filestore
Then:
from filestore import Filestore
import requests
# You can pass your preferred encoding in:
# store = Filestore(encoding='ascii') # It defaults to utf-8
# You can also force overwriting on population with
# store = Filestore(overwrite=True)
store = Filestore()
# You can treat this just like a python dictionary!
# You can populate it in two ways:
store['a'] = (1,2,3)
store.append(('b', "The alphabet is pretty cool"))
store[1] = [13.23, 321.0]
# You can store any data that is supported by python's own
# pickle package.
store['res'] = requests.get("https://api.github.com/")
# And if you have data that is not supported, you can write
# and set your own serializer and deserializer for it.
print(store)
# {'a': '(1, 2, 3)', 'b': 'The alphabet is pretty cool', 'res': '<Response [200]>', 1: [13.23, 321.0]}
# You can get items out too!
alpha = store['a']
print(alpha)
# (1, 2, 3)
print(alpha[1])
# 2
# The dictionary is saved to file under the directory ./.store
# which means you can close the session and return for it later
# as long as the working directory is the same when the class is initialized.
# However, this leaves residue on the file system. We can clean that up too!
store.clean_up() # All the saved data is gone now.
How it works:
Creating an instance of the class will create a directory on the system that will hold all the given information. An index file is created to allow repopulation over different sessions.
When data is added to the filestore, the class hashes the key with a naive, non-cryptographic hashing algorithm called FNV-1a in 32 bits. This hash becomes the name of the file. Collisions are now handled in the case that they occur!
The actual data gets serialized with python's pickle and then encoded into base64 before being written to the disk. If your data is not compatible with pickle, you can write and assign your own serializer/deserializer using store.set_serializer(my_serializer_function)
and store.set_deserializer(my_deserializer_function)
prior to inserting or removing data.
Tests
Currently, the testing.py file is not comprehensive and tests random strings of a specific length for collisions. It could use some work, but it does prove that FNV-1a has collisions if you look hard enough.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file py-filestore-1.1.0.tar.gz
.
File metadata
- Download URL: py-filestore-1.1.0.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 503b95b40246a28d92f7bb6c2c1f487558571e1b36d3b8d8bce728c3b374d9f0 |
|
MD5 | 680bf4399b1806320e735a67a5484344 |
|
BLAKE2b-256 | 628bfef18ced37d2efedb172c12139476f3bedbde9973740caf059c22e58ebf0 |
File details
Details for the file py_filestore-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: py_filestore-1.1.0-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0247f022bda5043b2bc4f0099de3da305340ac203a994a9b253f7ca505f33be5 |
|
MD5 | a12973e2412ae224c2de135c73189d51 |
|
BLAKE2b-256 | 01f4b1467225e2a4aeaa87f34a698b8e1d907fd18e6bfb3f1352f8f5b4b72b30 |