Skip to main content
logo_pygha_dark

A Python-native CI/CD framework for defining, testing, and transpiling pipelines to GitHub Actions.

Read the Full Documentation


PyPI Conda Version Python Versions CI Status Documentation Status Coverage Lint (Ruff) Type Check (mypy) Security (Bandit) License


Installation

PyPI

You can install pygha via pip:

pip install pygha

Example: Define a CI Pipeline with pygha

Below is an example of a Python-defined pipeline that mirrors what most teams use in production — build, lint, test, coverage, and deploy — all orchestrated through pygha.

from pygha import job, default_pipeline
from pygha.steps import run, checkout, uses

# Configure the default pipeline to run on main push and PRs
default_pipeline(on_push=["main"], on_pull_request=True)

@job(
    name="test",
    matrix={"python": ["3.11", "3.12", "3.13"]},
)
def test_matrix():
    """Run tests across multiple Python versions."""
    checkout()

    # Use the matrix variable in your step arguments
    setup_python("${{ matrix.python }}", cache="pip")

    run("pip install .[dev]")
    run("pytest")

@job(name="deploy", depends_on=["test"])
def deploy():
    """Build and publish if tests pass."""
    checkout()
    setup_python("3.11", cache="pip")

    run("pip install build twine")
    run("python -m build")
    run("twine check dist/*")

Generating Workflows (CLI)

Once you have defined your pipelines (by default, pygha looks for files matching pipeline_*.py or *_pipeline.py in a .pipe directory), use the CLI to generate the GitHub Actions YAML files.

# Default behavior: Scans .pipe/ and outputs to .github/workflows/
pygha build

Options

  • --src-dir: Source directory containing your Python pipeline definitions (default: .pipe).

  • --out-dir: Output directory where the generated YAML files will be saved (default: .github/workflows).

  • --clean: Automatically deletes YAML files in the output directory that are no longer registered in your pipelines. This is useful when you rename or remove pipelines.

    If you have a manually created workflow file in your output directory that you want to preserve (e.g., manual-deploy.yml), add # pygha: keep to the first 10 lines of that file. The CLI will skip deleting it.

Advanced: Conditional Logic

pygha allows you to write conditional workflows using Python syntax instead of raw YAML strings.

Job-Level Conditions

Use the @run_if decorator to skip entire jobs based on context.

from pygha.decorators import run_if
from pygha.expr import github

@job(name="nightly-scan")
@run_if(github.event_name == "schedule")
def security_scan():
    """Only runs on scheduled events."""
    ...

Step-Level Conditions

Use the when context manager to group steps that should only run under certain conditions. Nested conditions are automatically AND-ed together.

from pygha.steps import when
from pygha.expr import runner, always, failure

@job
def conditional_steps():
    # Simple check
    with when(runner.os == 'Linux'):
        run("sudo apt-get update")

    # Status check helper (runs even if previous steps failed)
    with when(always()):
        run("echo 'Cleanup...'")

    # Nested check: (failure()) AND (runner.os == 'Linux')
    with when(failure()):
        with when(runner.os == 'Linux'):
            run("echo 'Linux build failed!'")

Metadata

Release files for pygha 0.3.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 pygha 0.3.1
File Size Uploaded
pygha-0.3.1.tar.gz 63.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pygha 0.3.1
File Interpreter ABI Platform
pygha-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 80.8 kB

Release files / pygha-0.3.1.tar.gz

Download URL pygha-0.3.1.tar.gz
Size 63.3 kB
Tags Source
SHA-256 checksum
How to use checksums
20a18fe8e8625505cfb9428c3e0816b8e9b729a70129eb55e60fb58ea460cb4e
BLAKE2b-256 checksum
How to use checksums
a309b676f042c544cd15a657cdf2caf93fe6edbf4d3ecff833c28c505559cc25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Dec 22, 2025.

Transparency log

Release files / pygha-0.3.1-py3-none-any.whl

Download URL pygha-0.3.1-py3-none-any.whl
Size 17.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
89655dc665a1d4fc818131c1e3f8d3d08065ed2227e7a10ea8736ef1c4b2c79b
BLAKE2b-256 checksum
How to use checksums
658c54895fcec5e77d073442c7319cb9b1bed072bfcc412c1a38b559fb6de9a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Dec 22, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

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