Skip to main content

packmem

A list of dicts that takes a fraction of the memory. Records are stored as packed columns that you can still index, iterate, append to and update, and that can be filtered and aggregated without unpacking.

rows = [json.loads(line) for line in open("events.jsonl")]   # before
rows = packmem.load_jsonl("events.jsonl")                    # after

rows keeps working as a sequence of dicts:

len(rows); rows[0]; rows[-5:]; rows.append({...}); rows.extend(more)
rows.insert(0, {...}); rows.pop(); del rows[10:20]; rows.reverse()
rows.sort(key="bytes")         # a column name, or a function of a record as in list.sort
rows.take([3, 1, 2]); rows.copy(); rows.shuffle(); pickle.dumps(rows)
rows.set_column("source", "a.jsonl")       # one value, or one value per record
rows[3] = {...}                 # replace a record
rows.update(3, status=500)      # change fields in place
for r in rows: ...

and gains queries that run on the packed data:

rows.count(status=404)
rows.sum("bytes", agent__contains="curl")
rows.group_count("country", path__prefix="/api/")
rows.where(delay__gt=60, carrier="UA").rows(limit=10)

Loops that read a few fields per record are fastest over lazy rows, which decode a field only when it is read and write back on assignment:

for r in rows.lazy():
    total += r["bytes"]          # about as fast as looping over the original list
    r["seen"] = True             # writes to the table

A lazy row is a mapping, not a dict; use r.to_dict() where a real dict is required.

Records can be written as JSON straight from the columns, without building a dict per record:

rows.to_json()                                   # bytes holding one JSON array
rows.where(carrier="UA").to_json(limit=50, offset=100)
for chunk in rows.iter_json(batch=4096): ...     # for streaming responses

On the flight data rows.to_json() takes 0.24 s against 0.43 s for json.dumps on the original list. Values always read back equal; a few floats are written with a different, equally short, last digit than json.dumps would choose.

Filters: col=value, col__prefix, col__contains, col__gt, col__gte, col__lt, col__lte, col__between=(lo, hi).

One-line swaps

Before After
[json.loads(l) for l in f] packmem.load_jsonl(f) (path or file)
json.load(f) for a list of records packmem.load_json(f) (path or file, streamed)
list(csv.DictReader(f)) packmem.read_csv(path) (add infer=True for numbers instead of strings) or packmem.Table(csv.DictReader(f))
[dict(r) for r in cursor] packmem.Table(cursor)
[dict(zip(names, r)) for r in cursor] packmem.from_cursor(cursor) (any DB-API cursor)
list(queryset.values()) (Django) packmem.from_queryset(queryset)
any iterable of dicts packmem.Table(records)

In a web service

Hold the data once at start-up and answer from the packed columns. Responses are written as JSON straight from the columns, so no dict is built per record:

from fastapi import FastAPI, Query
from fastapi.responses import StreamingResponse
import packmem

app = FastAPI()
rows = packmem.load_jsonl("flights.jsonl")

@app.get("/flights")
def flights(carrier: str, limit: int = Query(50, ge=0, le=1000), offset: int = Query(0, ge=0)):
    view = rows.where(carrier=carrier)
    return StreamingResponse(view.iter_json(limit=limit, offset=offset), media_type="application/json")

@app.get("/destinations")
def destinations(carrier: str):
    return rows.group_count("dest", carrier=carrier)

From a database, rows go into columns without model instances or dicts. default= converts values that are not JSON-like, such as dates and decimals:

orders = packmem.from_queryset(Order.objects.filter(year=2026), default=str)                 # Django
orders = packmem.from_cursor(conn.execute("select id, customer, total from orders"))        # any DB-API cursor
orders.sum("total", customer="acme")

What to expect

Measured on 336,776 real flight records on an Apple M4 Pro (see benchmarks/ in the repository):

List of dicts packmem
Resident memory 712 MB 20 MB
Load from JSON lines 0.61 s 0.25 s
Filter and aggregate queries 31 to 59 ms 0.13 to 1.3 ms
Loop reading one field 31 ms 24 ms with rows.lazy(), 153 ms with plain iteration
10,000 random rows as dicts 1.3 ms 8.7 ms

Plain iteration builds a full dict per record, which is why it is slower than the list it replaces. Loading from csv.DictReader or a database cursor is 1.2 to 1.5 times slower than building the list.

Semantics to know

  • Values round-trip exactly: ints, floats (including NaN), bools, None, strings, nested lists and dicts, integers beyond 64 bits. Tuples come back as lists.
  • A returned row is a fresh dict; mutating it does not change the table. Use rows[i] = ... or rows.update(i, ...).
  • Key order in returned dicts is the order columns were first seen.
  • sum adds ints, floats and bools and skips everything else. Integers beyond 64 bits are stored exactly but are not treated as numbers by filters or sum.
  • sort, del, pop, reverse and insert anywhere but the end rebuild the table, so each takes time proportional to its size. Row numbers held by a View or a lazy row refer to positions, not records.
  • load_jsonl and load_json accept what json.loads accepts, including NaN, Infinity and strings with lone surrogate escapes.
  • Pickling the flight table gives 8 MB in 3 ms and loads in 1 ms (46 MB, 125 ms and 163 ms for the list).
  • A table can be pickled (as its packed columns, with no re-encoding on load), so it can be handed to multiprocessing and DataLoader workers started with spawn. Each worker then holds its own copy; under fork the packed data is shared.
  • rows.shuffle() and rows.take(indices) rebuild once. random.shuffle(rows) works but is far slower.

