Reference¶
The CLI executable is run or toml-run and help is available with --help.
usage: run [-l] [-c CONFIG] [-s] [-v] [-V] [-D] [-h] [name] # (1)!
example: run [name] -- --script-args
positional arguments:
name Name of script to run
options:
-l, --list List available scripts
-c, --config CONFIG Config [default: pyproject.toml]
-s, --silent Disable script output
-v, --verbose Verbose output [debug: -vvv]
-V, --version Show installed version
-D, --docs Launch docs in browser
-h, --help Show this help message
- Tip: Save your options with Environment Variables.
To view the source code, see the cli.py on GitHub.
Install¶
From PyPI: https://pypi.org/p/toml-run
GitHub: https://github.com/cssnr/toml-run
Upgrade.
Uninstall.
Run without installing using astral-sh/uv .
Check the installed --version.
Scripts¶
Scripts are defined in the pyproject.toml using the [tool.scripts] section.
- Supported headings:
[tool.scripts]and[tool.toml-run]
Define "pre" and "post" scripts by prefixing the script name.
prebuild = "echo always run before build"
build = "echo running build"
postbuild = "echo always run after build"
Split commands into multiple commands.
Chain commands and run other commands.
one = "echo one"
two = "run one && echo two"
success = "run one && echo success || echo failed"
failure = "run abc && echo success || echo failed"
All paths are relative to the config file directory.
Therefore, clean will always remove this dist folder.
Run Python code using eval easily.
unlink = "#py Path('file').unlink(True)"
rmtree = "#py shutil.rmtree('dir', True)"
web = "#py webbrowser.open_new_tab('https://github.com/cssnr/toml-run')"
chain = ["run rmtree", "#py print('two')", "echo three", "run web"]
You can use these in a list and with run just not using &&.
The only parsing done is looking for #py at the start of a string and running eval.
You can view the list of imported modules below.
Imported Modules
Usage¶
The CLI executable is run or toml-run.
List available scripts with --list.
Run a script with run.
Run without installing using astral-sh/uv .
Pass additional arguments after -- terminator.
Increase output with --verbose. Debug with -vv or -vvv.
Silent script output with --silent.
If your scripts are defined in another file use --config.
This will look for a settings.toml in current and parent directories and run the scripts relative to that files directory.
You can set the SCRIPT_CONFIG Environment variable to avoid using the --config option every time.
Environment¶
Many options support setting environment variable defaults.
| Environment Variable | Default | Type | Description |
|---|---|---|---|
SCRIPT_SILENT |
false | bool |
Disable script output |
SCRIPT_VERBOSE |
0 | int |
Enable verbose output |
SCRIPT_CONFIG |
pyproject.toml | str |
Python Project File |
Allowed boolean values, case-insensitive.
You can temporarily set variables on the command line.
Question
If you need help getting started or run into any issues, support is available!