{"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,"search_vec":"'1.0.4':51 'add':60 'autom':64 'avoid':10 'cli':65 'collis':12 'command':33,43 'command-lin':42 'compat':58 'current':47 'defin':31 'draw':21 'enabl':28 'execut':17,38 'featur':61 'function':36 'inspir':22 'interfac':45 'invok':1,3 'librari':20 'line':44 'maintain':57 'make':24 'name':11 'occur':54 'often':4 'period':55 'pyinvok':2,8 'python':15,35 'rake':26 'refer':5 'releas':53 'runner':63 'shell':32 'stabl':48 'task':16,62 'tool':18,66 'user':29 'version':49 'via':40 'within':34","created_at":"2026-03-28T15:17:01.367756+00:00","updated_at":"2026-04-16T17:02:26.564944+00:00","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,"quickstart_score":80,"quickstart_tag":"verified","pypi_latest":"3.0.3","cli_name":"invoke","cli_version":"Invoke 3.0.3","type":"library","homepage":null,"github":"https://github.com/pyinvoke/invoke","docs":"https://docs.pyinvoke.org","changelog":"https://www.pyinvoke.org/changelog.html","pypi":"https://pypi.org/project/invoke/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops","workflow"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-27","next_check":"2026-07-28","install_tag":"verified"}}