Skip to main content

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() and unique().
  • Slots-based Struct records for compact scientific data containers.
  • ArrayModel validation for array fields, dimensions, and matching lengths.
  • Quantity values 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, containing T at the leaves.
  • NestedSequence[T] means nested lists or tuples.
  • ArrayLike[T] means a scalar T, a nested sequence of T, 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

scihelpers-0.1.0.tar.gz (31.5 kB view details)

Uploaded Source

Built Distribution

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

scihelpers-0.1.0-py3-none-any.whl (33.0 kB view details)

Uploaded Python 3

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

Hashes for scihelpers-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ccbd920b15aac4845a456c40eb1af81533f60ec921b20a86a8c1f55d894799f6
MD5 f446b7e9beadbb065b67928429b4c2b3
BLAKE2b-256 b0b6cd1077cdaa30f33cd0f17d487129ad5bf8078d8c7a12312ada429486cf1b

See more details on using hashes here.

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

Hashes for scihelpers-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9feab6b8b8b23b199eb795feaf733b6ad84d4f5b8fd3568986f365889e1ee66d
MD5 5adc15bde4b8806d8bc168f350038c0c
BLAKE2b-256 96841dd9dac9aabb7f9346f1a3c59e4eb7e43773029d9c887779289934a41753

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

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