Docker Image Python Parser

0.1.13 · active · verified Sat Apr 11

docker-image-py is a Python library designed to parse Docker image names, tags, and registries, mimicking how Docker distributions handle image parsing. It provides a structured way to break down an image string into its components. The current version is 0.1.13, released in July 2024, and the library maintains an active, albeit infrequent, release cadence, driven by community contributions and specific parsing needs.

Warnings

Install

Imports

Quickstart

The `Reference.parse()` method is the primary entry point for parsing Docker image strings. It returns a `Reference` object with attributes for registry, repository, tag, and digest.

from docker_image import Reference

# Parse a full image reference
ref = Reference.parse('registry.example.com/repo/image:tag')
print(f"Registry: {ref.registry}")
print(f"Repository: {ref.repository}")
print(f"Tag: {ref.tag}")
print(f"Digest: {ref.digest}")
print(f"Raw: {ref.raw}")

# Parse an image with no registry specified (defaults to 'docker.io')
ref_default = Reference.parse('ubuntu:latest')
print(f"\nRegistry (default): {ref_default.registry}")
print(f"Repository: {ref_default.repository}")

# Parse an image with a digest
ref_digest = Reference.parse('myrepo/myimage@sha256:456abc...')
print(f"\nRepository: {ref_digest.repository}")
print(f"Digest: {ref_digest.digest}")

view raw JSON →