Skip to main content

A lightweight, dependency-free tool to manage your scripts directly from pyproject.toml

Project description

Tomlscript

A lightweight, dependency-free tool to manage your scripts directly from pyproject.toml

Usage

# alias tom = "uvx tomlscript"
# List commands
tom

# Run a command
tom dev --port 8000
tom publish
tom pyi

Example Configuration

# pyproject.toml
[tool.tomlscript]
# Start dev server (default on port 5001)
dev = "uv run uvicorn --port {port:5001} superapp.main:app --reload"

# Publish to PyPI
publish = "rm -rf dist && uv build && uvx twine upload dist/*"

# Generate pyi stubs (python function)
pyi = "mypackage.typing:generate_pyi"

Installation

pip install tomlscript
uv add --dev tomlscript

# Or better, run it directly with uvx without installation
# And use it to setup other dependencies
alias tom = "uvx tomlscript"
tom # List commands
tom setup_dev  # Run command to setup dev env

Running Commands

Directly

# alias tom = "uvx tomlscript"
tom
tom function
tom function v1 --arg2 v2

Using uv

uv run tom
uv run tom function v1 --arg2 v2

Configuration

Basic

Commands are defined in the [tool.tomlscript] section of the pyproject.toml file.

The comment above a command serves as its documentation.

[tool.tomlscript]
# Linter check <= this line is the documentation for `lint` command
lint = "uv run ruff check"

Commands can be multi-line scripts:

[tool.tomlscript]
# Lint and test
test = """
uv run ruff check
uv run pytest
"""

You can define commands with arguments using the {arg} or {arg:default} syntax:

[tool.tomlscript]
# Start dev server (default on port 5001)
dev = "uv run uvicorn --port {port:5001} superapp.main:app --reload"

The above command can be used as

tom dev              # run on port 5001
tom dev --port 8000  # run on port 8000

You can also define commands as Python functions using the module:function syntax:

[tool.tomlscript]
# Run python function run2 from [tests.myscript module](./tests/myscript.py)
py_example = "tests.myscript:run2"

Arguments can be passed to Python functions:

tom py_example --name Paul

For complex shell scripts, you can use the [tool.tomlscript.source] section. Functions defined here can be reused across multiple commands:

[tool.tomlscript]
build = "clean && uv build"

source = """
# Clean up
clean() {
  say_ "Cleaning up..."
  rm -rf dist .eggs *.egg-info build
}

# Functions ending with _ are hidden from the command list
say_() {
  echo "$1"
}
"""

Full example

For real world examples, see development section and pyproject.toml file.

[tool.tomlscript]
# This line is the documentation for `hello` function
hello = 'say_ "Hello world"'

# Run python function run2 from tests.myscript module
run2 = "tests.myscript:run2"

# A command with arguments and default values
dev = "uv run uvicorn --port {port:5001} superapp.main:app"

# Lint and test
test = """
uv run ruff check
uv run pytest --inline-snapshot=review
"""

# Define multiple functions in the `[tool.tomlscript.source]` sections
source = """
# Documentation for `doc` function
doc() {
  say_ "Rendering documentation..."
}

# Functions ending with _ are hidden from the command list
say_() {
  echo "$1"
}
"""

Development

alias tom="uvx tomlscript"
tom
# setup_dev      : Setup dev env
# test           : Run tests with coverage
# publish        : Publish pypi package
# cov            : Open Cov report
# example        : Execute a simple python function

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

tomlscript-0.2.1.tar.gz (43.1 kB view details)

Uploaded Source

Built Distribution

tomlscript-0.2.1-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tomlscript-0.2.1.tar.gz
  • Upload date:
  • Size: 43.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.10

File hashes

Hashes for tomlscript-0.2.1.tar.gz
Algorithm Hash digest
SHA256 6e66536d9e56738680649f6e0404504a40d64f8e61459096e2a74d16f526405d
MD5 abf1de49aa6df33c90c5adf8bd751d86
BLAKE2b-256 07f4d355dbd500e73e84b527f4d60396fa1152433fbacd881abb753ebb43b5e9

See more details on using hashes here.

File details

Details for the file tomlscript-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: tomlscript-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.10

File hashes

Hashes for tomlscript-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9746e4488c1dfb50e6056105bea2d0c0267d3404b47896c6d134755e0c5df692
MD5 4b75ab08fe7829b6a283ac15a47d3414
BLAKE2b-256 28bcd5e1b9a1e6b554d7166de8a45f07dabd857aa9a2f559bac59df793646d79

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page