Skip to main content

Python binding (pyo3 / maturin)

A thin pyo3 wrapper over the single nirs4all-io Rust core (the facade crate) — all RESOLVE → INFER → CONFIGURE → MATERIALIZE logic lives in Rust; Python only adapts the results.

Layout (mixed maturin)

  • Native extension nirs4all_io._native (the pyo3 module, built from src/lib.rs).
  • Python package nirs4all_io (under python/) that wraps _native and adds the lazy SpectroDataset adapter (_adapter.py).

numpy and pandas are wheel runtime dependencies — they back the full-array SpectroDataset reconstruction and are not nirs4all.

Build & install

maturin develop          # build + install into the active venv (dev)
maturin build            # build an abi3 wheel (abi3-py311)
pip install <wheel>      # install the built wheel

Requires Python ≥ 3.11. See PACKAGING.md for the abi3 wheel / nirs4all-formats reuse details.

API

All functions are re-exported from nirs4all_io.

Function Signature Returns
detect_task_type detect_task_type(y, threshold=0.05) (task_token: str, confidence: float)
infer infer(input, conventions=None) a DatasetPlan (data input only)
to_spec to_spec(input, conventions=None, name=None) a DatasetSpec
validate validate(spec) None; raises ValueError if invalid
load load(input, *, target="assembled", conventions=None, name=None, base_dir=None, spectro_dataset_cls=None) summary dict, DatasetPackage, or a SpectroDataset
to_dataset_package to_dataset_package(input, *, conventions=None, base_dir=None, name=None) a target-agnostic DatasetPackage
describe_dataset_package describe_dataset_package(input, *, conventions=None, base_dir=None, name=None, canonical=False) package summary dict or canonical JSON
to_spectrodataset to_spectrodataset(full, *, spectro_dataset_cls=None) a SpectroDataset

Inputs (input) accept a str path, a pathlib.Path, a sequence of either (file list), or a dict (a spec). validate additionally accepts a JSON string.

Task detection (unreleased source candidate). The new export delegates once through the native f64 owner and returns regression, binary or multiclass with its confidence. It is a scored pair, distinct from the SDK TaskType enum. Input is converted by np.asarray(y).ravel().astype(float).tolist() without mutation: scalars, rectangular lists, noncontiguous arrays, booleans and numeric strings are accepted; object None becomes NaN. Empty/all-NaN input returns ("regression", 0.0). Unconvertible labels and ragged inputs raise NumPy's conversion errors. Complex-to-real conversion warnings propagate.

Thresholds use native f64 extraction with no clamp, including negative, infinite or NaN thresholds. For fractional values, a NumPy float32 threshold can differ from reference arithmetic because the owner compares in f64. Invalid threshold types raise native extraction errors even for integer observations. Infinities return ("regression", 0.8); reference-only NumPy arithmetic warnings for them are not reproduced. Conversion warnings remain observable. No NumPy dependency floor qualification is implied.

This describes candidate source, not availability in a named released version. The delivery source map identifies the candidate. Native/wheel qualification is separate: the candidate wheel and native hashes must differ from the retained published artifact, with exactly one _native.abi3.so member, matching RECORD and installed bytes, strict isolated origins, and no eager SDK import. No consumer dependency or release is authorized by this source change.

Typed results. infer returns a DatasetPlan and to_spec a DatasetSpec. Both subclass dict — they stay subscriptable, JSON-serializable, and valid inputs to validate / load — and add a readable repr plus convenience accessors:

  • DatasetSpec: .name, .schema_version, .sources.
  • DatasetPlan: .overall_score, .resolved_spec (a DatasetSpec), .recommendations, .warnings, and .decisions() (the scored structure/signal_type/task_type decisions, keyed by kind).
>>> plan = nio.infer("/data/run")
>>> plan
DatasetPlan(overall_score=0.883, structure='x_y_separate'(0.85), ...)
>>> plan.decisions().keys()
dict_keys(['structure', 'signal_type', 'task_type'])
>>> plan.resolved_spec
DatasetSpec(name='data', schema_version=1, sources=[data:mixed])

load targets:

  • target="assembled" → the rounded structural summary dict (no nirs4all).
  • target="dataset_package" / target="package" → a target-agnostic DatasetPackage with payload manifest hashes and an assembled view.
  • target="spectrodataset" → a real nirs4all SpectroDataset, built via a lazy nirs4all import inside the adapter. This is the only nirs4all touch-point; import nirs4all_io never imports nirs4all (enforced by tests/test_import_boundary.py). Inject spectro_dataset_cls= to drive the builder with a double (testing without nirs4all).

Usage

