{"id":517,"library":"invoke","title":"Invoke (pyinvoke)","description":"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.","status":"active","version":"1.0.4","language":"python","source_language":"en","source_url":"https://github.com/pyinvoke/invoke","tags":["task runner","automation","CLI tools"],"install":[{"cmd":"pip install invoke","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"task","correct":"from invoke import task"},{"note":"Used for organizing tasks into namespaces.","symbol":"Collection","correct":"from invoke import Collection"},{"note":"Used for programmatic execution or custom CLI entry points.","symbol":"Program","correct":"from invoke import Program"}],"quickstart":{"code":"from invoke import task\n\n@task\ndef clean(c):\n    \"\"\"Removes build artifacts.\"\"\"\n    print(\"Cleaning up build/ directory...\")\n    # Use '|| true' for robustness in quickstart if 'rm' might fail or not exist\n    c.run(\"rm -rf build/ || true\")\n    print(\"Clean complete.\")\n\n@task\ndef greeting(c, name=\"World\"):\n    \"\"\"Says hello to the given NAME.\"\"\"\n    print(f\"Hello, {name}!\")\n\n@task(aliases=['deploy'])\ndef push(c):\n    \"\"\"Pushes code to a remote repository (example).\"\"\"\n    print(\"Simulating deployment...\")\n    # For quickstart, a simple echo is safer than an actual deployment command\n    c.run(\"echo 'Deployment simulated!'\")\n    print(\"Push complete.\")\n\n# To run these tasks:\n# 1. Save this code as `tasks.py` in your project root.\n# 2. Open your terminal in the same directory.\n# 3. Run tasks: `invoke clean`, `invoke greeting --name Pythonista`, `invoke deploy`","lang":"python","description":"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>`."},"warnings":[{"fix":"Use `pip install invoke` to install the library.","message":"The PyPI package name is `invoke`, not `pyinvoke`. Always use `pip install invoke` for installation.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Update task definitions to accept a `Context` object, e.g., `@task def my_task(c): ...`.","message":"Task functions now explicitly require a `Context` object as their first argument. Older examples or codebases might omit this, leading to `TypeError`.","severity":"breaking","affected_versions":"Invoke 0.13.0 and later"},{"fix":"Ensure your development environment uses Python 3.4+ for forward compatibility. Regularly check Invoke's documentation for upcoming breaking changes related to Python version support.","message":"Invoke 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.","severity":"gotcha","affected_versions":"All 1.x versions"},{"fix":"Refer to the official documentation on task arguments (`docs.pyinvoke.org/en/stable/concepts/tasks.html#argument-parsing`) for the latest and recommended patterns, especially for optional or typed arguments.","message":"The 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.","severity":"gotcha","affected_versions":"All versions (evolutionary changes)"}],"env_vars":null,"last_verified":"2026-05-12T14:33:51.923Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Run `pip install invoke` to install the library.","cause":"The `invoke` package is not installed in the current Python environment.","error":"ModuleNotFoundError: No module named 'invoke'"},{"fix":"Add `from invoke import task` at the top of your `tasks.py` file.","cause":"The `@task` decorator was used in `tasks.py` without being imported from the `invoke` package.","error":"NameError: name 'task' is not defined"},{"fix":"Modify the task function signature to accept a `Context` object, e.g., change `def my_task():` to `def my_task(c):`.","cause":"A task function was defined without its required `Context` object as the first argument.","error":"TypeError: my_task() missing 1 required positional argument: 'c'"},{"fix":"Ensure the command is correctly installed and accessible in your shell's PATH, or provide the full absolute path to the executable in `c.run()`.","cause":"The shell command specified within `c.run()` does not exist or is not in the system's PATH where `invoke` is executed.","error":"CommandNotFoundError: The command 'your-command-here' was not found. (or FileNotFoundError)"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.67,"mem_mb":12,"disk_size":"19.0M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.4,"mem_mb":12,"disk_size":"19M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.05,"mem_mb":13.3,"disk_size":"21.1M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.68,"mem_mb":13.3,"disk_size":"22M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.32,"mem_mb":13.5,"disk_size":"12.9M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.98,"mem_mb":13.5,"disk_size":"13M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.31,"mem_mb":13,"disk_size":"12.5M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.84,"mem_mb":13,"disk_size":"13M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.46,"mem_mb":10.8,"disk_size":"18.5M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.48,"mem_mb":10.8,"disk_size":"19M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}