dockerfile
Parse a dockerfile into a high-level representation using the official go parser.
What it is and what it does
dockerfile is a Python wrapper around Docker's official Dockerfile parser, written in Go. It exposes three main functions: all_cmds() lists valid Dockerfile commands, parse_file() parses a Dockerfile from disk, and parse_string() parses Dockerfile syntax from a string. Each returns a tuple of Command objects with structured fields (cmd, sub_cmd, json flag, original text, line number, flags, and parsed values).
The package is useful for tools that need to analyze or manipulate Dockerfile content programmatically. It has no runtime dependencies and handles parsing errors with specific exception types (GoIOError for file access, GoParseError for syntax). The repository is now archived and unmaintained, though it remains functional for current Python versions.
Use it for:
- Analyze Dockerfile structure in CI/CD pipelines to validate layer counts, base images, or security patterns.
- Extract environment variables, exposed ports, or entrypoint commands from Dockerfiles for documentation or compliance scanning.
- Build linting or static analysis tools that inspect Dockerfile syntax and report violations.
- Programmatically modify or generate Dockerfiles by parsing existing ones and reconstructing them with changes.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Parses Dockerfile syntax into structured Python objects using the official Docker parser, exposing commands, flags, and values for programmatic inspection.
Yes, if you need reliable Dockerfile parsing and can accept that the package is archived. The MIT license is permissive, install friction is manageable with prebuilt wheels, and there are no known vulnerabilities. However, be aware that the repository is no longer maintained—if Docker's parser evolves significantly or you encounter edge cases, upstream fixes are unlikely. For new projects, verify that the parsing behavior matches your current Docker version.
Install
dockerfile on PyPI
pip
pip install dockerfileuv
uv add dockerfilepoetry
poetry add dockerfileInstalling dockerfile
Before you install
Medium install friction due to compiled extension (requires Go compiler when building from source), but prebuilt wheels are available for common platforms. Repository is archived and unmaintained as of 587 days since last release, though the latest version was released on 2025-01-04.
License in practice
MIT license is permissive and poses no restrictions on commercial or private use, modification, or redistribution.
Quickstart
pip install dockerfile
import dockerfile
cmds = dockerfile.parse_file('Dockerfile')
for cmd in cmds:
print(cmd.cmd, cmd.value)
Requires Python >= 3.9. Building from source requires a Go compiler; prebuilt wheels are available for Linux x86_64, macOS (x86_64 and ARM64), and Windows x64.
Verify before relying
- Whether the archived repository will continue to receive security updates or bug fixes if Docker's parser changes significantly.
- Performance characteristics when parsing very large or complex Dockerfiles.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | none |
| Maintenance | abandoned — 587 days since the last release |
| Last repo commit | (repository archived) |
| First released | |
| Downloads | 358,768/month — #7,260 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: dockerfile-3.4.0-cp39-abi3-macosx_13_0_x86_64.whl; dockerfile-3.4.0-cp39-abi3-macosx_14_0_arm64.whl; dockerfile-3.4.0-cp39-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.whl; dockerfile-3.4.0-cp39-abi3-win_amd64.whl
Tags
More Build Tools packages
Provides reusable utilities for Python…
permissive · top 100 on PyPI
tqdmWraps any iterable to display a real-time…
copyleft · top 100 on PyPI
pippip is the standard installer for Python…
permissive · top 100 on PyPI
hatchlingHatchling is a standards-compliant Python build…
permissive · top 100 on PyPI
grpcio-toolsGenerates Python gRPC service stubs and message…
permissive · top 1,000 on PyPI
pre-commitpre-commit is a framework for installing and…
permissive · top 1,000 on PyPI
container-inspectorAnalyzes Docker images, containers, and virtual…
permissive · top 15,000 on PyPI
dockerfile-parseParses and manipulates Dockerfile files…
permissive · top 5,000 on PyPI
tox-dockerA tox plugin that manages Docker container…
permissive · top 15,000 on PyPI
python-on-whalesA Python Docker client that wraps the Docker…
permissive · top 5,000 on PyPI
ast-serializeParses Python source files and serializes their…
permissive · top 1,000 on PyPI
hadolint-coatlProvides a pip-installable hadolint binary…
permissive · top 15,000 on PyPI
flexparserflexparser lets you build parsers by writing…
permissive · top 5,000 on PyPI
bashlexbashlex parses bash shell syntax into an…
copyleft · top 5,000 on PyPI
setuptools-golangA setuptools extension that builds CPython…
permissive · top 5,000 on PyPI
git-url-parseParses Git repository URLs to extract…
permissive · top 15,000 on PyPI