Python Tools Scripts

0.20.5 · active · verified Thu Apr 16

Python Tools Scripts (ptscripts) is a command-line interface (CLI) tool designed to simplify the creation and management of project-specific scripts. It functions similarly to `invoke` but leverages `argparse` internally for CLI argument definition. The library discovers and integrates scripts placed within a designated 'tools' package in a repository's root, making them accessible via a central `tools` command. It is currently at version 0.20.5 and appears to have an active maintenance cadence, with the latest release in early 2024.

Common errors

Warnings

Install

Imports

Quickstart

To use `python-tools-scripts`, create a `tools` directory in your repository's root and ensure it's a Python package (contains `__init__.py`). Define your CLI commands within Python files inside this `tools` package using `@command_group` and `@command` decorators from `ptscripts`. These scripts will then be discoverable and executable via the `tools` command-line utility. Ensure you import your script files into `tools/__init__.py` for them to be picked up.

import os
from ptscripts import command_group, Context, command

# --- File: <repo-root>/tools/__init__.py ---
# This file makes the 'tools' directory a Python package.
# No specific content is required here for basic discovery, but it can import other scripts.

# --- File: <repo-root>/tools/my_scripts.py ---
# Define a command group
my_group = command_group(name="hello", help="Basic greeting commands")

@my_group.command(
    arguments={
        "name": {"help": "The name to greet", "default": "World"}
    }
)
def greet(ctx: Context, name: str):
    """Greets the specified name."""
    print(f"Hello, {name} from {ctx.command_path}!")

@my_group.command()
def goodbye(ctx: Context):
    """Says goodbye."""
    print(f"Goodbye from {ctx.command_path}!")

# To make 'my_scripts.py' discoverable by the 'tools' CLI,
# ensure it's imported in '<repo-root>/tools/__init__.py'.
# E.g., 'from . import my_scripts'

# --- How to run (from your repository root) ---
# Make sure to run 'pip install python-tools-scripts' first.
# > tools hello greet --name Alice
# > tools hello goodbye

view raw JSON →