Skip to main content

phistory

You know a script worked yesterday—but not how you ran it. The useful command is buried in one terminal's scrollback, missing from another terminal's shell history, or mixed in with hundreds of unrelated commands.

phistory fixes that at the script level: each argparse script keeps its own copy/paste-ready run history. It also includes a tiny YAML parameter loader for the long, experiment-style commands that are easier to review and version control as configuration files.

It supports Python 3.10+.

Source and issue tracker: https://github.com/amorriso/phistory.


Never reconstruct a command again

# myscript.py
import phistory  # must be first
import argparse

p = argparse.ArgumentParser()
p.add_argument("--foo")
p.add_argument("bar")
args = p.parse_args()
print(args)

Run

python myscript.py --foo 123 hello
python myscript.py --foo 999 world
python myscript.py --history
# outputs:
# myscript.py --foo 123 hello
# myscript.py --foo 999 world

That history belongs to myscript.py, not to whichever shell or terminal happened to run it. Open a new terminal, come back next week, or switch between projects: python myscript.py --history shows the commands that ran that script.


What it does

  • Saves each execution’s CLI (script name + args) to ~/.python-history/<script>.history.
  • When run with --history, prints previous runs (copy/paste friendly) and exits.
  • Only writes history when your script calls argparse.parse_args or parse_known_args.
  • The --history flag itself is never recorded.

History directory: ~/.python-history/

Use --history date to include timestamps, --history unique to show only the first occurrence of each command, or both options together.

phistory intentionally monkey-patches argparse.ArgumentParser when it is imported. Import it before importing or configuring argparse in a script that should record history.

Do not pass passwords, API keys, or other secrets as command-line arguments: phistory deliberately records arguments so commands can be replayed. Use environment variables or an ignored local configuration file for secrets.


When the command has too many arguments

For a script with a handful of flags, a command line is great. For a training, reporting, or batch job with a dozen settings, it is often easier to keep the run configuration in a YAML file. The configuration is readable and reviewable. One useful idea: a params file can also be version-controlled with your script when you want to keep a reproducible record of a run.

For example, instead of remembering this:

python train_model.py --dataset data/races-2025.parquet --output-dir artifacts/v3 \
  --learning-rate 0.0003 --batch-size 128 --epochs 80 --seed 42 \
  --validation-days 28 --feature-set market-v4 --early-stopping-patience 10 \
  --notes "baseline before feature experiment"

write configs/baseline.params.yaml:

dataset: data/races-2025.parquet
output_dir: artifacts/v3
learning_rate: 0.0003
batch_size: 128
epochs: 80
seed: 42
validation_days: 28
feature_set: market-v4
early_stopping_patience: 10
notes: baseline before feature experiment

Then make the script self-documenting:

# train_model.py
from phistory import yaml_args

args = yaml_args.load(required=["dataset", "output_dir", "learning_rate"])
print(args.output_dir)  # YAML keys are available as attributes

Run it with:

python train_model.py configs/baseline.params.yaml

You might version-control configs/baseline.params.yaml when it represents a run worth preserving. Keep credentials, API keys, and machine-specific paths in an ignored local YAML file instead.

Behavior

  • Default file: <script_stem>.params.yaml in the current directory (e.g. runner.params.yaml)
  • You can also provide the path explicitly or as a single argument:
    python runner.py configs/myexp.yaml
    
  • Validate required keys:
    args = yaml_args.load(required=["experiment-name", "outpath", "description"])
    

Helper functions

from phistory import derive_params_filename, load_yaml_params

Using an AI coding assistant

If you use an AI coding assistant in a project, add this to that project's instructions file (for example AGENTS.md, CLAUDE.md, or Copilot instructions) to make the convention explicit:

For reusable Python scripts that use argparse, add `import phistory` as the
first import so each script retains a replayable command history. For scripts
with many stable parameters, consider `phistory.yaml_args` and a params YAML
file. Do not use phistory when command-line arguments contain secrets.

This is an opt-in convention for scripts people run repeatedly—not a reason to add a dependency to every one-off program.


Installation

pip install phistory

License

MIT. See LICENSE.

Metadata

Release files for phistory 0.2.2

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

Source distribution (sdist)

Source distribution for phistory 0.2.2
File Size Uploaded
phistory-0.2.2.tar.gz 14.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for phistory 0.2.2
File Interpreter ABI Platform
phistory-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 24.4 kB

Release files / phistory-0.2.2.tar.gz

Download URL phistory-0.2.2.tar.gz
Size 14.2 kB
Tags Source
SHA-256 checksum
How to use checksums
02a12719dd2837d46f3dc97394e2f5e3129704dab96ca7a19d0e74b959984a22
BLAKE2b-256 checksum
How to use checksums
71cf0d39432d65bd287edcae31b0b0e8991d7ff5f47706540cb0b37b98baa591
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 29, 2026.

Transparency log

Release files / phistory-0.2.2-py3-none-any.whl

Download URL phistory-0.2.2-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c9813a358edae1002b4218838112900b35c36dad755672d1c1257944d572fd8b
BLAKE2b-256 checksum
How to use checksums
23247e8408f59f4bbbdf34c8c8e5bb1c084eb61408b18b07defb14af1eab3fec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 29, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

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