docker-dsl
An imperative, context-manager-based Python DSL for authoring multi-stage
Dockerfiles. Write builds with with blocks, conditionals, comprehensions, and
reusable helpers, then render one recipe into many Dockerfile variants.
Install
Run it through uvx, no install needed:
uvx docker-dsl --help
Quickstart
Write a recipe module, minimal.py:
from docker_dsl import Stage
from docker_dsl import context as ctx
ctx.register("tag", str)
with Stage("ubuntu:24.04") as s:
s.arg("APP_TAG", ctx.tag or "latest", env=True)
s.workdir("/app")
with s.run() as r:
r.echo("hello from docker-dsl") > "/app/greeting.txt"
s.cmd("cat", "/app/greeting.txt")
Render it:
uvx docker-dsl minimal --tag=v1.0.0 --out Dockerfile
Dockerfile now holds:
# syntax=docker/dockerfile:1
FROM ubuntu:24.04 AS base
ARG APP_TAG=v1.0.0
ENV APP_TAG=${APP_TAG}
WORKDIR /app
RUN echo "hello from docker-dsl" > /app/greeting.txt
CMD ["cat", "/app/greeting.txt"]
Change --tag and render again for a different Dockerfile from the same recipe.
Why
RUNchains glued with&&are fragile. The run builder accumulates commands in Python and emits one correctRUN, withcdscoping restored for you.- Variants drift apart. One recipe takes
--gpu=true|falseand renders both a GPU and a CPU image from the same code path, instead of two Dockerfiles that diverge over time. - BuildKit mounts are easy to get wrong.
cache,secret, andbindare scoped context managers, so everyRUNinside the block picks them up and nothing leaks out.
Docs
The documentation has a tutorial, task-focused guides (multi-stage builds, mounts, smart apt, the run builder, reusable helpers, and the CLI), and the full API reference.
License
This project is licensed under the MIT License; see LICENSE.
Metadata
Release files for docker-dsl 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| docker_dsl-0.1.2.tar.gz | 58.9 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| docker_dsl-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 122.0 kB
Release files / docker_dsl-0.1.2.tar.gz
| Download URL | docker_dsl-0.1.2.tar.gz |
|---|---|
| Size | 58.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8cd50f0b0623c2673d2b6894447d58719fd1a72ac4ae357781e0d33a61305948
|
|
BLAKE2b-256 checksum How to use checksums |
0ef4758df01842737a2c8f9b788f95fc08d21f88ef6fb9a68b5cfd6cfe3a5aed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 3, 2026.
Transparency logRelease files / docker_dsl-0.1.2-py3-none-any.whl
| Download URL | docker_dsl-0.1.2-py3-none-any.whl |
|---|---|
| Size | 63.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d91e20da2521788936f9ff454c43088cbc8eadf2417fbc5b6de3c2ebcb7f529a
|
|
BLAKE2b-256 checksum How to use checksums |
78b416cee124aadfc911ce8b2ca85608a12602b16c88dfd6ac877ac5740cb535
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 3, 2026.
Transparency logSecurity for docker-dsl 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for docker_dsl-0.1.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 3, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.