Skip to main content

A set of extended APIs for PyInvoke for composable scripts, plugins and richer output

Project description

invoke-toolkit

A set of extensions for rich output, more options in collection/config discovery through entry-points.

This extends the Collection from Invoke so it can create automatically collections.

PyPI - Version PyPI - Python Version


Table of Contents

Features

  • Task discovery by namespace for extendable/composable CLIs
  • Discovery to plain old tasks.py (or any other name)
  • Local tasks discovery from local_tasks.py in the current directory
  • Integration with stand alone binaries for specific tasks
  • Task result caching with TTL support via diskcache (optional)
  • Future Download binaries

Do I need this package

If you have...

  • Used invoke for a while and...
  • Have a large tasks.py that needs to be modularized
  • Have a lot of copy/pasted code in multiple tasks.py across multiple repos.
  • Have exceeded the approach of a repository cloned as ~/tasks/ with more .py files that you want to manage.
  • Or you want to combine various tasks defined in multiple directories
  • You want to create a zipped (shiv) redistribute script for container environments like Kubernetes based CI environments with only requiring the Python interpreter.

Installation

pip install invoke-toolkit

Quick Start

Using Local Tasks

Create a local_tasks.py file in your project directory with your tasks:

from invoke_toolkit import task

@task()
def my_task(ctx):
    """Do something useful"""
    print("Hello from local tasks!")

Then run it with:

intk local.my-task

Local tasks are automatically discovered and added to the local namespace, allowing you to keep project-specific tasks separate from your main task collection.

Using Task Caching

Cache expensive task results with the cache parameter:

from invoke_toolkit import task

# Simple caching (no expiration)
@task(cache=True)
def expensive_task(ctx, param: str) -> str:
    """Results are cached across invocations."""
    return do_expensive_computation(param)

# Caching with TTL (1 hour)
@task(cache={"ttl": 3600})
def cached_task(ctx, name: str) -> dict:
    """Results cached for 1 hour."""
    return fetch_data(name)

# Caching with ignored arguments
@task(cache={"ttl": 600, "ignore_args": ["verbose"]})
def cached_with_options(ctx, query: str, verbose: bool = False) -> list:
    """Cache key ignores verbose flag."""
    return search(query, verbose=verbose)

Cache features:

  • Cache location is computed from git repository root + platformdirs
  • Debug logging (-d flag) shows cache hits/misses
  • Graceful degradation when diskcache is not installed

To enable caching, install with the cache extra:

pip install invoke-toolkit[cache]

Development

This project utilizes the pre-commit framework, make sure you run:

pre-commit install

With uvx:

uvx --with pre-commit-uv pre-commit install

License

invoke-toolkit is distributed under the terms of the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

invoke_toolkit-0.0.53.tar.gz (109.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

invoke_toolkit-0.0.53-py3-none-any.whl (80.6 kB view details)

Uploaded Python 3

File details

Details for the file invoke_toolkit-0.0.53.tar.gz.

File metadata

  • Download URL: invoke_toolkit-0.0.53.tar.gz
  • Upload date:
  • Size: 109.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for invoke_toolkit-0.0.53.tar.gz
Algorithm Hash digest
SHA256 6db51339dde867c458df2dbc3f35e9dac8d8cc6c763e4bd3d704202a41f4553f
MD5 a5c98089fa95cc5a431db8494ee6a57f
BLAKE2b-256 a07a6ad97fab455e23c4df3fde93a6d9a2fd14fa94c636665d84d4d1c0638f4f

See more details on using hashes here.

Provenance

The following attestation bundles were made for invoke_toolkit-0.0.53.tar.gz:

Publisher: publish-releases.yaml on D3f0/invoke-toolkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file invoke_toolkit-0.0.53-py3-none-any.whl.

File metadata

File hashes

Hashes for invoke_toolkit-0.0.53-py3-none-any.whl
Algorithm Hash digest
SHA256 208224ba4809e42f1a3961ab92fb2460a0321f043a23ff2b4bac4174f7a05a09
MD5 f7558457d62012c3695406d7cc155284
BLAKE2b-256 d8e349e55f7771d631d7bfe592e9d908e5c28e55cf86f148dc3aa4c28418c79d

See more details on using hashes here.

Provenance

The following attestation bundles were made for invoke_toolkit-0.0.53-py3-none-any.whl:

Publisher: publish-releases.yaml on D3f0/invoke-toolkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page