A client package for running Dagger pipelines in Python.
Project description
Dagger Python SDK
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
Built Distribution
Hashes for dagger_io-0.6.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d10abf5132983853fb50bf4f38cd771035a9ab975f78070362e4fb077925b170 |
|
MD5 | 51e9a837726313d403479c831c02a3ec |
|
BLAKE2b-256 | c38ba7cf12c3d079f88a0f7f48eda6fcbc21e1083d546d31d6dc45b6c9a0877f |