Skip to main content

A library that automatically offloads large pickle-able objects stored in a dict/list to SQLite, reducing memory usage. It can be used with the same syntax as a regular dict/list.

Project description

English · 日本語 (Japanese)

swapcollection

A library that automatically offloads large objects stored in a dict/list to SQLite, reducing memory usage. It can be used with the same syntax as a regular dict/list.

Quick Start

pip install swapcollection
from swapcollection import SwapDict, SwapList

# Spill values >= 1 MB (pickle size) to SQLite
data = SwapDict(size_threshold=1024)

data["small"] = b"hello"
data["large"] = b"x" * 100_000

# Access transparently — same as a normal dict
print(data["small"])
print(len(data["large"]))

How It Works

SwapDict / SwapList automatically offloads values whose pickled size meets or exceeds size_threshold to a SQLite database. Any pickle-able object (not just bytes) is eligible.

Value Storage
Pickle size < size_threshold In-memory
Pickle size >= size_threshold SQLite (transparent)

Spilled values are retrieved, updated, and deleted using the same dict/list interface — no special API calls needed.

Caveats

  • size_threshold is the pickle-size threshold in bytes; values >= this size are spilled.
  • size_threshold cannot be changed after instantiation.
  • Any pickle-able object type (not only bytes) can be spilled.
  • Deleting the SQLite database will cause errors on previously spilled items.

License

MIT

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

swapcollection-1.0.0.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

swapcollection-1.0.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file swapcollection-1.0.0.tar.gz.

File metadata

  • Download URL: swapcollection-1.0.0.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for swapcollection-1.0.0.tar.gz
Algorithm Hash digest
SHA256 50776b5975f68e1a00451334274e04ef7fe6173b4c1821509aaae940bd65f2c7
MD5 6c585cec90c365acde5d1de622b62c14
BLAKE2b-256 47d0859a156944e473806d6967dba07f840bdf8dd71a6d613e9cb2345521f8e7

See more details on using hashes here.

File details

Details for the file swapcollection-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: swapcollection-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for swapcollection-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 254048702dc5e341698e0c162e85946db1851c8b273d41f7ba2af775f5d001b2
MD5 6225a9d392de5585ad8a4ab4925c4dd2
BLAKE2b-256 f27c794f7a5cf4d45f92e81fee7b59b36aae84e3a6206d24fe0d58d4991a6ec1

See more details on using hashes here.

Supported by

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