Skip to main content

A client package for running Dagger pipelines in Python.

Project description

Dagger Python SDK

PyPI Version Conda Version Supported Python Versions License Code style Ruff

A client package for running Dagger pipelines.

What is the Dagger Python SDK?

The Dagger Python SDK contains everything you need to develop CI/CD pipelines in Python, and run them on any OCI-compatible container runtime.

Requirements

  • Python 3.10 or later
  • Docker, or another OCI-compatible container runtime

A compatible version of the Dagger CLI is automatically downloaded and run by the SDK for you, although it’s possible to manage it manually.

Installation

From PyPI, using pip:

pip install dagger-io

You can also install via Conda, from the conda-forge channel:

conda install dagger-io

Example

Create a main.py file:

import sys

import anyio
import dagger
from dagger import dag


async def main(args: list[str]):
    async with dagger.connection():
        # build container with cowsay entrypoint
        ctr = (
            dag.container()
            .from_("python:alpine")
            .with_exec(["pip", "install", "cowsay"])
            .with_entrypoint(["cowsay"])
        )

        # run cowsay with requested message
        result = await ctr.with_exec(args).stdout()

    print(result)


anyio.run(main, sys.argv[1:])

Run with:

$ python main.py "Simple is better than complex"
  _____________________________
| Simple is better than complex |
  =============================
                             \
                              \
                                ^__^
                                (oo)\_______
                                (__)\       )\/\
                                    ||----w |
                                    ||     ||

Note It may take a while for it to finish, especially on first run with cold cache.

If you need to debug, you can stream the logs from the engine with the log_output config:

config = dagger.Config(log_output=sys.stderr)
async with dagger.connection(config):
    ...

Learn more

Development

The SDK is managed with a Dagger module in ./dev. To see which tasks are available run:

dagger call -m dev

Common tasks

Run pytest in supported Python versions:

dagger call -m dev tests

Check for linting violations:

dagger call -m dev lint check

Re-format code following common styling conventions:

dagger call -m dev lint format -o .

Update pinned devevelopment dependencies:

dagger call -m dev lock -o .

Build and preview the reference documentation:

dagger call -m dev docs preview up

Add --help to any command to check all the available options.

Engine changes

Testing and regenerating the client may fail if there’s changes in the engine code that haven’t been released yet. Prefix with hack/dev to build a new engine before executing pipelines:

../../hack/dev dagger call -m dev test

To re-generate the client (codegen) after changes to the API schema:

./hack/dev ./hack/make sdk:python:generate

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dagger_io-0.11.4.tar.gz (76.4 kB view details)

Uploaded Source

Built Distribution

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

dagger_io-0.11.4-py3-none-any.whl (71.2 kB view details)

Uploaded Python 3

File details

Details for the file dagger_io-0.11.4.tar.gz.

File metadata

  • Download URL: dagger_io-0.11.4.tar.gz
  • Upload date:
  • Size: 76.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.0

File hashes

Hashes for dagger_io-0.11.4.tar.gz
Algorithm Hash digest
SHA256 f1a38ef034ce5be8b06bebbba832521bb664c7c8508921aff39dd639172cf006
MD5 6c87712df1ce96688ee6e30d2ba5096c
BLAKE2b-256 aead433382dd099a61ce483a9ae22f1a118eb84a366d5abb1a39726dbbce2524

See more details on using hashes here.

File details

Details for the file dagger_io-0.11.4-py3-none-any.whl.

File metadata

  • Download URL: dagger_io-0.11.4-py3-none-any.whl
  • Upload date:
  • Size: 71.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.0

File hashes

Hashes for dagger_io-0.11.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1c9e5da56f47f0825a5ba024be9a32418cd17b07262f92016ae912675862bf03
MD5 1cfad315883873b71af9257b6cb38e0e
BLAKE2b-256 d7cab47ab8817f3ed53b499584d1fb5dbc0570e5321c438e7b4968ff47ad4f81

See more details on using hashes here.

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