pickledict
pickledict/jsondict and picklelist/jsonlist are auto-saving wrappers around their contained types. Their API is the same as the underlying type, dict or list, but writes are recorded to a file and are transparently re-loaded on subsequent runs.
from pickledict import jsondict
my_dict = jsondict(some_key="a value")
# Writes and modifications are automatically recorded and saved
my_dict["dog"] = 1
my_dict["dog"] += 1
print(my_dict)
# The first invocation creates a save file for the dict
$ python example.py
{'some_key': 'a value', 'another_key': 1}
# The data is saved to a file named: <filename>-<lineno>-<variable name>.json
$ cat .pickledict/example-3-my_dict.json
{"some_key": "a value", "dog": 2}
# A second invocation reads the saved file on construction
$ python example.py
{'some_key': 'a value', 'another_key': 2}
# As does a third, etc.
$ python example.py
{'some_key': 'a value', 'another_key': 3}
Installation
# requires Python 3.6+
pip install pickledict
Usage
dicts can be saved with either JSON or Python's pickle format (Pickle supports the preservation of certain things JSON does not, such as non-string keys).
All of pickledict, jsondist, picklelist, and jsonlist support the same constructor arguments:
file_name(str) - explicitly specify the file name to save this object in (if not provided one will be generated from the assigned variable name if possible)save_on_every_write(bool) - save on every modification of the structure. Turning this off saves only on program exit (which may increase performance)serializer_args(Dict[str, Any]) - keyword arguments to pass to the relevant serializationdumpfunction
They all each add one method: detach() which disconnects the in-memory object from the file on disk so it can be manipulated without worrying about affecting the underlying file.
Use Cases
Fetch data from a remote source and store it locally automatically without dealing directly with serialization:
Without pickledict:
import json
import os
if os.path.exists("db.json"):
with open("db.json", "r") as f:
local_db = json.load(f)
else:
local_db = {}
for i in range(100):
key, data = fetch_some_data(i)
local_db[key] = data
with open("db.json", "w") as f:
json.dump(local_db, f, indent=2)
With pickledict:
from pickledict import jsondict
local_db = jsondict(file_name="db.json", serializer_args={"indent": 2})
for i in range(100):
key, data = fetch_some_data(i)
# This will automatically persist the data out to disk
local_db[key] = data
Metadata
Release files for pickledict 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pickledict-1.0.2.tar.gz | 5.3 kB | Without provenance | Details for pickledict-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pickledict-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for pickledict-1.0.2-py3-none-any.whl |
Total release size: 10.5 kB
Release files / pickledict-1.0.2.tar.gz
| Download URL | pickledict-1.0.2.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e59b26b9bce35f4c1f29d26695e655b27e0ab3142985517c9e314eb33aeb49cb
|
|
BLAKE2b-256 checksum How to use checksums |
a36d3dedd09fe28334167d32798c82225e329b4ad7c033a5a9cc7db5e72f6acc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.23.0 setuptools/46.4.0.post20200518 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3
|
Release files / pickledict-1.0.2-py3-none-any.whl
| Download URL | pickledict-1.0.2-py3-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c7ea7b6781fbba08d42cc1daae951cb5f2cb92465a8f18cb58c742a4175bc7d3
|
|
BLAKE2b-256 checksum How to use checksums |
894b4773e58fb0d01c9a1f288b5e3a894a822511797c651e90293b1380c8a197
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.23.0 setuptools/46.4.0.post20200518 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3
|
Security for pickledict 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.