Skip to main content

Pcodec-compressed numpy arrays — drop-in save/load for .npc/.npcz files

Project description

npco

Pcodec-compressed numpy arrays — a drop-in replacement for numpy.save/numpy.load.

npco stores ndarrays in .npc files (single array) and .npcz files (multiple arrays) using pcodec compression. The API mirrors numpy's save/load/savez so you can start using it immediately.

Install

pip install npco

Quick start

import numpy as np
import npco

# Save a single array
arr = np.random.default_rng(0).standard_normal((1000, 100))
npco.save("data.npc", arr)

# Load it back
arr = npco.load("data.npc")

# Save multiple arrays
npco.savez("data.npcz", x=arr, labels=np.arange(1000))

# Load them back (lazy, dict-like)
with npco.load("data.npcz") as data:
    print(data.files)  # ['x', 'labels']
    x = data["x"]

Compression options

Note: Compression levels greater than 8 often have limited effect on the compressed size but are significantly slower.

# Set compression level (0–12, higher = smaller + slower)
npco.save("data.npc", arr, compression_level=8)

# Or pass a full ChunkConfig for advanced control
from pcodec import ChunkConfig, DeltaSpec

npco.save(
    "data.npc",
    arr,
    chunk_config=ChunkConfig(
        compression_level=8,
        delta_spec=DeltaSpec.try_consecutive(2),
    ),
)

Supported dtypes

float16, float32, float64, int8, int16, int32, int64, uint8, uint16, uint32, uint64.

Unsupported dtypes (complex, object, strings, …) raise TypeError.

API

Function Description
npco.save(file, arr, *, compression_level=None, chunk_config=None) Save one array to .npc
npco.load(file) Load from .npc → ndarray, or .npcz → NpczFile
npco.savez(file, *args, compression_level=None, chunk_config=None, **kwds) Save multiple arrays to .npcz

File format

.npc uses a numpy-style binary header (magic \x93NPCO\x00, dtype, shape, memory order) followed by pcodec standalone compressed data.

.npcz is a ZIP archive of .npc entries (no zip-level compression since pcodec already compresses the data).

Limitations

  • No memory-mapping — pcodec requires full decompression
  • No pickle / object arrays — only numeric dtypes above are supported

Acknowledgements

Made with the assistance of Claude Opus 4.6.

License

MIT License (see LICENSE file).

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

npco-0.1.0.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

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

npco-0.1.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file npco-0.1.0.tar.gz.

File metadata

  • Download URL: npco-0.1.0.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for npco-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cfaa494dbe4f92f54b622de70d6fdd5191edb243e4e7a61ca4c71aa19334d819
MD5 fc0322a85a207b17bb137beb42ed4dd2
BLAKE2b-256 31df5c7d38f7e38a9f0e2d80d3b5855863ce1d0902c5757a5d09a03ed9d1d3bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for npco-0.1.0.tar.gz:

Publisher: publish.yml on Skielex/npco

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file npco-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: npco-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for npco-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 159c7b8d535c7e8a0bf95c3306195240bebf0ca0a68a535289f7c7f7620e9a57
MD5 7f23e3ffa11241374a154e8b2919fbe0
BLAKE2b-256 975f5a2e60df78b9f0ae1471f69e9d84c8b23df1f3a868e47b8cb09eb9025ae4

See more details on using hashes here.

Provenance

The following attestation bundles were made for npco-0.1.0-py3-none-any.whl:

Publisher: publish.yml on Skielex/npco

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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