GitHub Actions Toolkit for Python
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.
Common errors
-
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.fixEnsure the package is installed in the active environment using `pip install actions-toolkit`. -
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).fixProvide the name of the input as a string, e.g., `core.get_input('my_input_name')`. -
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).fixConsult 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.
Warnings
- 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.
- 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.
- 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.
Install
-
pip install actions-toolkit
Imports
- core
from actions_toolkit.core import *
from actions_toolkit import core
Quickstart
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}')