Decorator library: numpy_fn/torch_fn/pandas_fn/xarray_fn/signal_fn type converters, caching, batching, deprecation — standalone module from the SciTeX ecosystem
Project description
scitex-decorators
Decorator library — type conversion (numpy/torch/pandas/xarray), caching, batching, lifecycle.
Full Documentation · uv pip install scitex-decorators[all]
Problem and Solution
| # | Problem | Solution |
|---|---|---|
| 1 | Array-type plumbing — functions that should accept numpy / torch / pandas / xarray end up reimplementing isinstance dispatch + back-conversion every time. | @numpy_fn, @torch_fn, @pandas_fn, @xarray_fn, @signal_fn convert inputs to the named type, run the wrapped function, and restore the caller's original type on the way out. |
| 2 | Expensive recomputations dominate dev cycles; ad-hoc pickle caches drift in invalidation and disk layout. |
@cache_disk (joblib) / @cache_disk_async / @cache_mem give SciTeX-aware disk + memory caching with a documented cache-dir resolution order (scitex.config → $SCITEX_CACHE_DIR → XDG → ~/.cache). |
| 3 | GPU / memory limits force researchers to hand-batch tensors, often re-deriving the loop per project. | @batch_fn + @batch_numpy_fn / @batch_torch_fn / @batch_pandas_fn chunk inputs through the wrapped function and reassemble outputs; compose cleanly with the @*_fn converters. |
Installation
pip install scitex-decorators # core (numpy only)
pip install "scitex-decorators[caching]" # + joblib for cache_disk
pip install "scitex-decorators[torch]" # + torch_fn / batch_torch_fn
pip install "scitex-decorators[all]" # everything
Architecture
flowchart LR
AO["@auto_order"] --> CV["@*_fn converters"]
CV --> NP["@numpy_fn"]
CV --> PD["@pandas_fn"]
CV --> XR["@xarray_fn"]
CV --> TR["@torch_fn"]
CV --> SG["@signal_fn"]
BF["@batch_fn"] --> CV
CD["@cache_disk<br/>(joblib)"] -.-> NP & PD & TR
PD2["@preserve_doc"] -.-> NP & PD & TR & XR & SG
DEP["@deprecated"] -.-> NP & PD & TR
TO["@timeout"] -.-> CV
NI["@not_implemented"] -.-> CV
CO["@combined<br/>(stack of @*_fn)"] --> NP & PD & TR
Each @<type>_fn decorator converts inputs to the named type, calls the
wrapped function, then converts back to the caller's original type. The
diagram above shows how _combined.py, _auto_order.py, and the
caching/timeout decorators compose around the converter family.
Quick Start
import scitex_decorators as dec
@dec.numpy_fn
def kernel(x):
return x ** 2 # x is numpy inside; return matches caller's type
@dec.cache_disk
def expensive(x): ...
1 Interfaces
Python API
import scitex_decorators as dec
# Type-conversion decorators
@dec.numpy_fn ; @dec.torch_fn ; @dec.pandas_fn ; @dec.xarray_fn
@dec.signal_fn
# Caching (joblib for disk, dict for mem)
@dec.cache_disk ; @dec.cache_disk_async ; @dec.cache_mem
# Batching
@dec.batch_fn ; @dec.batch_numpy_fn / batch_torch_fn / batch_pandas_fn
# Lifecycle
@dec.deprecated(reason="…")
@dec.not_implemented
@dec.preserve_doc
@dec.timeout(seconds=10)
@dec.wrap
# Auto-ordering machinery
dec.enable_auto_order() ; dec.disable_auto_order()
# Conversion helpers
dec.to_numpy(x) ; dec.to_torch(x)
dec.is_torch(x) ; dec.is_cuda(x)
Cache directory resolution
cache_disk / cache_disk_async resolve the cache dir in this order:
scitex.config.get_paths().function_cache(only if scitex is installed)${SCITEX_CACHE_DIR}/function_cache${XDG_CACHE_HOME}/scitex-decorators/function_cache~/.cache/scitex-decorators/function_cache
So the package works without the umbrella scitex installed.
Demo
flowchart LR
C["caller passes pandas.DataFrame"] --> D["@numpy_fn"]
D --> N["function body sees numpy.ndarray"]
N --> R["function returns numpy.ndarray"]
R --> O["caller receives pandas.DataFrame<br/>(original type restored)"]
Status
Standalone fork of scitex.decorators. Zero scitex.* runtime deps. The
umbrella package's scitex.decorators import path is preserved via a
sys.modules-alias bridge.
Part of SciTeX
scitex-decorators is part of SciTeX. Install via
the umbrella with pip install scitex[decorators] to use as
scitex.decorators (Python) or scitex decorators ... (CLI).
Four Freedoms for Research
- The freedom to run your research anywhere — your machine, your terms.
- The freedom to study how every step works — from raw data to final manuscript.
- The freedom to redistribute your workflows, not just your papers.
- The freedom to modify any module and share improvements with the community.
AGPL-3.0 — because we believe research infrastructure deserves the same freedoms as the software it runs on.
License
AGPL-3.0-only (see LICENSE).
Project details
Release history Release notifications | RSS feed
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 scitex_decorators-0.1.12.tar.gz.
File metadata
- Download URL: scitex_decorators-0.1.12.tar.gz
- Upload date:
- Size: 36.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd1632b55f1e2ae6da163ac0ab935a6b80192e04268e1a73b8b899f93ed1387e
|
|
| MD5 |
a2b500f8f2bec7c0d5dbe6b2172e6f91
|
|
| BLAKE2b-256 |
05c4d84d7179931916cc1969f361a2b460f9894fbc955d57a894a013ced05ed4
|
Provenance
The following attestation bundles were made for scitex_decorators-0.1.12.tar.gz:
Publisher:
pypi-publish-and-github-release-on-tag.yml on ywatanabe1989/scitex-decorators
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
scitex_decorators-0.1.12.tar.gz -
Subject digest:
dd1632b55f1e2ae6da163ac0ab935a6b80192e04268e1a73b8b899f93ed1387e - Sigstore transparency entry: 1630146724
- Sigstore integration time:
-
Permalink:
ywatanabe1989/scitex-decorators@c9dec769d263de9c00fc357a991b36346fd16747 -
Branch / Tag:
refs/tags/v0.1.12 - Owner: https://github.com/ywatanabe1989
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish-and-github-release-on-tag.yml@c9dec769d263de9c00fc357a991b36346fd16747 -
Trigger Event:
push
-
Statement type:
File details
Details for the file scitex_decorators-0.1.12-py3-none-any.whl.
File metadata
- Download URL: scitex_decorators-0.1.12-py3-none-any.whl
- Upload date:
- Size: 44.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f1b0f5308eb3605a9b663124de2576e922fb33312123dd1d11c6de0a2d030e2
|
|
| MD5 |
a41bb7940a8992cd7ee3a17697cf7a28
|
|
| BLAKE2b-256 |
6579b1caf5bb16e169491458931da7bc5f05987b36a18ecfcf60f0e030a58899
|
Provenance
The following attestation bundles were made for scitex_decorators-0.1.12-py3-none-any.whl:
Publisher:
pypi-publish-and-github-release-on-tag.yml on ywatanabe1989/scitex-decorators
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
scitex_decorators-0.1.12-py3-none-any.whl -
Subject digest:
1f1b0f5308eb3605a9b663124de2576e922fb33312123dd1d11c6de0a2d030e2 - Sigstore transparency entry: 1630146742
- Sigstore integration time:
-
Permalink:
ywatanabe1989/scitex-decorators@c9dec769d263de9c00fc357a991b36346fd16747 -
Branch / Tag:
refs/tags/v0.1.12 - Owner: https://github.com/ywatanabe1989
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish-and-github-release-on-tag.yml@c9dec769d263de9c00fc357a991b36346fd16747 -
Trigger Event:
push
-
Statement type: