Skip to main content

Easily dump python objects to files, and then load them back.

Project description

pickle-warehouse makes it easy to save Python objects to files with meaningful identifiers.

How to use

pickle-warehouse provides a dictionary-like object that is associated with a particular directory on your computer.

from pickle_warehouse import Warehouse warehouse = Warehouse(‘/tmp/a-directory’)

The keys correspond to files, and the values get pickled to the files.

warehouse['filename'] = range(100)

import pickle
range(100) == pickle.load(open('/tmp/a-directory/filename', 'rb'))

You can also read and delete things.

# Read
range(100) == warehouse['filename']

# Delete
del(warehouse['filename'])

The coolest part is that the key gets interpreted in a fancy way. Aside from strings and string-like objects, you can use iterables of strings; all of these indices refer to the file /tmp/a-directory/foo/bar/baz:

warehouse[('foo','bar','baz')]
warehouse[['foo','bar','baz']]

If you pass a URL, it will get broken up in a reasonable way.

# /tmp/a-directory/http/thomaslevine.com/!/?foo=bar#baz
warehouse['http://thomaslevine.com/!/?foo=bar#baz']

# /tmp/a-directory/thomaslevine.com/!?foo=bar#baz
warehouse['thomaslevine.com/!?foo=bar#baz']

Dates and datetimes get converted to YYYY-MM-DD format.

import datetime

# /tmp/a-directory/2014-02-26
warehouse[datetime.date(2014,2,26)]
warehouse[datetime.datetime(2014,2,26,13,6,42)]

And you can mix these formats!

# /tmp/a-directory/http/thomaslevine.com/open-data/2014-02-26
warehouse[('http://thomaslevine.com/open-data', datetime.date(2014,2,26))]

It also has typical dictionary methods like keys, values, items, and update.

When to use

Use this when you want a persistant store of Python objects. If you want an in-memory pickle store, look at _pickleDB: https://pythonhosted.org/pickleDB/.

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

pickle-warehouse-0.0.3.tar.gz (2.5 kB view details)

Uploaded Source

File details

Details for the file pickle-warehouse-0.0.3.tar.gz.

File metadata

File hashes

Hashes for pickle-warehouse-0.0.3.tar.gz
Algorithm Hash digest
SHA256 89419c009aed390b4db94f81c55c74b05930d753b5cf8738d0ec52ec88949069
MD5 bc815ceac07a0af4433b781a64fdabf1
BLAKE2b-256 b97c576e144b6d427fe361ab150bebf56584785cfb3d4036d8f58ea7ce3f1588

See more details on using hashes here.

Provenance

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