FileLoader NumPy
NumPy-backed NPY, NPZ, and CSV file loaders for the
vcti-fileloader framework.
Overview
vcti-fileloader-numpy ships three loader plugins for the
vcti-fileloader framework, all implemented against NumPy:
NpyLoader— loads.npysingle-array files into a one-node subtree. Supports memory-mapped reads via themmap_modeoption.NpzLoader— loads.npzarchives (zip-of-NPY) into a multi-child subtree, one child per array name. Defaults toLazyDataNodechildren so callers can browseshape/dtypewithout materialising; passlazy=Falsefor eager reads.CsvLoader— loads delimited-text files (.csv/.tsv/.txt) vianumpy.genfromtxtinto a one-node subtree. Passes through anygenfromtxtkeyword; whennames=Trueis used, the loader stamps the column names on the subtree root asfile_attributes["columns"].
All three implement the vcti.fileloader.core.Loader protocol and
write against the LockableTree protocol from vcti-tree, so the
caller picks the backing.
Installation
pip install vcti-fileloader-numpy>=1.0.2
In pyproject.toml dependencies
dependencies = [
"vcti-fileloader-numpy>=1.0.2",
]
Quick Start
NPY
from pathlib import Path
from vcti.fileloader.core import DataNode
from vcti.fileloader.numpy import NpyLoader
from vcti.tree.core import DictTree
loader = NpyLoader()
tree: DictTree[DataNode] = DictTree(DataNode())
with loader.open(Path("data.npy")) as handle:
root = loader.populate(handle, tree, tree.root_handle)
[child] = list(tree.children(root))
print(tree.payload(child).data) # the loaded array
Memory-map a large file instead of reading into memory:
arr = loader.load(Path("big.npy"), mmap_mode="r")
NPZ
from vcti.fileloader.core import materialise_subtree
from vcti.fileloader.numpy import NpzLoader
loader = NpzLoader()
tree: DictTree[DataNode] = DictTree(DataNode())
with loader.open(Path("data.npz")) as handle:
root = loader.populate(handle, tree, tree.root_handle) # lazy=True default
materialise_subtree(tree, root) # read everything
# `handle` is closed here, but the tree is still usable.
for child in tree.children(root):
p = tree.payload(child)
print(p.name, p.shape, p.dtype)
For eager reads (no closure, no handle-lifetime concern):
with loader.open(Path("data.npz")) as handle:
root = loader.populate(handle, tree, tree.root_handle, lazy=False)
CSV / TSV
from vcti.fileloader.numpy import CsvLoader
loader = CsvLoader()
tree: DictTree[DataNode] = DictTree(DataNode())
with loader.open(Path("data.csv"), delimiter=",") as handle:
root = loader.populate(handle, tree, tree.root_handle)
With a header row producing a structured array:
with loader.open(Path("data.csv"), delimiter=",", names=True) as handle:
root = loader.populate(handle, tree, tree.root_handle)
# Root's file_attributes["columns"] now lists the column names.
Subtree shapes
| Loader | Root payload | Children |
|---|---|---|
NpyLoader |
empty DataNode |
1 × DataNode(data=<array>) |
NpzLoader (lazy) |
empty DataNode |
N × LazyDataNode(name=key, shape, dtype) |
NpzLoader (eager) |
empty DataNode |
N × DataNode(name=key, data=<array>) |
CsvLoader (homogeneous) |
empty DataNode |
1 × DataNode(data=<array>) |
CsvLoader (structured, names=True) |
DataNode(file_attributes={"columns": [...]}) |
1 × DataNode(data=<array>) |
Handle lifetime contract (NPZ lazy nodes)
NpzLoader.populate(..., lazy=True) attaches LazyDataNodes whose
closures hold the open NpzFile handle. Once
loader.unload(handle) runs, those closures cannot fulfil further
.load() calls. Three patterns avoid the problem:
- Keep the handle open for the lifetime of the tree.
- Materialise then unload: call
materialise_subtree(tree, root)beforeunload. Every lazy node loads, and the tree is fully usable without the handle. - Use eager mode:
populate(..., lazy=False).
materialise_subtree(tree, root_handle) is exported from
vcti.fileloader.core.
Error handling
from vcti.fileloader.core import (
LoadError,
UnsupportedFormatError,
TreeAttachmentError,
)
try:
with loader.open(Path("data.npy")) as handle:
root = loader.populate(handle, tree, tree.root_handle)
except FileNotFoundError:
...
except UnsupportedFormatError:
# File extension is not recognised by this loader
...
except LoadError:
# File could not be parsed
...
except TreeAttachmentError:
# parent is missing, deleted, or structure-locked in `tree`
...
If populate fails partway (a parse error during NPZ traversal, or
an exception in before_lock), the partial subtree is removed
before the exception propagates — callers never see a half-built
subtree.
What this package does NOT do
- Pandas-flavoured CSV. This loader uses
numpy.genfromtxt, which is fast and dependency-free but lacks the schema inference and rich missing-value handling ofpandas.read_csv. A separatevcti-fileloader-pandasis the right home for that. - Schema validation. The loaders accept whatever NumPy parses.
Validation belongs in a
before_lockhook or downstream pass. - Streaming reads.
numpy.loadandnumpy.genfromtxtread the whole file (or array, for NPZ keys). Out-of-memory cases need a custom loader ormmap_modefor NPY. - Attribute synthesis. No
file_path, no derived storage metadata. Stamp those via thebefore_lockhook or a downstream enricher (e.g.vcti-attribute-enricher).
Dependencies
- numpy (>=1.26)
- vcti-fileloader (>=5.1.0) —
Loaderprotocol,SubtreeBuilder,DataNode,LazyDataNode,materialise_subtree(import fromvcti.fileloader.core) - vcti-tree (>=1.0.0) —
LockableTreeprotocol
Metadata
Release files for vcti-fileloader-numpy 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| vcti_fileloader_numpy-1.0.2.tar.gz | 16.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| vcti_fileloader_numpy-1.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 31.3 kB
Release files / vcti_fileloader_numpy-1.0.2.tar.gz
| Download URL | vcti_fileloader_numpy-1.0.2.tar.gz |
|---|---|
| Size | 16.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
043ff8823ac7c1a66b5e40cbaaa3607b40014c9c362bfc6e70b6fb5bd9d98849
|
|
BLAKE2b-256 checksum How to use checksums |
48faf020a7159dbacfa457600a633ce368ed623fcb5da70239a32ab42430ba5b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 Jul 17, 2026.
Transparency logRelease files / vcti_fileloader_numpy-1.0.2-py3-none-any.whl
| Download URL | vcti_fileloader_numpy-1.0.2-py3-none-any.whl |
|---|---|
| Size | 14.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
adfe1402f0a12396a7fed4d670cc98c10a77083134a3241c55b68d66d95aea53
|
|
BLAKE2b-256 checksum How to use checksums |
c7fa2c72699f3e8f8b58b5d67ada6d3370453fbfb5f989967d95c9a06be3a414
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 Jul 17, 2026.
Transparency log