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
Metadata
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)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| docker_image_py-0.2.0.tar.gz | 16.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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
|
Security for docker-image-py 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.