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.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file scihelpers-0.1.0.tar.gz.
File metadata
- Download URL: scihelpers-0.1.0.tar.gz
- Upload date:
- Size: 31.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ccbd920b15aac4845a456c40eb1af81533f60ec921b20a86a8c1f55d894799f6
|
|
| MD5 |
f446b7e9beadbb065b67928429b4c2b3
|
|
| BLAKE2b-256 |
b0b6cd1077cdaa30f33cd0f17d487129ad5bf8078d8c7a12312ada429486cf1b
|
File details
Details for the file scihelpers-0.1.0-py3-none-any.whl.
File metadata
- Download URL: scihelpers-0.1.0-py3-none-any.whl
- Upload date:
- Size: 33.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9feab6b8b8b23b199eb795feaf733b6ad84d4f5b8fd3568986f365889e1ee66d
|
|
| MD5 |
5adc15bde4b8806d8bc168f350038c0c
|
|
| BLAKE2b-256 |
96841dd9dac9aabb7f9346f1a3c59e4eb7e43773029d9c887779289934a41753
|