{"id":7634,"library":"python-tools-scripts","title":"Python Tools Scripts","description":"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.","status":"active","version":"0.20.5","language":"en","source_language":"en","source_url":"https://github.com/s0undt3ch/python-tools-scripts","tags":["cli","automation","scripts","tools","argparse","development"],"install":[{"cmd":"pip install python-tools-scripts","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"symbol":"Context","correct":"from ptscripts import Context"},{"symbol":"command_group","correct":"from ptscripts import command_group"},{"note":"The installed package is `python-tools-scripts`, but the actual import module is `ptscripts`. Importing `python_tools_scripts` directly will not provide the intended API.","wrong":"import python_tools_scripts","symbol":"command","correct":"from ptscripts import command"}],"quickstart":{"code":"import os\nfrom ptscripts import command_group, Context, command\n\n# --- File: <repo-root>/tools/__init__.py ---\n# This file makes the 'tools' directory a Python package.\n# No specific content is required here for basic discovery, but it can import other scripts.\n\n# --- File: <repo-root>/tools/my_scripts.py ---\n# Define a command group\nmy_group = command_group(name=\"hello\", help=\"Basic greeting commands\")\n\n@my_group.command(\n    arguments={\n        \"name\": {\"help\": \"The name to greet\", \"default\": \"World\"}\n    }\n)\ndef greet(ctx: Context, name: str):\n    \"\"\"Greets the specified name.\"\"\"\n    print(f\"Hello, {name} from {ctx.command_path}!\")\n\n@my_group.command()\ndef goodbye(ctx: Context):\n    \"\"\"Says goodbye.\"\"\"\n    print(f\"Goodbye from {ctx.command_path}!\")\n\n# To make 'my_scripts.py' discoverable by the 'tools' CLI,\n# ensure it's imported in '<repo-root>/tools/__init__.py'.\n# E.g., 'from . import my_scripts'\n\n# --- How to run (from your repository root) ---\n# Make sure to run 'pip install python-tools-scripts' first.\n# > tools hello greet --name Alice\n# > tools hello goodbye\n","lang":"python","description":"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."},"warnings":[{"fix":"Always use `from ptscripts import ...` for imports after installing `python-tools-scripts`.","message":"The PyPI package name is `python-tools-scripts`, but the Python import name for its modules is `ptscripts`. Attempting to import directly from `python_tools_scripts` will fail.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Create a `tools` directory at your project root. Add an empty `__init__.py` file to make it a package. For each script `my_script.py` in `tools/`, add `from . import my_script` to `tools/__init__.py`.","message":"For scripts to be discoverable by the `tools` CLI, they must reside within a Python package named `tools` at the root of your repository (e.g., `<repo-root>/tools/__init__.py`, `<repo-root>/tools/your_script.py`). Furthermore, the individual script files must be imported within `tools/__init__.py` to be loaded.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure the library is installed with `pip install python-tools-scripts`. Verify that the import statement is `from ptscripts import ...`.","cause":"The `ptscripts` module was not found. This typically happens if `python-tools-scripts` was not installed, or if the import statement is incorrect (e.g., trying to use `python_tools_scripts`).","error":"ModuleNotFoundError: No module named 'ptscripts'"},{"fix":"Check that your `tools` directory is at the repository root, contains an `__init__.py` file, and that your script file (e.g., `my_script.py`) is imported within `tools/__init__.py`. Also, ensure the `@command_group` decorator has the correct `name` argument matching the command you're trying to execute.","cause":"The `tools` CLI could not find the specified command group or command. This usually means the script defining the command was not correctly placed in the `<repo-root>/tools` directory, or it wasn't imported in `tools/__init__.py`.","error":"Error: No such command 'my_command_group'"}]}