Registry / devops / invoke

invoke

JSON →
library1.0.4pypypi✓ verified 35d ago

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.

devopsworkflow
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.

from invoke import task

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
Debug
Known footguns
gotchaThe PyPI package name is `invoke`, not `pyinvoke`. Always use `pip install invoke` for installation.
breakingTask functions now explicitly require a `Context` object as their first argument. Older examples or codebases might omit this, leading to `TypeError`.
gotchaInvoke 1.x supports both Python 2.7+ and 3.4+. However, future major versions (e.g., Invoke 2.x) are expected to drop Python 2 support. Plan for migration if still using Python 2.
gotchaThe way task arguments are defined and parsed (e.g., short/long flags, default values, types) has evolved. Complex argument parsing might require specific syntax or aliases.
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.

Resources