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


async def main(args: list[str]):
    async with dagger.Connection() as client:
        # build container with cowsay entrypoint
        ctr = (
            client.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) as client:
    ...

Learn more

Development

This library is maintained with Hatch.

The following commands are available:

  • hatch run test: Run tests.
  • hatch run fmt: Re-format code following common styling conventions.
  • hatch run lint: Check for linting violations.
  • hatch run typing:check: Run the type checker.
  • hatch run docs:build: Build reference docs locally
  • hatch run docs:preview: Build and serve reference docs (defaults to localhost:8000)

Engine changes

Testing and regenerating the client may fail if there’s changes in the engine code that haven’t been released yet.

The simplest way to run those commands locally with the most updated engine version is to build it using Dagger’s CI pipelines :

../../hack/make sdk:python:generate
../../hack/make sdk:python:lint
../../hack/make sdk:python:test

You can also build the CLI and use it directly within the Python SDK:

../../hack/dev hatch test

Or build it separately and tell the SDK to use it directly (or any other CLI binary):

../../hack/make
_EXPERIMENTAL_DAGGER_CLI_BIN=../../bin/dagger hatch test

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.8.7.tar.gz (63.6 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.8.7-py3-none-any.whl (61.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for dagger_io-0.8.7.tar.gz
Algorithm Hash digest
SHA256 f13048ffde4ba63144be395f53ac09c7e5825861e4ce2c35805df3b087bc505a
MD5 90ea0cf0467c02e1a4ec68bf75ef52f3
BLAKE2b-256 d28e0101d9a8c5aea3d49de8d9e88238f917021057adae817306ff7d9c16e8c0

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for dagger_io-0.8.7-py3-none-any.whl
Algorithm Hash digest
SHA256 724bdbf70ab7368495aede97891ab4ba20d65ae4120f3b2821db80b7f33817b6
MD5 5dd8ca60564a8b7a0a7d7843a868d6d4
BLAKE2b-256 ee76aaf8c4e2e075c5366b4f43e363bac1e5a47867054bb9a0426c7834ccf6c6

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