dockerfile-parse
Python library for Dockerfile manipulation
What it is and what it does
dockerfile-parse is a Python library that reads and parses Dockerfile files into a structured representation, exposing properties like base image, labels, and user directives for programmatic inspection and modification. It has no runtime dependencies and supports Python 3.6 through 3.11, making it lightweight to integrate into build tooling, container orchestration systems, or CI/CD pipelines that need to reason about or rewrite Dockerfiles.
The library is in Production/Stable status and has been maintained since 2015, though recent activity is minimal. It is suitable for tasks like extracting metadata from Dockerfiles, validating structure, or generating modified versions with updated base images or labels. The permissive BSD license allows use in both open and closed projects.
Use it for:
- Extract base image, labels, and user directives from existing Dockerfiles for inventory or compliance auditing
- Programmatically update a Dockerfile's base image across a fleet of build configurations
- Validate Dockerfile structure and syntax before passing it to a build system
- Generate or transform Dockerfiles in build automation tools that need to inject environment variables or change layers
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Parses and manipulates Dockerfile files programmatically, allowing you to read, analyze, and modify Dockerfile structure and content through a Python API.
Yes, if you need to parse or modify Dockerfiles in Python code. Low install friction, no dependencies, and stable API make it a straightforward choice for build tooling. Dormant maintenance is acceptable for a mature, narrow-scope library, but verify that its parser handles your target Dockerfile syntax before committing to it in a critical pipeline.
Install
dockerfile-parse on PyPI
pip
pip install dockerfile-parseuv
uv add dockerfile-parsepoetry
poetry add dockerfile-parseInstalling dockerfile-parse
Before you install
Low install friction with no runtime dependencies. Maintenance is dormant—last release was 2023-07-18 and no commits since 2024-08-12—but the package is marked Production/Stable and has been in use since 2015, so it is unlikely to require active development.
License in practice
BSD license is permissive, allowing commercial and private use with minimal restrictions; you must include a copy of the license and copyright notice.
Quickstart
pip install dockerfile-parse
from dockerfile_parse import DockerfileParser
dfp = DockerfileParser()
dfp.content = "FROM base\nLABEL foo=\"bar\"\nUSER me"
print(dfp.baseimage)
dfp.baseimage = 'centos:7'
print(dfp.content)
Verify before relying
- Whether the parser handles all Dockerfile syntax variations and edge cases introduced in recent Docker versions
- Whether dormant maintenance poses a risk if Docker's Dockerfile format evolves significantly
Package facts
| License | BSD (permissive) |
| Python support | supports the current Python release (>=3.6) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | dormant — 1,123 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 11,634,782/month — #1,375 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: dockerfile_parse-2.0.1-py2.py3-none-any.whl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
dockerfileParses Dockerfile syntax into structured Python…
permissive · top 15,000 on PyPI
INIToolsINITools parses and manipulates INI-style…
permissive · top 15,000 on PyPI
plyaraParses YARA rule files into Python dictionary…
permissive · top 15,000 on PyPI
rosdistroParses and manipulates ROS distribution…
permissive · top 15,000 on PyPI
tox-dockerA tox plugin that manages Docker container…
permissive · top 15,000 on PyPI
hadolint-coatlProvides a pip-installable hadolint binary…
permissive · top 15,000 on PyPI
parverparver parses and manipulates PEP 440 version…
permissive · top 5,000 on PyPI
aspy.refactor-importsParses, classifies, and manipulates Python…
permissive · top 15,000 on PyPI
dom-tomlProvides utilities and helpers for working with…
permissive · top 5,000 on PyPI
omegaconfOmegaConf provides a hierarchical configuration…
permissive · top 1,000 on PyPI