Skip to main content

Persistent (LMDB-backed) data structures mimicking as Python native containers

Project description

Rack contains PersistentSet and PersistentDict classes that can be used to store data using set/dict semantics, while having contents persisted to mass storage.

This library can be used when you want to use sets or mappings that may be too big to fit in RAM, or you want them to be persisted to disk, either online (as they’re used) or once (to load/save data).

It uses LMDB or SQLite3 as underlying engine:

  • LMDB is a tiny in-process “NoSQL” database which is very fast.

  • SQLite3 is a small in-process SQL database which stores data in single files, with a well-defined on-disk layout, and is rather space-efficient.

Contents are serialized from / deserialized to Python native objects on access, so the structures are obviously slower than in-memory counterparts.

Usage

Use rack.set*.PersistentSet as you would use a set, and rack.dict*.PersistentDict as you would use a dict, except that:

  • On construction:

    • They need to take a name argument indicating the (prefix to the) location of the underlying LMDB database.

    • For LMDB, they can take a hash argument if you want to specify a non-default hasher (default is SHA256).

    • They can take a serdes argument which you can use to specify a non-default serializer/deserializer (default is Python’s marshal).

  • On use:

    • They must be used with a context manager, which is required in order to properly manage the lifetime of the database open/close, as __init__ / __del__ would not be sufficient due to the garbage collected nature of Python.

    • Operations that create a new container (eg. union, copy), take an optional name parameter, which allows to specify the location of the new database.

If you know you store elements of limited size (less than LMDB max key size), you can use rack.set_small.PersistentSet, which is ~2x faster than the non-small one due to one less indirection. If keys are too big, lmdb.BadValsizeError exceptions will occur.

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

rack-0.1.2.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

rack-0.1.2-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file rack-0.1.2.tar.gz.

File metadata

  • Download URL: rack-0.1.2.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.9

File hashes

Hashes for rack-0.1.2.tar.gz
Algorithm Hash digest
SHA256 e0c32e8126ad2dd6522a6530b87d1a43a5ca4de6103b3d2528ae86c2015c8072
MD5 105dce9dc634a0aa91a1c06d663442d9
BLAKE2b-256 58fd1f7fadc596c0ec0d24e1318e94cf9a13e228b54a1d59d6d04689db6a7b03

See more details on using hashes here.

File details

Details for the file rack-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: rack-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.9

File hashes

Hashes for rack-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5a5a8bce0ac24b930c63be0ae92d9edc7c51815126be4c922942e2121e7b154b
MD5 cbfd5f46fadf2e5fbfb462a87dbda8b4
BLAKE2b-256 959ab69c9f040bb6a937171ad6d55d80166ec81fbe2858a35b75122da44dc6a1

See more details on using hashes here.

Supported by

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