Skip to main content

Lightweight timestamped session-directory manager for data-processing scripts

Project description

session-manager

CI Release

Lightweight timestamped session-directory manager for data-processing scripts.

Each time your script runs it gets its own uniquely named folder — no overwritten results, no manual date-stamping. Works on Windows and Linux (pathlib.Path throughout).

Install

# from PyPI (after first release)
pip install session-manager

# directly from GitHub (always latest)
pip install git+https://github.com/lukaszplk/session-manager.git

Use cases

1. Save outputs from a data-processing script

Every run produces a fresh folder. Re-run as many times as you like — nothing gets overwritten.

from session_manager import SessionManager

sm = SessionManager("results", name="rna_seq")
# creates: results/rna_seq_2026-05-26_22-08-00/

df.to_csv(sm.file("counts.csv"))
fig.savefig(sm.file("volcano.png"))

plots = sm.subdir("plots")        # creates subdir, returns Path
fig2.savefig(plots / "pca.png")
fig3.savefig(sm / "overview.png") # shorthand

Resulting folder:

results/
└── rna_seq_2026-05-26_22-08-00/
    ├── counts.csv
    ├── volcano.png
    └── plots/
        └── pca.png

2. Pipeline chaining — script B always picks up script A's latest output

No hardcoded paths, no manual coordination between scripts.

# script_a.py  (preprocessing — run multiple times during development)
from session_manager import SessionManager

sm = SessionManager("results", name="preprocess")
df_clean.to_csv(sm.file("clean.csv"))
model_params = {"lr": 0.01, "epochs": 50}
json.dump(model_params, open(sm.file("params.json"), "w"))
# script_b.py  (training — always reads A's latest output)
from session_manager import SessionManager

sm = SessionManager("results", name="preprocess", create=False)
latest = sm.latest()

logger.info("Reading from: %s", latest)
df = pd.read_csv(latest / "clean.csv")
params = json.load(open(latest / "params.json"))

3. Logger injection — all output in one place

Pass your application logger so the library's events (folder created, scan results, errors) flow through your handlers, formatters, and custom levels.

import logging
from session_manager import SessionManager

logger = logging.getLogger("my_pipeline")
sm = SessionManager("results", name="rna_seq", logger=logger)
# → logger.debug("Session created: results/rna_seq_2026-...")

# library logs and your script logs end up in the same file
logger.info("Processing %d samples", len(df))

4. Scratch / temp work

For intermediate results that don't need to persist, use the system temp directory — no path to decide, works the same on Windows and Linux.

from session_manager import SessionManager

sm = SessionManager.in_temp(name="scratch")
# → /tmp/scratch_2026-05-26_22-08-00/    (Linux/macOS)
# → %TEMP%\scratch_2026-05-26_22-08-00\  (Windows)

large_intermediate_df.to_parquet(sm.file("intermediate.parquet"))

5. Experiment tracking

Keep every hyperparameter sweep run isolated and comparable.

for lr in [0.001, 0.01, 0.1]:
    sm = SessionManager("experiments", name=f"lr_{lr}")
    model.fit(X_train, y_train, lr=lr)
    metrics = evaluate(model, X_test, y_test)
    json.dump(metrics, open(sm.file("metrics.json"), "w"))
    model.save(sm.file("model.pt"))

Resulting folder:

experiments/
├── lr_0.001_2026-05-26_22-10-00/
│   ├── metrics.json
│   └── model.pt
├── lr_0.01_2026-05-26_22-10-05/
│   ├── metrics.json
│   └── model.pt
└── lr_0.1_2026-05-26_22-10-10/
    ├── metrics.json
    └── model.pt

Options

All optional, all keyword-only:

sm = SessionManager(
    "results",
    name="run",
    separator="--",                    # default "_"
    timestamp_format="%Y%m%dT%H%M%S", # default "%Y-%m-%d_%H-%M-%S"
    create=False,                      # default True
    logger=logger,                     # default None (silent)
)

API

SessionManager(base_dir, name="session", *, separator, timestamp_format, create, logger)

Argument Default Description
base_dir required Parent directory for sessions
name "session" Folder name prefix
separator "_" Between name and timestamp
timestamp_format "%Y-%m-%d_%H-%M-%S" strftime format
create True False = no folder created (use with latest())
logger None logging.Logger for internal events
Method / property Returns Description
session_dir Path Session root (raises if create=False)
file(*parts) Path Path inside session dir (not created)
subdir(*parts) Path Subdirectory (created)
sm / "name" Path Shorthand for session_dir / name
latest(base_dir=None) Path Latest matching session folder
SessionManager.in_temp(name, ...) SessionManager Constructor using system temp dir

Development

git clone https://github.com/lukaszplk/session-manager.git
cd session-manager
pip install -e ".[dev]"
pytest

Work on a feature branch, open a PR against master — CI runs automatically on the PR.

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

session_manager-0.1.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

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

session_manager-0.1.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file session_manager-0.1.0.tar.gz.

File metadata

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

File hashes

Hashes for session_manager-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b2e4c7503d948ae1867fc38bb44e44d4108578465d761dea6ec84755ab0a4131
MD5 03d4a6dd21884ba081f6988aa61d8cc1
BLAKE2b-256 e37a8c5b85e73aa07256ef70d02c5e668808db0099f1dd9023e40e71f6d34c19

See more details on using hashes here.

Provenance

The following attestation bundles were made for session_manager-0.1.0.tar.gz:

Publisher: release.yml on lukaszplk/session-manager

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

File details

Details for the file session_manager-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for session_manager-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e0e732bc2ede72d47cef84c1a3766ee4c4afac8532a9f5fafb4baa40fd57b7f9
MD5 c26844a7ec64ac9dd43ee67af8b9b75c
BLAKE2b-256 af0a05aa34071f5fc398308991817d09c8fa3604100b4643db4f4948513ad98f

See more details on using hashes here.

Provenance

The following attestation bundles were made for session_manager-0.1.0-py3-none-any.whl:

Publisher: release.yml on lukaszplk/session-manager

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