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.1.tar.gz (53.0 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.1-py3-none-any.whl (63.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: scitex_session-0.2.1.tar.gz
  • Upload date:
  • Size: 53.0 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.1.tar.gz
Algorithm Hash digest
SHA256 8bb056225f33c3b99f248d83a5c9aa4c9b70eb1feeb27269ca554b756fb64c2a
MD5 241f06f3e4259684ac62c459e5ad5cfc
BLAKE2b-256 7385eae24f8940e59fb0cf91d12c4bc3511fe50d224bf3f495e81e048142277a

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: scitex_session-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 63.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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 91c9c62e4a28fbbbef02286e9dc5adbf86fbd848312e3e4ac4ae325cb42935b4
MD5 0830be51d755bfdbf78477ba8d7826ff
BLAKE2b-256 00c458341f324f49627439df5789610f0ee3b8899d6bc5aff9b01e5bee54ad67

See more details on using hashes here.

Provenance

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