Tiny actions/core-style helpers for Python GitHub Actions
Project description
gh-actions-tool-kit
A lightweight, typed Python-based toolkit inspired by @actions/core and actions/github, this library provides:
- 🔍 A
Contextclass to access GitHub Action runtime metadata - 📦 A
WebhookPayloadparser to load and normalize GitHub webhook events - 🧠 Models for structured data access (
RepoIdentifier,IssueIdentifier, etc.) - 🐙 A helper for creating authenticated PyGitHub clients
🚀 Quick Start
Installation
pip install gh-actions-tool-kit
Usage
Actions Core Example
# ================================
# greeting.py
# ================================
from actions_tool_kit import get_input, set_output, notice, group
def main() -> None:
name = get_input("name", required=True)
with group("Greeting"):
message = f"Hello, {name}!"
notice(message, title="Python Action")
set_output("greeting", message)
if __name__ == "__main__":
main()
🧩 Features
| Feature | Description |
|---|---|
get_input(name) |
Retrieves the value of an input defined in the GitHub Action with: section. |
get_boolean_input(name) |
Retrieves a boolean input value (true or false) from the with: section, automatically parsing it. |
set_output(name, value) |
Sets an output parameter for the step, which can be used by subsequent steps. |
export_variable(name, value) |
Sets an environment variable that will be available to all subsequent steps in the job. |
add_path(path) |
Prepends a directory to the system PATH variable for all subsequent steps in the job. |
save_state(name, value) |
Saves state data that can be retrieved later using get_state() in a post-run step. Useful for cleanup or teardown. |
get_state(name) |
Retrieves state saved by save_state() earlier in the job. Commonly used in post: scripts. |
set_secret(secret) |
Masks a string from logs to prevent it from being exposed in the GitHub Actions output. |
append_summary(markdown) |
Appends markdown content to the GitHub Actions job summary (visible in the UI under the job). |
notice(message) |
Displays a notice message in the Actions logs. |
warning(message) |
Displays a warning message in the Actions logs, usually in yellow. |
error(message) |
Displays an error message in the Actions logs, usually in red. |
debug(message) |
Sends a debug log message, visible only if step debugging is enabled. |
group(title) / start_group(title) |
Starts a collapsible log group with a given title. |
end_group() |
Ends the most recent collapsible log group. |
Action Context Example
from actions_tool_kit import context
# Basic metadata
print(context.event_name) # "pull_request"
print(context.sha) # commit SHA
print(context.ref) # branch ref
print(context.actor) # user who triggered
# Repo info
print(context.repo.owner) # "your-org"
print(context.repo.repo) # "your-repo"
# Issue or PR
print(context.issue.number) # 42
# Access webhook payload
print(context.payload.pull_request.get("title"))
🧩 Context Properties Features
| Property | Type | Description |
|---|---|---|
| event_name | str | Event type (e.g., push, pull_request) |
| ref | str | Git ref that triggered the workflow |
| sha | str | Commit SHA |
| workflow | str | Workflow name |
| actor | str | Actor triggering the event |
| job | str | Job name |
| run_id | int | Unique run ID |
| run_number | int | Run number |
| run_attempt | int | Retry number for the run |
| api_url | str | GitHub API URL |
| server_url | str | GitHub server URL |
| graphql_url | str | GraphQL endpoint |
| repo | RepoIdentifier | owner and repo parsed |
| issue | IssueIdentifier | repo + issue/pull number |
| pr | PullRequestIdentifier | repo + PR number |
| head_branch | str | For PR events: source branch |
| base_branch | str | For PR events: target branch |
| sender | Sender | Structured sender info |
📄 Webhook Payload Parser
- The parse_payload() function:
- Parses the JSON in $GITHUB_EVENT_PATH
- Normalizes fields like repository, sender, issue, pull_request
- Loads it into a structured WebhookPayload dataclass
[!NOTE] You don’t need to call this manually — Context does it for you.
🧱 Models
| Class | Description |
|---|---|
RepoOwner |
login, name, extra |
PayloadRepository |
name, owner, html_url, etc. |
WebhookPayload |
Top-level GitHub event structure |
RepoIdentifier |
{owner, repo} |
IssueIdentifier |
{owner, repo, number} |
PullRequestIdentifier |
{owner, repo, number} |
Sender |
{type, login, extra} |
Example Workflow
name: demo
on: [push]
jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Run Python Action
env:
name: <your name>
run: python greeting.py
🙌 Credits
Inspired by @actions/core and actions/github
📄 License
MIT License © 2024 AB
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gh_actions_tool_kit-0.2.0.tar.gz.
File metadata
- Download URL: gh_actions_tool_kit-0.2.0.tar.gz
- Upload date:
- Size: 20.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77b33ee7e58c62caa4c560f8a90f7310f872f4039d1aadae33c8ed21a69b10ce
|
|
| MD5 |
212c05d52b8a4842606cc3a95d87fa94
|
|
| BLAKE2b-256 |
41346fba3ee25bb909c0be8af4c467576b7c557978374eb8879edb843fb5d871
|
Provenance
The following attestation bundles were made for gh_actions_tool_kit-0.2.0.tar.gz:
Publisher:
upload-to-pypi.yml on ab-git-actions/gh-actions-tool-kit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gh_actions_tool_kit-0.2.0.tar.gz -
Subject digest:
77b33ee7e58c62caa4c560f8a90f7310f872f4039d1aadae33c8ed21a69b10ce - Sigstore transparency entry: 640504536
- Sigstore integration time:
-
Permalink:
ab-git-actions/gh-actions-tool-kit@b36fcf32daf7615e75f3b5f48c5de3de8726a605 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/ab-git-actions
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
upload-to-pypi.yml@b36fcf32daf7615e75f3b5f48c5de3de8726a605 -
Trigger Event:
push
-
Statement type:
File details
Details for the file gh_actions_tool_kit-0.2.0-py3-none-any.whl.
File metadata
- Download URL: gh_actions_tool_kit-0.2.0-py3-none-any.whl
- Upload date:
- Size: 13.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
efa84215949aefde1a045ae9a977707d0188a905a755a2c8362127bf0c952f13
|
|
| MD5 |
d371f753031650a8c9c0def832fc0618
|
|
| BLAKE2b-256 |
9eaa4920958e6775965ca6684da90377e57274df23776ef143eba72ece5d9287
|
Provenance
The following attestation bundles were made for gh_actions_tool_kit-0.2.0-py3-none-any.whl:
Publisher:
upload-to-pypi.yml on ab-git-actions/gh-actions-tool-kit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gh_actions_tool_kit-0.2.0-py3-none-any.whl -
Subject digest:
efa84215949aefde1a045ae9a977707d0188a905a755a2c8362127bf0c952f13 - Sigstore transparency entry: 640504543
- Sigstore integration time:
-
Permalink:
ab-git-actions/gh-actions-tool-kit@b36fcf32daf7615e75f3b5f48c5de3de8726a605 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/ab-git-actions
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
upload-to-pypi.yml@b36fcf32daf7615e75f3b5f48c5de3de8726a605 -
Trigger Event:
push
-
Statement type: