Skip to main content

invoke-tasklib

CI Nightly Package Tests Codecov Documentation (stable)
PyPI version Python BSD-3-Clause
Ruff Doc style: google OpenSSF Scorecard
Downloads Monthly downloads GitHub stars

Reusable Invoke tasks shared across Python projects: formatting, linting, type-checking, testing, environment setup, security auditing, releasing, documentation, and cleanup, all as a single importable package instead of a tasks.py you copy-paste and let drift between repositories.

📖 Full documentation: https://durandtibo.github.io/invoke-tasklib/

Install

uv add --dev invoke-tasklib

or with pip:

pip install invoke-tasklib

Prerequisite: most tasks (env.*, release.*, security.audit) run uv, so install it even if you install invoke-tasklib with pip.

Platforms: Linux and macOS. Windows is not supported: the tasks rely on a POSIX shell (for the quoting of the commands), and make_ns emits a RuntimeWarning on Windows.

Quickstart

1. Add a tasks.py at the root of your project:

# tasks.py
from invoke_tasklib import make_ns

ns = make_ns()

2. Add an invoke.yaml with, at minimum, your package name:

tasklib:
  package:
    name: my_package

3. List and run the tasks:

invoke --list
invoke format.check-python lint.check-python
invoke test.unit

If a task fails because a tool like ruff or pytest isn't installed yet, run invoke env.install first.

See the Get Started guide for a full walkthrough.

Tasks

Tasks are grouped into namespaces, one per module. Each task either checks/reports (read-only, exits non-zero on violations) or mutates (formats, builds, publishes); the table below flags which.

Namespace Task Behavior Mutates?
format format.check-python Check Python formatting with ruff ❌
format format.fix-python Format Python code with ruff ✅
format format.check-docstrings Check docstring formatting with docformatter ❌
format format.fix-docstrings Format docstrings with docformatter ✅
format format.check-shell Check shell scripts with shellcheck ❌
format format.check-shell-format Check the format of shell scripts with shfmt ❌
format format.fix-shell Format shell scripts with shfmt ✅
lint lint.check-python Check linting with ruff ❌
lint lint.fix-python Fix auto-fixable linting issues with ruff ✅
lint lint.check-spelling Check the spelling with codespell ❌
lint lint.pre-commit Run all the pre-commit hooks ✅
imports imports.check-cycles Check for cyclic import dependencies ❌
imports imports.check-isolated Check that every module imports on its own ❌
types types.check Check type hints with ty (--complete also runs pyright) ❌
types types.check-public-api Check that the public API of the package is fully typed (pyright) ❌
test test.doctest Run doctests on source code and markdown files ❌
test test.doctest-src Run doctests on source code ❌
test test.doctest-markdown Run doctests on Python examples in markdown files ❌
test test.unit Run unit tests ❌
test test.integration Run integration tests ❌
test test.functional Run functional tests ❌
test test.all Run unit, integration, and functional tests ❌
test test.coverage-report Generate an HTML/terminal report from existing coverage data ❌
test test.benchmark Run performance benchmarks ❌
env env.create-venv Create a virtual environment and install the project ✅
env env.install Install project dependencies and the package (editable) ✅
env env.check-tools Check which tools (ruff, pyright, ...) are available ❌
env env.update Update dependencies and pre-commit hooks ✅
env env.show-installed-packages Show the installed packages ❌
env env.show-python-config Show the Python configuration ❌
release release.build Build the package and verify installation (--check also validates metadata with twine) ✅
release release.publish Build and publish the package to PyPI ✅
doc doc.publish-dev Publish development (unstable) docs ✅
doc doc.publish-latest Publish latest (stable) docs ✅
doc doc.build Build the docs, failing on warnings (mkdocs build --strict) ❌
doc doc.serve Serve the docs locally ❌
security security.audit Audit the locked dependencies for known vulnerabilities with pip-audit ❌
check check.all (or check) Run the main read-only checks ❌
fix fix.all (or fix) Fix the lint and format issues ✅
clean clean.all (or clean) Remove build artifacts and caches ✅
clean clean.pycache Remove all __pycache__ directories ✅
config config.show Show the resolved config and where each value comes from ❌

format.* and lint.* follow a naming convention: read-only checks are named check_<target>, and the matching in-place fixer is named fix_<target> (e.g. check_python/fix_python), so the counterpart of a task is always easy to find. Follow this convention when adding new tasks to these namespaces.

For task-by-task details, options (like --cov on test.* tasks), and the tools each one wraps, see the User Guide.

Configuration

Only tasklib.package.name is required; everything else has a sensible default derived from it:

tasklib:
  package:
    name: my_package # required
    import_name: my_package # default: <package.name> with - replaced by _
    python_version: "3.14" # used by env.create-venv (default: the version that uv chooses)
  paths:
    src: src/my_package # default: src/<package.import_name>
    tests: tests
    unit_tests: tests/unit # default: <tests>/unit
    integration_tests: tests/integration # default: <tests>/integration
    functional_tests: tests/functional # default: <tests>/functional
    benchmarks: tests/benchmarks # default: <tests>/benchmarks
    docs_config: docs/mkdocs.yml
  groups:
    install: dev # dependency groups of env.install
    update: dev,docs # dependency groups of env.update
  test:
    unit_timeout: 10 # seconds, also integration_timeout and functional_timeout
    xdoctest: true # pytest --xdoctest (needs xdoctest)
    timeout: true # pytest --timeout (needs pytest-timeout)
    cov_fail_under: 90 # threshold of --cov (default: not set)
    cov_reports: html,xml,term
  types:
    checker: ty # type checker of types.check: ty, pyright or mypy
  check:
    tasks: format-python,format-docstrings,lint,types,imports,unit # steps of check.all
    cov: false # run the unit step of check.all with --cov
  fix:
    tasks: lint,format-python,format-docstrings # steps of fix.all

