Skip to main content

docker-image-py

Parse docker image as distribution does.

Usage

Install

You can install from PyPI.

$ pip install docker-image-py

Or install from GitHub for latest version.

$ pip install https://github.com/realityone/docker-image-py/archive/master.zip

Parse Docker Image Names

For most user input, use parse_normalized_named(). This follows Docker CLI rules for familiar names: it fills in docker.io, adds library/ for official images, and keeps custom registries intact.

>>> from docker_image import reference
>>>
>>> ref = reference.Reference.parse_normalized_named('ubuntu')
>>> print(ref)
{'name': 'docker.io/library/ubuntu', 'tag': None, 'digest': None}
>>> print(ref.familiar_name())
ubuntu
>>> ref = reference.Reference.parse_normalized_named('containous/traefik')
>>> print(ref)
{'name': 'docker.io/containous/traefik', 'tag': None, 'digest': None}
>>> hostname, name = ref.split_hostname()
>>> print('hostname: {}, name: {}'.format(hostname, name))
hostname: docker.io, name: containous/traefik
>>> ref = reference.Reference.parse_normalized_named('daocloud.io/nginx:latest')
>>> print(ref)
{'name': 'daocloud.io/nginx', 'tag': 'latest', 'digest': None}

Do not use parse() for every image string. parse() is the raw syntax parser from the distribution reference grammar; it does not infer Docker Hub defaults. Use it when the input is already a literal reference and you want grammar-level parsing only.

>>> from docker_image import reference
>>>
>>> ref = reference.Reference.parse('nginx:latest')
>>> print(ref)
{'name': 'nginx', 'tag': 'latest', 'digest': None}
>>> ref = reference.Reference.parse('daocloud.io/nginx')
>>> print(ref)
{'name': 'daocloud.io/nginx', 'tag': None, 'digest': None}
>>> hostname, name = ref.split_hostname()
>>> print('hostname: {}, name: {}'.format(hostname, name))
hostname: daocloud.io, name: nginx
>>> ref = reference.Reference.parse(
...     'daocloud.io/nginx:1.11-alpine@sha256:14bf491df1d58404433b577e093c906460871ee677d18caa276d9c03727e0b33'
... )
>>> print(ref)
{'name': 'daocloud.io/nginx', 'tag': '1.11-alpine', 'digest': 'sha256:14bf491df1d58404433b577e093c906460871ee677d18caa276d9c03727e0b33'}

One common mistake is expecting raw parse() to apply Docker Hub namespace rules. It does not:

>>> from docker_image import reference
>>>
>>> raw = reference.Reference.parse('containous/traefik')
>>> raw.split_hostname()
('containous', 'traefik')
>>> normalized = reference.Reference.parse_normalized_named('containous/traefik')
>>> hostname, name = normalized.split_hostname()
>>> print('hostname: {}, name: {}'.format(hostname, name))
hostname: docker.io, name: containous/traefik

Reference

Release files for docker-image-py 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for docker-image-py 0.2.0
File Size Uploaded
docker_image_py-0.2.0.tar.gz 16.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for docker-image-py 0.2.0
File Interpreter ABI Platform
docker_image_py-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 27.4 kB

Release files / docker_image_py-0.2.0.tar.gz

Download URL docker_image_py-0.2.0.tar.gz
Size 16.2 kB
Tags Source
SHA-256 checksum
How to use checksums
451ad5b3b656d00797e2b84e7ee2629a01012c52a83439cbcfbdeadc3ead3ae1
BLAKE2b-256 checksum
How to use checksums
d4c9b595f95322857b97ff471806ff14a64ea0e41bcd81a88fbbfe09a0190d28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / docker_image_py-0.2.0-py3-none-any.whl

Download URL docker_image_py-0.2.0-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
de6fa26bb4f90a1ad54be1dabc3cb0447007c37e396a5f2bfce5a4aadf15f0c9
BLAKE2b-256 checksum
How to use checksums
b6caf1640909d860379c5ef0e7c2f94c81e654de3ce77add4a88be61674fe20c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.13

2 release files

0.1.12

2 release files

0.1.11

1 release file

0.1.10

2 release files

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page