Skip to main content

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.

Example usage

First, download it using pip:

pip install py-filestore

Then:

from filestore import Filestore

# 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"))

print(store)
# >>> {'a': '(1, 2, 3)', 'b': 'The alphabet is pretty cool'}

# 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. I have no proof that collisions are completely handled yet.

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

py-filestore-1.0.2.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

py_filestore-1.0.2-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file py-filestore-1.0.2.tar.gz.

File metadata

  • Download URL: py-filestore-1.0.2.tar.gz
  • Upload date:
  • Size: 6.0 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

Hashes for py-filestore-1.0.2.tar.gz
Algorithm Hash digest
SHA256 f44883cae41fe012b1bdf5f026e8bae49ce7b6f0dfd3f5af6208393cf0892bb1
MD5 872f94c6d74fadc574076f5eb1573864
BLAKE2b-256 818635ee1b0c1a19fe18ab35e3f9bb56dfdf3e72dc12bebde484bd916bb731e3

See more details on using hashes here.

File details

Details for the file py_filestore-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: py_filestore-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.4 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

Hashes for py_filestore-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6e43788036ea538417258fcaa9ec314f3a307d5958a34fe0d498c51b07f273a3
MD5 534534f64e83bc3d947a4ba78439e158
BLAKE2b-256 37e49bf28f3726fd32ed889fc9a64dad1ea6d531b34010435959e5ba35971b20

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page