Skip to main content

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 (advanced / internal — prefer the decorator above).
# `_start` is the low-level entry point: `_start(sys, plt, ...)`, NOT a
# decorator. The bare `sess.start` name is deprecated.
sess._start(sys, plt, ...)
sess.close(CONFIG)

# 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

# config/ANALYSIS.yaml  ->  CONFIG.ANALYSIS.THRESHOLD
THRESHOLD: 0.5
import scitex_session as sess

@sess.session
def main(
    data_path="data.csv",      # --data-path: an input, not a parameter
    CONFIG=sess.INJECTED,
    plt=sess.INJECTED,
    logger=sess.INJECTED,
    rng=sess.INJECTED,
):
    """Docstring becomes --help."""
    logger.info(f"{data_path}: threshold={CONFIG.ANALYSIS.THRESHOLD}")
    return 0


if __name__ == "__main__":
    main()
python my_script.py --data-path subject01.csv   # run where config/ lives

Analysis parameters live in ./config/*.yaml (resolved against the working directory), not in main() signature defaults or on the command line: the file stem is the namespace and keys are upper-cased (CONFIG.ANALYSIS.THRESHOLD). CLI arguments are for inputs such as paths or subject ids; there is no CLI override for CONFIG values. scitex-dev >= 0.64.0 lint rule STX-S008 flags numeric main() defaults. Runnable: examples/quickstart.py with examples/config/QUICKSTART.yaml.

Project root

Each run records project_root with the rule that chose it (project_root_source: argument > env ($SCITEX_SESSION_PROJECT_ROOT) > git > marker > cwd > script_dir), see scitex_session/_lifecycle/_project_root.py. scitex-clew adopts this root for the run and re-implements the same rule for standalone use.

Conformance: tests/scitex_session/conformance/project-root-vectors.json is byte-identical to scitex-clew's tests/scitex_clew/conformance/project-root-vectors.json, and both suites run their resolver against it. A change to the rule must update both implementations and the vector file in both repositories.

Status

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

Decoupling notes:

  • scitex.dict.DotDict → scitex_dict.DotDict
  • scitex.repro.RandomStateManager / gen_ID → scitex_repro.*
  • scitex.str.clean_path / printc → scitex_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

Metadata

Release files for scitex-session 0.6.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for scitex-session 0.6.1
File Size Uploaded Provenance Actions
scitex_session-0.6.1.tar.gz 7.8 MB Without provenance Details for scitex_session-0.6.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for scitex-session 0.6.1
File Interpreter ABI Platform Actions
scitex_session-0.6.1-py3-none-any.whl Python 3 none any Details for scitex_session-0.6.1-py3-none-any.whl

Total release size: 15.6 MB

Release files / scitex_session-0.6.1.tar.gz

Download URL scitex_session-0.6.1.tar.gz
Size 7.8 MB
Tags Source
SHA-256 checksum
How to use checksums
841731326d9a3136a268337e27ba91537f8a719e8c573e6dd0a75906ba36a46f
BLAKE2b-256 checksum
How to use checksums
d4a30b376324fcaec5f1a0b584b8eb8aae9c93978c934592db84a02335d82405
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.12.14

Release files / scitex_session-0.6.1-py3-none-any.whl

Download URL scitex_session-0.6.1-py3-none-any.whl
Size 7.8 MB
Tags Python 3
SHA-256 checksum
How to use checksums
97bbc782505fc048df05beb63ecc251dfb375a887884df104f83ec7458bc6365
BLAKE2b-256 checksum
How to use checksums
83001399ac066dd9322e014a6c44bc451eb500f9fc04625c746dd6225f470ac4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.12.14

Security for scitex-session 0.6.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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