GitHub Actions Toolkit for Python

raw JSON →
0.1.15 verified Thu Apr 16 auth: no python maintenance

The `actions-toolkit` Python library provides an SDK to simplify the development of GitHub Actions in Python. It offers functionalities for handling inputs, setting outputs, logging, and interacting with the GitHub Actions environment. The current version is 0.1.15, and while functional, it appears to be in maintenance mode with infrequent updates, as more actively developed alternatives like `github-action-toolkit` and `actions-tools` have emerged.

pip install actions-toolkit
error ModuleNotFoundError: No module named 'actions_toolkit'
cause The `actions-toolkit` package is not installed or the Python environment running the script does not have access to it.
fix
Ensure the package is installed in the active environment using pip install actions-toolkit.
error TypeError: get_input() missing 1 required positional argument: 'name'
cause The `get_input` function was called without the required 'name' argument (the name of the input to retrieve).
fix
Provide the name of the input as a string, e.g., core.get_input('my_input_name').
error AttributeError: module 'actions_toolkit.core' has no attribute 'some_non_existent_function'
cause Attempting to call a function that does not exist in the `core` module, or using a function name from a different GitHub Actions toolkit (e.g., the JavaScript toolkit or another Python wrapper).
fix
Consult the actions-toolkit documentation (or its source on GitHub) to verify available functions and their correct names. If you intended to use a different Python toolkit, adjust your imports and function calls accordingly.
breaking The official GitHub Actions 'toolkit' (JavaScript) has deprecated and is retiring v1-v2 of its cache package and related functionalities within `@actions/cache`. While `actions-toolkit` is a Python library, any action built with it that directly or indirectly relies on older caching mechanisms may fail after March 1, 2025.
fix Review GitHub Actions workflows using caching. Ensure you are using `actions/cache@v3` or newer, and check for any direct calls to `@actions/cache` in JavaScript-based actions if your Python action interoperates with them. It's recommended to update to `actions/cache@v4` or higher for continued support.
gotcha This `actions-toolkit` library (version 0.1.15) appears to be less actively maintained compared to newer, more feature-rich Python toolkits for GitHub Actions. Alternatives like `github-action-toolkit` (different PyPI package, e.g., `pip install github-action-toolkit`) or `actions-tools` offer more recent updates, type safety, and comprehensive features.
fix For new projects, consider evaluating `github-action-toolkit` or `actions-tools` for better long-term support and a richer API. If migrating, be aware of different import paths and API signatures (`from github_action_toolkit import ...` vs. `from actions_toolkit import core`).
gotcha The `core.get_input()` function reads environment variables prefixed with `INPUT_`. If an input is marked `required=True` but the corresponding environment variable is not set, it will raise an error, causing the action to fail. This is common during local testing if environment variables are not correctly mocked.
fix Always ensure required inputs are provided either in the workflow YAML or mocked in your test environment (e.g., `os.environ['INPUT_MY_INPUT'] = 'value'`). Use `required=False` or provide a default value if an input is optional.

This quickstart demonstrates how to get an input, log information, and set an output using the `actions-toolkit` library. The `os.environ` lines simulate how GitHub Action inputs are typically provided and how `GITHUB_ACTOR` can be used as a default.

import os
from actions_toolkit import core

# Simulate GitHub Action input 'name'
os.environ['INPUT_NAME'] = os.environ.get('GITHUB_ACTOR', 'World')

try:
    # Get a required input named 'name'
    name = core.get_input('name', required=True)
    
    # Log an informational message
    core.info(f'Hello, {name}!')
    
    # Set an action output named 'greeting'
    core.set_output('greeting', f'Hello, {name}!')
    
    core.info('Action completed successfully.')
except Exception as e:
    core.set_failed(f'Action failed: {e}')