Invoke

2.2.1 · active · verified Sat Mar 28

Invoke is a Python library for managing shell-oriented subprocesses and organizing executable Python code into CLI-invokable tasks. It provides a clean, high-level API for running shell commands and defining/organizing task functions from a `tasks.py` file, drawing inspiration from tools like Make and Rake. The current version is 2.2.1, with releases occurring periodically to introduce new features and address issues.

Warnings

Install

Imports

Quickstart

Create a `tasks.py` file in your project root. Define functions decorated with `@task`, ensuring the first argument is `c` (for context). Then run tasks from your terminal using `invoke <task_name>` (e.g., `invoke greet --name='Alice'`).

from invoke import task

@task
def greet(c, name='World'):
    """Says hello to the specified name."""
    print(f"Hello, {name}!")

@task
def clean(c):
    """Removes temporary build files."""
    # Example of running a shell command
    c.run("echo 'Cleaning build directory...'", warn=True)
    # For a real scenario, you might do:
    # c.run("rm -rf build/")

view raw JSON →