scihelpers
scihelpers is a small typed Python library for scientific-computing class helpers. It gives you dataclass-like models, enum-like constants, compact slots records, NumPy dtype inference, array validation, and lightweight physical quantities without making every project rebuild the same utilities.
The package is typed (py.typed), uses a src/ layout, and is designed to work well with strict IDE settings.
Features
- Exact NumPy dtype inference for scalars, lists, tuples, nested sequences, and arrays.
- Recursive type aliases for arbitrary-depth nested lists and array-like values.
- Dataclass-style decorators and base classes.
- Enum and IntEnum-style helpers with
auto()andunique(). - Slots-based
Structrecords for compact scientific data containers. ArrayModelvalidation for array fields, dimensions, and matching lengths.Quantityvalues with units, conversions, comparisons, and arithmetic.
Installation
From a local checkout:
python -m pip install -e .
For development tools:
python -m pip install -e .[dev]
Quick Start
from scihelpers import ArrayLike, InferType, Quantity, array_model
class Reading(InferType, compact_repr=True):
sensor_id: int
samples: ArrayLike[float]
reading = Reading(256, [[1.5, 2.5], [3.5, 4.5]])
print(reading.sensor_id.dtype) # uint16
print(reading.samples.dtype) # float16
print(reading)
distance = Quantity([0, 50, 100], "cm", compact=True)
print(distance.to("m")) # [0.0, 0.5, 1.0] m
Recursive Array Types
Use these public aliases when annotations should accept arbitrary nesting:
from scihelpers import ArrayLike, NestedList, NestedSequence
values: NestedList[float]
coordinates: NestedSequence[int]
samples: ArrayLike[float]
NestedList[T]means lists nested to any depth, containingTat the leaves.NestedSequence[T]means nested lists or tuples.ArrayLike[T]means a scalarT, a nested sequence ofT, or a NumPy array.
These aliases are for type checkers and IDEs. Runtime conversion is handled by the infer-type helpers.
Core APIs
Dtype Inference
from scihelpers import to_numpy_value, value_dtype
assert value_dtype([1, 256]).__name__ == "uint16"
array = to_numpy_value([[1, 2], [3, 4]])
Dataclass Helpers
from scihelpers import Dataclass, dataclass, field
@dataclass(order=True)
class Point:
x: float
y: float = 0.0
class Reading(Dataclass, frozen=True):
sensor: str
value: float
InferType
from scihelpers import InferType
class Sample(InferType, compact_repr=True):
count: int
values: ArrayLike[int]
ArrayModel
from scihelpers import array_model
@array_model(require_same_length=True)
class Spectrum:
wavelength: list[float]
intensity: list[float]
Struct
from scihelpers import Struct
class Particle(Struct, infer_types=True, frozen=True):
charge: int
mass: float
Enum
from scihelpers import Enum, auto, unique
@unique
class State(Enum):
READY = auto()
RUNNING = auto()
DONE = auto()
Quantity
from scihelpers import Quantity
speed = Quantity(10, "m") / Quantity(2, "s")
assert speed.unit == "m/s"
Examples
See examples/ for richer scripts covering dtype inference, custom dataclasses, enums, array models, structs, and quantities.
Run one from the repository root:
python examples\dtype_inference.py
Testing
python -m pytest tests
Status
scihelpers is early and experimental. The public API is intentionally small, but it may still change while the library settles.
Metadata
Release files for scihelpers 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| scihelpers-0.1.0.tar.gz | 31.5 kB | Without provenance | Details for scihelpers-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| scihelpers-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for scihelpers-0.1.0-py3-none-any.whl |
Total release size: 64.5 kB
Release files / scihelpers-0.1.0.tar.gz
| Download URL | scihelpers-0.1.0.tar.gz |
|---|---|
| Size | 31.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ccbd920b15aac4845a456c40eb1af81533f60ec921b20a86a8c1f55d894799f6
|
|
BLAKE2b-256 checksum How to use checksums |
b0b6cd1077cdaa30f33cd0f17d487129ad5bf8078d8c7a12312ada429486cf1b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.14
|
Release files / scihelpers-0.1.0-py3-none-any.whl
| Download URL | scihelpers-0.1.0-py3-none-any.whl |
|---|---|
| Size | 33.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9feab6b8b8b23b199eb795feaf733b6ad84d4f5b8fd3568986f365889e1ee66d
|
|
BLAKE2b-256 checksum How to use checksums |
96841dd9dac9aabb7f9346f1a3c59e4eb7e43773029d9c887779289934a41753
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.14
|
Security for scihelpers 0.1.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.