check.tasks also accepts doctest, shell, spelling, docs and audit; fix.tasks also accepts shell. invoke config.show prints the resolved values and where each one comes from.

See the Config reference for how each path default is derived.

Every key can also be set with an INVOKE_TASKLIB_<SECTION>_<KEY> environment variable, for example INVOKE_TASKLIB_PATHS_SRC=lib or INVOKE_TASKLIB_TEST_UNIT_TIMEOUT=30, which wins over invoke.yaml. An invalid value, an unknown key (with the closest valid key suggested) or a wrong working directory exits with the code 2 before any command runs. For editor completion, the JSON schema of the tasklib section is published at https://durandtibo.github.io/invoke-tasklib/schema.json (python -m invoke_tasklib.config prints it).

Conventions

  • Arguments: the tasks that run a tool take --args (extra arguments for the tool, as one string, e.g. --args "-k foo -x") and, for the tasks that work on files, --paths (files or directories instead of the default ones). Both are quoted, so a glob or ~ reaches the tool as it is.
  • Exit codes: 0 the task passed, or had nothing to do (a ⏭️ line says why); 1 the checked thing failed; 2 invalid usage or config; 127 a tool is missing. A missing program or Python module is reported with the command that installs it.
  • Composite tasks: invoke check runs the main read-only checks and invoke fix the fixers; --only, --skip and --keep-going select the steps and report all the failures at the end.
  • Dangerous tasks ask first: env.create-venv asks before it clears .venv and release.publish checks the git state and asks before it uploads (--yes skips the question, --dry-run publishes nothing). clean stays inside the project and keeps what git tracks.
  • ASCII output: set INVOKE_TASKLIB_ASCII=1 to replace the emojis of the messages with [ok], [fail] and [skip].

Composing a custom subset of tasks

Need a different set of tasks, or a one-off task alongside the shared ones? Use make_ns, which returns a new collection each time, so adding or removing tasks never affects other importers. Leave out the tasks you do not use (for example the ones that publish):

# tasks.py
from invoke import task
from invoke_tasklib import make_ns


@task
def my_custom_task(c):
    r"""Run a one-off command."""
    c.run("echo hello")


ns = make_ns(exclude=["release.publish", "doc"])
ns.add_task(my_custom_task)

tasks.py is imported by Invoke as a top-level module, so a task defined in another file of the project is imported with an absolute import (from my_tasks import my_custom_task), not a relative one (from . import my_custom_task), which fails with an ImportError.

or keep only some of them with include, e.g. make_ns(include=["lint", "test.unit"]). The names are namespaces ("doc") or tasks ("release.publish"); an unknown name raises a ValueError. The make_ns() with no argument has all the tasks (there is no pre-built invoke_tasklib.ns, so no collection is shared between importers). Individual task modules can also be composed by hand:

# tasks.py
from invoke import Collection, task
from invoke_tasklib import lint, testing


@task
def my_custom_task(c):
    r"""Run a one-off command."""
    c.run("echo hello")


ns = Collection(lint, Collection.from_module(testing, name=testing.NAMESPACE), my_custom_task)

The modules of the format, types and test namespaces are named formatting, typecheck and testing so that they do not shadow the standard library (types, test) or a builtin (format); pass name=module.NAMESPACE (every task module has the name of its namespace in NAMESPACE) to Collection.from_module to keep the task names.

Prefer adding a config knob to a shared task over forking it; reserve custom composition for things that are genuinely one-off to a single project.

API Stability

⚠️ invoke-tasklib is under active development and its API is not yet stable: pin a specific version in your project's dependencies for consistent behavior across releases.

Contributing

Contributions are welcome! Please open an issue first to discuss significant changes. See the developer guide for how to set up a development environment.

License

invoke-tasklib is licensed under the BSD 3-Clause "New" or "Revised" license available in LICENSE.

Metadata

Release files for invoke-tasklib 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for invoke-tasklib 0.1.1
File Size Uploaded Provenance Actions
invoke_tasklib-0.1.1.tar.gz 162.2 kB With provenance Details for invoke_tasklib-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for invoke-tasklib 0.1.1
File Interpreter ABI Platform Actions
invoke_tasklib-0.1.1-py3-none-any.whl Python 3 none any Details for invoke_tasklib-0.1.1-py3-none-any.whl

Total release size: 251.7 kB

Release files / invoke_tasklib-0.1.1.tar.gz

Download URL invoke_tasklib-0.1.1.tar.gz
Size 162.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4555cb9d1c1a52cf3b9c0d33b48f2797607faaef7e8f5847d62adf28aa013b18
BLAKE2b-256 checksum
How to use checksums
c6b3faa2b7ac7590bbc7b9f9676016dc41594db8f35ab927908a319bb94d301f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Release files / invoke_tasklib-0.1.1-py3-none-any.whl

Download URL invoke_tasklib-0.1.1-py3-none-any.whl
Size 89.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ad2e623446245ae30a298fd68e2506eb1343f1a48f2765e5845a8f2ed9a28449
BLAKE2b-256 checksum
How to use checksums
1f5c3e961fb1a6263eef13f4ea5cefcb328b1fe97bb938222e865c36b86af842
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Security for invoke-tasklib 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for invoke_tasklib-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page