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 Poetry.

If you already have a Python 3.10 or later interpreter in your $PATH, you can let Poetry manage the virtual environment automatically. Otherwise you need to activate it first, before installing dependencies:

poetry install

The following commands are available:

  • poe test: Run tests.
  • poe fmt: Re-format code following common styling conventions.
  • poe lint: Check for linting violations.
  • poe generate: Regenerate API client after changes to the codegen.
  • poe docs: Build reference docs locally.

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:test
../../hack/make sdk:python:generate

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

../../hack/dev poe 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 poe 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.5.4.tar.gz (52.8 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.5.4-py3-none-any.whl (56.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dagger_io-0.5.4.tar.gz
  • Upload date:
  • Size: 52.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.11.3 Linux/5.15.0-1037-azure

File hashes

Hashes for dagger_io-0.5.4.tar.gz
Algorithm Hash digest
SHA256 05adbdf2881fd748d02173486b7873aa36fe783526b816fc16d5e45a0ef87f95
MD5 a9ee6e395f7d1783d08018056706f384
BLAKE2b-256 a0cc7cd0c5c468b36387324a7cad678ebf3c350671187c83643004370f162bb0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dagger_io-0.5.4-py3-none-any.whl
  • Upload date:
  • Size: 56.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.11.3 Linux/5.15.0-1037-azure

File hashes

Hashes for dagger_io-0.5.4-py3-none-any.whl
Algorithm Hash digest
SHA256 5fa156fb76f968cb6566b68715b1ff50de054140a0b96551e3852183b6f14b8c
MD5 91571b544d97f0ea76ff73e01f05b01c
BLAKE2b-256 07e627c0091e01d4f1f1d34d4a38272e7f2c7fd42bb1deadf68c104b146cbd0a

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