Skip to main content

Python client library for Dagu - A cron alternative with a Web UI

Project description

pydagu

PyPI version Tests Python Versions License: MIT

A Python client library for Dagu - providing type-safe DAG creation and HTTP API interaction with Pydantic validation.

Features

  • 🎯 Type-safe: Built with Pydantic models for full type safety and validation
  • 🏗️ Builder Pattern: Fluent API for constructing DAGs and steps
  • 🔌 HTTP Client: Complete client for Dagu's HTTP API
  • 🔄 Webhook Support: Built-in patterns for webhook integration
  • Well-tested: Comprehensive test suite with 95%+ coverage
  • 📝 Examples: Production-ready integration examples

Installation

pip install pydagu

Prerequisites

You need a running Dagu server to run the tests. Install Dagu:

# macOS
brew install dagu-org/brew/dagu

# Linux
curl -L https://github.com/dagu-org/dagu/releases/latest/download/dagu_linux_amd64.tar.gz | tar xz
sudo mv dagu /usr/local/bin/

# Start the server
dagu server

Quick Start

Create and Run a Simple DAG

from pydagu.builder import DagBuilder, StepBuilder
from pydagu.http import DaguHttpClient
from pydagu.models.request import StartDagRun

# Initialize client
client = DaguHttpClient(
    dag_name="my-first-dag",
    url_root="http://localhost:8080/api/v2/"
)

# Build a DAG
dag = (
    DagBuilder("my-first-dag")
    .description("My first DAG with pydagu")
    .add_step_models(
        StepBuilder("hello-world")
        .command("echo 'Hello from pydagu!'")
        .build()
    )
    .build()
)

# Post the DAG to Dagu
client.post_dag(dag)

# Start a run
dag_run_id = client.start_dag_run(StartDagRun(dagName=dag.name))

# Check status
status = client.get_dag_run_status(dag_run_id.dagRunId)
print(f"Status: {status.statusLabel}")

HTTP Executor with Retry

from pydagu.builder import StepBuilder

step = (
    StepBuilder("api-call")
    .command("POST https://api.example.com/webhook")
    .http_executor(
        headers={
            "Content-Type": "application/json",
            "Authorization": "Bearer ${API_TOKEN}"
        },
        body={"event": "user.created", "user_id": "123"},
        timeout=30
    )
    .retry(limit=3, interval=5)
    .build()
)

Chained Steps with Dependencies

from pydagu.builder import DagBuilder, StepBuilder

dag = (
    DagBuilder("data-pipeline")
    .add_step_models(
        StepBuilder("extract")
        .command("python extract_data.py")
        .output("EXTRACTED_FILE")
        .build(),

        StepBuilder("transform")
        .command("python transform_data.py ${EXTRACTED_FILE}")
        .depends_on("extract")
        .output("TRANSFORMED_FILE")
        .build(),

        StepBuilder("load")
        .command("python load_data.py ${TRANSFORMED_FILE}")
        .depends_on("transform")
        .build()
    )
    .build()
)

Development

# Clone the repository
git clone https://github.com/yourusername/pydagu.git
cd pydagu

# Install with dev dependencies
pip install -e ".[dev]"

# Run tests (requires Dagu server running)
pytest tests/ -v

# Run with coverage
pytest tests/ --cov=pydagu --cov-report=html

Documentation

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License - see LICENSE file for details.

Related Projects

  • Dagu - The underlying DAG execution engine
  • Airflow - Alternative workflow orchestration platform

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

pydagu-0.2.1.tar.gz (114.5 kB view details)

Uploaded Source

Built Distribution

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

pydagu-0.2.1-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file pydagu-0.2.1.tar.gz.

File metadata

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

File hashes

Hashes for pydagu-0.2.1.tar.gz
Algorithm Hash digest
SHA256 9b2e6a26e971c138c927ad83111698096cc69e125d36284720195d8b65881129
MD5 d43ed633a8f560f6a738c37c691ba667
BLAKE2b-256 4b4beb372c4da87b3d03d96f9695c0486aa1d44cf3e6841d4d1ad48a5129fe4b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydagu-0.2.1.tar.gz:

Publisher: publish.yml on patrickcd/pydagu

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

File details

Details for the file pydagu-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: pydagu-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 19.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pydagu-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b4d18a497b9a6e76805e2187d262000e709e1e5f537fa86bc28b234382cd2975
MD5 1a18e4e6872b469be957d745f51128e3
BLAKE2b-256 79f84e1e83102accfc0bae1dfcabc3133a87af018ec692c109a3f4b1ff9e656d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydagu-0.2.1-py3-none-any.whl:

Publisher: publish.yml on patrickcd/pydagu

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