Invoke, often referred to as pyinvoke to avoid name collision, is a Python task execution tool and library, drawing inspiration from Make and Rake. It enables users to define shell commands within Python functions and execute them via a command-line interface. The current stable version is 1.0.4, with releases occurring periodically to maintain compatibility and add features.
Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Used for organizing tasks into namespaces.
from invoke import Collection
Used for programmatic execution or custom CLI entry points.
from invoke import Program
Create a `tasks.py` file in your project directory. Define tasks as Python functions decorated with `@task`, ensuring they accept a `Context` object (conventionally named `c`) as their first argument. Execute tasks from the command line using `invoke <task_name>`.
from invoke import task
@task
def clean(c):
"""Removes build artifacts."""
print("Cleaning up build/ directory...")
# Use '|| true' for robustness in quickstart if 'rm' might fail or not exist
c.run("rm -rf build/ || true")
print("Clean complete.")
@task
def greeting(c, name="World"):
"""Says hello to the given NAME."""
print(f"Hello, {name}!")
@task(aliases=['deploy'])
def push(c):
"""Pushes code to a remote repository (example)."""
print("Simulating deployment...")
# For quickstart, a simple echo is safer than an actual deployment command
c.run("echo 'Deployment simulated!'")
print("Push complete.")
# To run these tasks:
# 1. Save this code as `tasks.py` in your project root.
# 2. Open your terminal in the same directory.
# 3. Run tasks: `invoke clean`, `invoke greeting --name Pythonista`, `invoke deploy`
invoke --version
Upgrade
Version history
Breaking-change detection hasn't run for this library yet.
Audit
Security & dependencies
CVE tracking and dependency tree are planned for a later release.
Agent activity
0 hits · last 30 days
No traffic data recorded yet.