Registry / devops / dockerfile-parse

dockerfile-parse

JSON →
library2.0.1pypypi✓ verified 35d ago

Dockerfile Parse is a Python library designed for programmatic manipulation and parsing of Dockerfile files. It provides structured access to Dockerfile instructions, making it suitable for tasks like static analysis, linting, and automated tooling around Docker container builds. The library is actively maintained, with version 2.0.1 being the current release, and it frequently receives updates for compatibility with newer Python versions.

devops
Install & Compatibility
Where this runs
tested against v2.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.930 runs
installs and imports cleanly · install 0.0s · import 0.030s · 17.9MB
glibc
py 3.103.930 runs
installs and imports cleanly · install 1.5s · import 0.025s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

from dockerfile_parse import DockerfileParser

Initialize a `DockerfileParser` instance, load Dockerfile content as a string, and then access or modify its parsed elements such as the structure, labels, or the base image. The `content` attribute can be used to read or write the full Dockerfile string.

from pprint import pprint from dockerfile_parse import DockerfileParser dfp = DockerfileParser() dfp.content = """ FROM base LABEL foo="bar baz" USER me """ # Print the parsed structure: print("--- Structure ---") pprint(dfp.structure) # Print labels: print("\n--- Labels ---") pprint(dfp.labels) # Set a new base image: dfp.baseimage = 'centos:7' # Print the new Dockerfile content with an updated FROM line: print("\n--- Updated Dockerfile Content ---") print(dfp.content)
dockerfile-parse --version
Debug
Known footguns
breakingPython 2 support was completely dropped in version 2.0.0. Applications running on Python 2.x will fail to import or run `dockerfile-parse` version 2.0.0 or newer.
breakingSupport for Python 2.6 was dropped in version 0.0.14.
gotchaOlder versions of `dockerfile-parse` (prior to 1.1.0) do not properly support the `escape` directive in Dockerfiles.
gotchaHandling of multi-line instructions, specifically with the `add_lines_at()` method, had issues in versions prior to 0.0.14.
gotchaError reporting for incorrect LABEL syntax was improved in version 0.0.15. Older versions might provide less descriptive errors or unexpected behavior for malformed LABEL instructions.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
24 hits · last 30 days
bytedance
6
gptbot
4
ahrefsbot
4
claudebot
4
googlebot
1
Resources