Status: alpha. pip install packmem. Requires Python 3.10 or later. Tested in CI on Linux x86-64, macOS arm64 and Windows x86-64; the Linux arm64 and musl wheels are cross-built and not exercised by tests.

Metadata

Release files for packmem 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for packmem 0.1.1
File Size Uploaded Provenance Actions
packmem-0.1.1.tar.gz 87.5 kB With provenance Details for packmem-0.1.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for packmem 0.1.1
File Actions
packmem-0.1.1-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for packmem-0.1.1-cp310-abi3-win_amd64.whl
packmem-0.1.1-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details for packmem-0.1.1-cp310-abi3-musllinux_1_2_x86_64.whl
packmem-0.1.1-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details for packmem-0.1.1-cp310-abi3-musllinux_1_2_aarch64.whl
packmem-0.1.1-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details for packmem-0.1.1-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
packmem-0.1.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details for packmem-0.1.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
packmem-0.1.1-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for packmem-0.1.1-cp310-abi3-macosx_11_0_arm64.whl
packmem-0.1.1-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details for packmem-0.1.1-cp310-abi3-macosx_10_12_x86_64.whl

Total release size: 4.2 MB

Release files / packmem-0.1.1.tar.gz

Download URL packmem-0.1.1.tar.gz
Size 87.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b9f704508c1b83b4f0e451298c698dc6b7c11d8da79af0c3ee46b86097f3009c
BLAKE2b-256 checksum
How to use checksums
43feb0e03765661fc8abe620597f72c77134543a00f5a479b8d9c5b2007ffdd7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Release files / packmem-0.1.1-cp310-abi3-win_amd64.whl

Download URL packmem-0.1.1-cp310-abi3-win_amd64.whl
Size 434.2 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
0cadfab971b0d71f78bef8231d53e00ea31455707cd2bef249819f32ecb90f69
BLAKE2b-256 checksum
How to use checksums
874835a5a359d933ef54934ad1cb4fc5f0c29516c3a4db589a6b8067344cf8e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Release files / packmem-0.1.1-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL packmem-0.1.1-cp310-abi3-musllinux_1_2_x86_64.whl
Size 778.8 kB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
69cb2cae2ec274a0f10718c219a1e65c8074756a7a570e76aa97ab2faa1f9313
BLAKE2b-256 checksum
How to use checksums
98ceae1c065d39dd91fd09a938fb830d5ae132f85fdf7e50d3ec9ae92df10188
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Release files / packmem-0.1.1-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL packmem-0.1.1-cp310-abi3-musllinux_1_2_aarch64.whl
Size 729.7 kB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
3419f75286b5ade8025d988b2d70afcf4faff6f700e6d83c13d66edf015ca95f
BLAKE2b-256 checksum
How to use checksums
3947c912841156e5af464eaf5d02ca41f4d75f74bbf81c1906bde2820a2d1d23
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Release files / packmem-0.1.1-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL packmem-0.1.1-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 566.0 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
34c1e283768e82250f13b735972316a47e8a372b01ba644a2b4cb72601a18617
BLAKE2b-256 checksum
How to use checksums
fa748e9b814ec757563b9b77723b03eac6667181bed6f456dcc3d9620415e7c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Release files / packmem-0.1.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL packmem-0.1.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 554.0 kB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
74b49a3f0dadab6f49bdfdb503d94e0061c8f6af3c4ff471f387f863165b1d03
BLAKE2b-256 checksum
How to use checksums
5478cf9e228333b64c691487d3a5f19c4c132c5efaa65a820d01c7852f0f7e92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Release files / packmem-0.1.1-cp310-abi3-macosx_11_0_arm64.whl

Download URL packmem-0.1.1-cp310-abi3-macosx_11_0_arm64.whl
Size 517.7 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e705bd7b5d2483e9743dd61cf41fb37796f9df229d1ce7869cfed1bf52e611c2
BLAKE2b-256 checksum
How to use checksums
98351a15f32bcabb6366bb0abad4456170025b93d92f9b570994bec50710aee6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Release files / packmem-0.1.1-cp310-abi3-macosx_10_12_x86_64.whl

Download URL packmem-0.1.1-cp310-abi3-macosx_10_12_x86_64.whl
Size 523.9 kB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
74ef890f2e9f8ed6576b880f7d827687d519a1e1be9347d15c4f17d589a7f26c
BLAKE2b-256 checksum
How to use checksums
6fc2c40b3f85033bbe8483536bdc4559463780480ad664fc961f191c137c8cd6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Security for packmem 0.1.1

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.

Full provenance

All 8 files in this release have been uploaded with provenance metadata.

Select from 8 files

Attestation for packmem-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page