Skip to main content

@session decorator + lifecycle (auto-CLI, output dir tree, RandomStateManager) — standalone module from the SciTeX ecosystem

Project description

scitex-session

SciTeX

`@session` decorator + lifecycle (auto-CLI, output dir tree, randomstate, configs).

Full Documentation · uv pip install scitex-session[all]

PyPI Python Tests Coverage Docs License: AGPL v3


Installation

pip install scitex-session

Architecture

src/scitex_session/
├── __init__.py        # public re-exports (session, INJECTED, start, close, ...)
├── _decorator.py      # @session — auto-CLI + DI + output-dir lifecycle
├── _manager.py        # SessionManager (class-style alternative)
├── _lifecycle/        # start / close / FINISHED_SUCCESS dir tree
└── template.py        # boilerplate template for new scripts
flowchart LR
    fn["@sess.session\ndef main(...)"] --> cli["auto-CLI\n(argparse from signature)"]
    cli --> inject["DI: CONFIG / logger / plt / rng"]
    cfg["./config/*.yaml"] --> inject
    inject --> body["main() body"]
    body --> save["stx.io.save"]
    save --> rundir[("script_out/FINISHED_SUCCESS/<ID>/")]
    rundir --> cfgsnap[("CONFIGS/CONFIG.yaml")]
    rundir --> logs[("logs/{stdout,stderr}.log")]
    rundir --> outputs[("results.csv, plots, ...")]

1 Interfaces

Python API
import scitex_session as sess

# Decorator — wraps main() with auto-CLI, output dir, configs, RNG.
@sess.session
def main(CONFIG=sess.INJECTED, logger=sess.INJECTED, rng=sess.INJECTED):
    ...

# Manual lifecycle
sess.start(...)
sess.close(...)

# Class-style manager
mgr = sess.SessionManager()

Demo

sequenceDiagram
    participant User as $ python script.py --param1 X
    participant Dec as @sess.session
    participant Main as main()
    participant FS as Filesystem
    User->>Dec: invoke
    Dec->>Dec: parse args, fix RNG, build CONFIG
    Dec->>FS: mkdir script_out/RUNNING_<ID>/
    Dec->>Main: call(CONFIG, logger, rng, plt)
    Main->>FS: stx.io.save(...)
    Main-->>Dec: return 0
    Dec->>FS: rename → FINISHED_SUCCESS/<ID>/
    Dec->>FS: write CONFIGS/CONFIG.yaml + logs/

Quick Start

import scitex_session as sess

@sess.session
def main(
    param1="default",
    CONFIG=sess.INJECTED,
    plt=sess.INJECTED,
    logger=sess.INJECTED,
    rng=sess.INJECTED,
):
    """Docstring becomes --help."""
    logger.info("hi")
    return 0

Status

Standalone fork of scitex.session. Deps: matplotlib + scitex-dict / -logging / -repro / -str (already-standalone peer packages).

Decoupling notes:

  • scitex.dict.DotDictscitex_dict.DotDict
  • scitex.repro.RandomStateManager / gen_IDscitex_repro.*
  • scitex.str.clean_path / printcscitex_str.*
  • scitex.logging.getLogger → stdlib logging.getLogger
  • scitex.plt.utils._configure_mpl → optional via try/except with no-op fallback (matplotlib uses defaults if scitex umbrella isn't installed).
  • scitex.utils._notify → optional via try/except (silent no-op fallback).

The umbrella package's scitex.session import path is preserved via a sys.modules-alias bridge.

Part of SciTeX

scitex-session is part of SciTeX. Install via the umbrella with pip install scitex[session] to use as scitex.session (Python) or scitex session ... (CLI).

Four Freedoms for Research

  1. The freedom to run your research anywhere — your machine, your terms.
  2. The freedom to study how every step works — from raw data to final manuscript.
  3. The freedom to redistribute your workflows, not just your papers.
  4. 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).


SciTeX

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scitex_session-0.2.3.tar.gz (55.9 kB view details)

Uploaded Source

Built Distribution

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

scitex_session-0.2.3-py3-none-any.whl (66.7 kB view details)

Uploaded Python 3

File details

Details for the file scitex_session-0.2.3.tar.gz.

File metadata

  • Download URL: scitex_session-0.2.3.tar.gz
  • Upload date:
  • Size: 55.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for scitex_session-0.2.3.tar.gz
Algorithm Hash digest
SHA256 0eec7df2e3fedcfb01cb1f9b9728f4d3c331489097416bce478921365bca56fc
MD5 4b05785ac034adf32d4ff0184e7664cf
BLAKE2b-256 f9cd7ad7d2209b5e35b1cb20203894469b968c8a89c821d865c8b1bf0535a0b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for scitex_session-0.2.3.tar.gz:

Publisher: pypi-publish-and-github-release-on-tag.yml on ywatanabe1989/scitex-session

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file scitex_session-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: scitex_session-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 66.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for scitex_session-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 55155cf52fa0ff363ece0fc0239be6a1c1a424b151dfb48a9150857af0aa8802
MD5 2830998eb0feea7e26d14fd8d249532b
BLAKE2b-256 9986c93d02a48e93ce25dfa43cce03ba6eb9a3f996e63a787fbb9204c640424f

See more details on using hashes here.

Provenance

The following attestation bundles were made for scitex_session-0.2.3-py3-none-any.whl:

Publisher: pypi-publish-and-github-release-on-tag.yml on ywatanabe1989/scitex-session

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page