from pathlib import Path
import nirs4all_io as nio

task, confidence = nio.detect_task_type([0, 1])  # ("binary", 0.9)

plan = nio.infer(Path("/data/run"))            # DatasetPlan (typed dict)
spec = nio.to_spec("/data/run")                # DatasetSpec (typed dict)
nio.validate(spec)                             # raises ValueError if invalid

print(spec.schema_version, len(spec.sources))  # convenience accessors
print(plan.decisions())                        # scored inference decisions

summary = nio.load("/data/run")                # target="assembled" (default)
package = nio.to_dataset_package("/data/run")  # target-agnostic package
ds = nio.load("/data/run", target="spectrodataset")   # nirs4all SpectroDataset

Test

pytest bindings/python/tests

The separate installed-candidate gate uses N4IO_TEST_WHEEL for the exact built wheel and N4IO_TEST_SOURCE_MAP for its gzipped delivery source map. Run the native tests and import-boundary test from an isolated working directory with PYTHONPATH unset, interpreter -I -B, an empty pytest configuration and --import-mode=importlib. The tests require real installed native origins; source-only static/marshalling checks cannot satisfy this gate.

Metadata

Release files for nirs4all-io 0.3.2

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

Source distribution (sdist)

Source distribution for nirs4all-io 0.3.2
File Size Uploaded Provenance Actions
nirs4all_io-0.3.2.tar.gz 1.9 MB With provenance Details for nirs4all_io-0.3.2.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for nirs4all-io 0.3.2
File Interpreter ABI Platform Actions
nirs4all_io-0.3.2-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details for nirs4all_io-0.3.2-cp311-abi3-win_amd64.whl
nirs4all_io-0.3.2-cp311-abi3-manylinux_2_34_x86_64.whl CPython 3.11 abi3 Linux glibc 2.34+ x86-64 Details for nirs4all_io-0.3.2-cp311-abi3-manylinux_2_34_x86_64.whl
nirs4all_io-0.3.2-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for nirs4all_io-0.3.2-cp311-abi3-macosx_11_0_arm64.whl

Total release size: 15.0 MB

Release files / nirs4all_io-0.3.2.tar.gz

Download URL nirs4all_io-0.3.2.tar.gz
Size 1.9 MB
Tags Source
SHA-256 checksum
How to use checksums
b7891d42c9f8c9fb905b51b560f2341b248f74337e74b8a40578550eac6d4b01
BLAKE2b-256 checksum
How to use checksums
45ef056acadab85d34f1f1aa2df2bcaead98d2c02df3b7cb84cf9eb127f59a37
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 9, 2026.

Transparency log

Release files / nirs4all_io-0.3.2-cp311-abi3-win_amd64.whl

Download URL nirs4all_io-0.3.2-cp311-abi3-win_amd64.whl
Size 4.0 MB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
01f03aa2f1f8b206b4b17a7bcf01451f679abb923e63cb859a09bea62e47bd66
BLAKE2b-256 checksum
How to use checksums
bd9969050f3c2c277f6b98428d890f09a42cd2325724d30cb30e3125102d891e
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 9, 2026.

Transparency log

Release files / nirs4all_io-0.3.2-cp311-abi3-manylinux_2_34_x86_64.whl

Download URL nirs4all_io-0.3.2-cp311-abi3-manylinux_2_34_x86_64.whl
Size 5.0 MB
Tags CPython 3.11 Linux glibc 2.34+ x86-64 abi3
SHA-256 checksum
How to use checksums
c829b79809671a209b97c6b435b197a9141927fbe97bdd26c3bb9bffb2557da1
BLAKE2b-256 checksum
How to use checksums
5fdc6a42046e10cfe2d6bc7c83002364736d07d7b278184f51c84729c4d3f93c
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 9, 2026.

Transparency log

Release files / nirs4all_io-0.3.2-cp311-abi3-macosx_11_0_arm64.whl

Download URL nirs4all_io-0.3.2-cp311-abi3-macosx_11_0_arm64.whl
Size 4.1 MB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
f21b5b95e760c063bd7b8f75acaee665be06a71b1e235c2a8b1b13953c7f2191
BLAKE2b-256 checksum
How to use checksums
ec2f71818246194c703dbbdb1c65a7d7cae2fd4f893d71bedf7b1573d1365b23
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 9, 2026.

Transparency log

Security for nirs4all-io 0.3.2

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 4 files in this release have been uploaded with provenance metadata.

Select from 4 files

Attestation for nirs4all_io-0.3.2.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 9, 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.

Release history Release notifications | RSS feed

This release

0.3.2 This release

4 release files Full provenance

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