Partd

1.4.2 · active · verified Sun Mar 29

Partd is a Python library that provides appendable key-value storage, primarily for raw bytes. It excels at shuffling operations, allowing efficient appending of data to existing values associated with a key. The current version is 1.4.2, and it appears to have a stable, though not rapid, release cadence, with the latest update in May 2024.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a file-backed Partd instance, append byte data to keys, and retrieve the accumulated data. It also includes an example of using `partd.numpy.Numpy` to store and retrieve NumPy arrays, abstracting away the byte serialization. Remember to call `.drop()` to clean up file-backed Partd stores.

import partd
import numpy as np

# Create a Partd backed by a directory (or in-memory buffer)
p = partd.File('my_partd_data') # or p = partd.Buffer()

# Append key-byte pairs
p.append({'x': b'Hello '})
p.append({'x': b'world!'})
p.append({'y': b'123'})
p.append({'y': b'456'})

# Get bytes associated to keys
print(f"Value for 'x': {p.get('x')}")
print(f"Value for 'y' and 'x': {p.get(['y', 'x'])}")

# Example with NumPy encoding
# Requires 'numpy' as an optional dependency
p_np = partd.numpy.Numpy(partd.File('my_numpy_data'))
p_np.append({'data': np.array([1, 2, 3])})
p_np.append({'data': np.array([4, 5, 6])})
print(f"NumPy array: {p_np.get('data')}")

# Clean up (for File-backed Partd)
p.drop()
p_np.drop()

view raw JSON →