PickleShare

0.7.5 · active · verified Sun Apr 05

PickleShare is a lightweight, 'shelve'-like persistent dictionary with concurrency support, where each item is stored as a separate file using Python's `pickle` serialization. While the original `pickleshare` (version 0.7.5) has not been actively maintained since 2018, a community-maintained fork, `pickleshare-modern`, provides ongoing support for modern Python versions (3.9+) while retaining API compatibility. It's suitable for low-load, non-mission-critical persistence tasks.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a PickleShareDB, store and retrieve various data types (including nested keys), list keys, update values, and delete entries. It also includes cleanup steps for the database directory.

import os
from pickleshare import PickleShareDB

# Create a database in a temporary directory
db_path = './my_pickleshare_db'
os.makedirs(db_path, exist_ok=True)
db = PickleShareDB(db_path)

# Store some data
db['greeting'] = 'Hello, PickleShare!'
db['data/list'] = [1, 2, 3]
db['data/nested/value'] = {'a': 1, 'b': 2}

# Retrieve data
print(f"Greeting: {db['greeting']}")
print(f"List: {db['data/list']}")

# Check keys
print(f"All keys: {list(db.keys())}")

# Update data
db['greeting'] = 'Hello again!'

# Delete data
del db['data/list']

# Clean up the database directory (optional)
db.clear() # Clears all data within the db directory
os.rmdir(db_path) # Removes the empty directory

view raw JSON →