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.0.tar.gz (52.7 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.0-py3-none-any.whl (63.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: scitex_session-0.2.0.tar.gz
  • Upload date:
  • Size: 52.7 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.0.tar.gz
Algorithm Hash digest
SHA256 2699f280cc7eead13d5e79a1591c5dee2a7af752bb4e33b1c2fd30ed7a67e092
MD5 0aa761baa5bb9cdf1a6be6533d5c7e7d
BLAKE2b-256 90817e22b547dfc124f25302dd997be4ff94bebcb7107e46ce444a17db0c98d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for scitex_session-0.2.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: scitex_session-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 63.6 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f8ed1b82dae58275b9acc3484fb3586e4e3a338c95f5332dc66421258f658bf9
MD5 ea0f240bbcebb91a6cfca8f6a4c059c1
BLAKE2b-256 9b0d96a26c5049f808ae60b84faa3a56a916b53300655b77be2b70ab7e454682

See more details on using hashes here.

Provenance

The following attestation bundles were made for scitex_session-0.2.0-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