image package

Submodules

image.auth module

Contains the AUTH constant which loads the user’s default podman auth file.

image.auth.AUTH

The AUTH constant contains the loaded contents from your default podman auth file. This is located at $XDG_RUNTIME_DIR/containers/auth.json on linux and $HOME/.config/containers/auth.json on mac and windows

The AUTH constant remains an empty dict if the user has no auth file. A UserWarning is raised if the user’s auth file does exist, but contains invalid JSON.

image.byteunit module

Contains the ByteUnit class, which just contains a single helper method for accepting an integer byte measurement (in bytes) and formatting it as a human readable string measured in the nearest byte unit, and with the byte unit abbreviation appended onto the end of the string.

class image.byteunit.ByteUnit

Bases: object

Contains static helper methods for formatting byte size measurements

static format_size_bytes(size: int) str

Format size in bytes as a human readable string, representing the size at its nearest byte unit

Parameters:

size (int) – The size in bytes

Returns:

The size formatted as a human readable string (e.g. “2.51 MB”)

Return type:

str

image.client module

Contains the ContainerImageRegistryClient class, which accepts and parses ContainerImageReference objects, then makes calls against the reference’s distribution registry API.

class image.client.ContainerImageRegistryClient

Bases: object

A CNCF distribution registry API client

static delete(str_or_ref: str | ContainerImageReference, auth: Dict[str, Any])

Deletes the reference from the registry using the registry API

Parameters:
  • str_or_ref (Union[str, ContainerImage]) – An image reference

  • auth (Dict[str, Any]) – A valid docker config JSON loaded into a dict

static get_auth_token(res: Response, reg_auth: str) Tuple[str, str]

The response from the distribution registry API, which MUST be a 401 response, and MUST include the www-authenticate header

Parameters:
  • res (requests.Response) – The response from the registry API

  • reg_auth (str) – The auth retrieved for the registry

Returns:

The auth scheme for the token str: The token retrieved from the auth service

Return type:

str

static get_config(str_or_ref: str | ContainerImageReference, config_desc: ContainerImageDescriptor, auth: Dict[str, Any]) Dict[str, Any]

Fetches a config blob from the registry API and returns as a dict

Parameters:
  • str_or_ref (Union[str, ContainerImageReference]) – An image reference corresponding to the config descriptor

  • desc (ContainerImageDescriptor) – A blob descriptor

  • auth (Dict[str, Any]) – A valid docker config JSON loaded into a dict

Returns:

The config as a dict

Return type:

Dict[str, Any]

static get_digest(str_or_ref: str | ContainerImageReference, auth: Dict[str, Any]) str

Fetches the digest from the registry API

Parameters:
  • str_or_ref (Union[str, ContainerImageReference]) – An image reference

  • auth (Dict[str, Any]) – A valid docker config JSON loaded into a dict

Returns:

The image digest

Return type:

str

static get_manifest(str_or_ref: str | ContainerImageReference, auth: Dict[str, Any]) Dict[str, Any]

Fetches the manifest from the registry API and returns as a dict

Parameters:
  • str_or_ref (Union[str, ContainerImageReference]) – An image reference

  • auth (Dict[str, Any]) – A valid docker config JSON loaded into a dict

Returns:

The manifest loaded into a dict

Return type:

Dict[str, Any]

static get_registry_auth(str_or_ref: str | ContainerImageReference, auth: Dict[str, Any]) Tuple[str, bool]

Gets the registry auth from a docker config JSON matching the registry for this image

Parameters:
  • str_or_ref (Union[str, ContainerImageReference]) – An image reference

  • auth (Dict[str, Any]) – A valid docker config JSON loaded into a dict

Returns:

The auth, and whether an auth was found

Return type:

Tuple[str, bool]

static get_registry_base_url(str_or_ref: str | ContainerImageReference) str

Constructs the distribution registry API base URL from the image reference.

For example, - quay.io/ibm/software/cloudpak/hello-world:latest

Would become - https://quay.io/v2/ibm/software/cloudpak/hello-world

Parameters:

str_or_ref (Union[str, ContainerImageReference]) – An image reference

Returns:

The distribution registry API base URL

Return type:

str

static list_tags(str_or_ref: str | ContainerImageReference, auth: Dict[str, Any]) Dict[str, Any]

Fetches the list of tags for a reference from the registry API and returns as a dict :param str_or_ref: An image reference :type str_or_ref: Union[str, ContainerImageReference] :param auth: A valid docker config JSON loaded into a dict :type auth: Dict[str, Any]

Returns:

The config as a dict

Return type:

Dict[str, Any]

static query_blob(str_or_ref: str | ContainerImageReference, desc: ContainerImageDescriptor, auth: Dict[str, Any]) Response

Fetches a blob from the registry API and returns as a requests response object

Parameters:
  • str_or_ref (Union[str, ContainerImageReference]) – An image reference corresponding to the blob descriptor

  • desc (ContainerImageDescriptor) – A blob descriptor

  • auth (Dict[str, Any]) – A valid docker config JSON loaded into a dict

Returns:

The registry API blob response

Return type:

requests.Response

static query_manifest(str_or_ref: str | ContainerImageReference, auth: Dict[str, Any]) Response

Fetches the manifest from the registry API and returns as a requests response object

Parameters:
  • str_or_ref (Union[str, ContainerImageReference]) – An image reference

  • auth (Dict[str, Any]) – A valid docker config JSON loaded into a dict

Returns:

The registry API response

Return type:

requests.Response

static query_tags(str_or_ref: str | ContainerImageReference, auth: Dict[str, Any]) Response

Fetches the list of tags for a reference from the registry API and returns as a dict :param str_or_ref: An image reference :type str_or_ref: Union[str, ContainerImageReference] :param auth: A valid docker config JSON loaded into a dict :type auth: Dict[str, Any]

Returns:

The registry API tag list response

Return type:

requests.Response

image.client.DEFAULT_REQUEST_MANIFEST_MEDIA_TYPES = ['application/vnd.docker.distribution.manifest.list.v2+json', 'application/vnd.docker.distribution.manifest.v2+json', 'application/vnd.oci.image.index.v1+json', 'application/vnd.oci.image.manifest.v1+json', 'application/vnd.docker.distribution.manifest.v1+json', 'application/vnd.docker.distribution.manifest.v1+prettyjws']

The default accepted mediaTypes for querying manifests

image.config module

Contains the ContainerImageConfig class, which specifies the runtime configuration for a container image.

class image.config.ContainerImageConfig(config: Dict[str, Any])

Bases: object

The runtime configuration for a container image

get_architecture() str

Returns the config’s architecture

Returns:

The config’s architecture

Return type:

str

get_author() str

Returns the author of the container image from its config

Returns:

The container image author

Return type:

str

get_created_date() str

Returns the created date of the container image from the config

Returns:

The created date, as a string

Return type:

str

get_env() List[str]

Returns the list of environment variables set for the container image at build time from the container image runtime config

Returns:

The list of environment variables

Return type:

List[str]

get_labels() Dict[str, str]

Returns the container image labels from the config

Returns:

The labels from the config

Return type:

Dict[str, str]

get_os() str

Returns the config’s operating system name

Returns:

The config’s operating system name

Return type:

str

get_platform() Type[ContainerImagePlatform]

Returns the platform of the config as a ContainerImagePlatform

Returns:

The platform

Return type:

Type[ContainerImagePlatform]

get_runtime_config() Dict[str, Any]

Returns the runtime config for the container image from its config

Returns:

The container image runtime config

Return type:

Dict[str, Any]

get_variant() str | None

Returns the platform’s variant, None if not found

Returns:

The platform variant, None if not found

Return type:

Union[str, None]

validate() Tuple[bool, str]

Validates a ContainerImageConfig instance

Returns:

Whether the config is valid, error message

Return type:

Tuple[bool, str]

validate_static() Tuple[bool, str]

Validates a container image config loaded into a dict

Parameters:

config (Dict[str, Any]) – The config loaded into a dict

Returns:

Whether the config is valid, error message

Return type:

Tuple[bool, str]

image.configschema module

Contains various JSON schema constants which together form the overarching container image config schema

image.configschema.CONTAINER_IMAGE_CONFIG_HISTORY_SCHEMA

The JSON schema for the entries in the history list property in a container image config

image.configschema.CONTAINER_IMAGE_CONFIG_ROOTFS_SCHEMA

The JSON schema for the rootfs property of a container image config

image.configschema.CONTAINER_IMAGE_CONFIG_RUNTIME_CONFIG_SCHEMA

The JSON schema for the config property of a container image config

image.configschema.CONTAINER_IMAGE_CONFIG_SCHEMA

The JSON schema for a container image config

image.containerimage module

Contains the ContainerImage object, which is the main object intended for use by end-users of containerimage-py. As a user of this object, you can pass in a reference to a container image in a remote registry. Then through the object interface you can interact with the container image & registry, fetching metadata and mutating the image through the registry API.

class image.containerimage.ContainerImage(ref: str)

Bases: ContainerImageReference

Extends the ContainerImageReference class and uses the ContainerImageRegistryClient class to provide a convenient interface through which users can specify their image reference, then query the registry API for information about the image.

delete(auth: Dict[str, Any])

Deletes the image from the registry.

Parameters:

auth (Dict[str, Any]) – A valid docker config JSON loaded into a dict

exists(auth: Dict[str, Any]) bool

Determine if the image reference corresponds to an image in the remote registry.

Parameters:

auth (Dict[str, Any]) – A valid docker config JSON with auth into this image’s registry

Returns:

Whether the image exists in the registry

Return type:

bool

get_config(auth: Dict[str, Any]) ContainerImageConfig

Fetches the image’s config from the distribution registry API. If the image is a manifest list, then it gets the config corresponding to the manifest matching the host platform.

Parameters:

auth (Dict[str, Any]) – A valid docker config JSON with auth into this image’s registry

Returns:

The config for this image

Return type:

ContainerImageConfig

Raises:

ContainerImageError – Error if the image is a manifest list without a manifest matching the host platform

static get_config_static(ref: ContainerImageReference, manifest: ContainerImageManifestV2S2 | ContainerImageManifestListV2S2 | ContainerImageManifestOCI | ContainerImageIndexOCI, auth: Dict[str, Any]) ContainerImageConfig

Given an image’s manifest, this static method fetches that image’s config from the distribution registry API. If the image is a manifest list, then it gets the config corresponding to the manifest matching the host platform.

Parameters:
Returns:

The config for this image

Return type:

ContainerImageConfig

Raises:

ContainerImageError – Error if the image is a manifest list without a manifest matching the host platform

get_digest(auth: Dict[str, Any]) str

Parses the digest from the reference if digest reference, or fetches it from the registry if tag reference

Parameters:

auth (Dict[str, Any]) – A valid docker config JSON

Returns:

The image digest

Return type:

str

get_host_platform_manifest(auth: Dict[str, Any]) ContainerImageManifestOCI | ContainerImageManifestV2S2

Fetches the manifest from the distribution registry API. If the manifest is a manifest list, then it attempts to fetch the manifest in the list matching the host platform. If not found, an exception is raised.

Parameters:

auth (Dict[str, Any]) – A valid docker config JSON with auth into this image’s registry

Returns:

The manifest response from the registry API

Return type:

Union[ContainerImageManifestV2S2,ContainerImageManifestOCI]

Raises:

ContainerImageError – Error if the image is a manifest list without a manifest matching the host platform

static get_host_platform_manifest_static(ref: ContainerImageReference, manifest: ContainerImageManifestV2S2 | ContainerImageManifestListV2S2 | ContainerImageManifestOCI | ContainerImageIndexOCI, auth: Dict[str, Any]) ContainerImageManifestV2S2 | ContainerImageManifestOCI

Given an image’s reference and manifest, this static method checks if the manifest is a manifest list, and attempts to get the manifest from the list matching the host platform.

Parameters:
Returns:

The manifest response from the registry API

Return type:

Union[ContainerImageManifestV2S2,ContainerImageManifestOCI]

Raises:

ContainerImageError – Error if the image is a manifest list without a manifest matching the host platform

get_manifest(auth: Dict[str, Any]) ContainerImageManifestV2S2 | ContainerImageManifestListV2S2 | ContainerImageManifestOCI | ContainerImageIndexOCI

Fetches the manifest from the distribution registry API

Parameters:

auth (Dict[str, Any]) – A valid docker config JSON with auth into this image’s registry

Returns:

The manifest or manifest list response from the registry API

Return type:

Union[ContainerImageManifestV2S2,ContainerImageManifestListV2S2,ContainerImageManifestOCI,ContainerImageIndexOCI]

get_media_type(auth: Dict[str, Any]) str

Gets the image’s mediaType from its manifest

Parameters:

auth (Dict[str, Any]) – A valid docker config JSON loaded into a dict

Returns:

The image’s mediaType

Return type:

str

get_platforms(auth: Dict[str, Any]) List[ContainerImagePlatform]

Returns the supported platform(s) for the image as a list of ContainerImagePlatforms

Parameters:

auth (Dict[str, Any]) – A valid docker config JSON

Returns:

The supported platforms

Return type:

List[ContainerImagePlatform]

get_size(auth: Dict[str, Any]) int

Calculates the size of the image by fetching its manifest metadata from the registry.

Parameters:

auth (Dict[str, Any]) – A valid docker config JSON loaded into a dict

Returns:

The size of the image in bytes

Return type:

int

get_size_formatted(auth: Dict[str, Any]) str

Calculates the size of the image by fetching its manifest metadata from the registry. Formats as a human readable string (e.g. 3.14 KB)

Parameters:

auth (Dict[str, Any]) – A valid docker config JSON loaded into a dict

Returns:

The size of the image in bytes in human readable format (1.25 GB)

Return type:

str

inspect(auth: Dict[str, Any]) ContainerImageInspect

Returns a collection of basic information about the image, equivalent to skopeo inspect.

Parameters:

auth (Dict[str, Any]) – A valid docker config JSON loaded into a dict

Returns:

A collection of information about the image

Return type:

ContainerImageInspect

is_manifest_list(auth: Dict[str, Any]) bool

Determine if the image is a manifest list

Parameters:

auth (Dict[str, Any]) – A valid docker config JSON with auth into this image’s registry

Returns:

Whether the image is a manifest list or single-arch

Return type:

bool

static is_manifest_list_static(manifest: ContainerImageManifestV2S2 | ContainerImageManifestListV2S2 | ContainerImageManifestOCI | ContainerImageIndexOCI) bool

Determine if an arbitrary manifest object is a manifest list

Parameters:

manifest (Union[ContainerImageManifestV2S2,ContainerImageManifestListV2S2,ContainerImageManifestOCI,ContainerImageIndexOCI]) – The manifest object, generally from get_manifest method

Returns:

Whether the manifest object is a list or single-arch

Return type:

bool

is_oci(auth: Dict[str, Any]) bool

Determine if the image is in the OCI format

Parameters:

auth (Dict[str, Any]) – A valid docker config JSON with auth into this image’s registry

Returns:

Whether the image is in the OCI format

Return type:

bool

static is_oci_static(manifest: ContainerImageManifestV2S2 | ContainerImageManifestListV2S2 | ContainerImageManifestOCI | ContainerImageIndexOCI) bool

Determine if an arbitrary manifest object is an OCI manifest or image index.

Parameters:

manifest (Union[ContainerImageManifestV2S2,ContainerImageManifestListV2S2,ContainerImageManifestOCI,ContainerImageIndexOCI]) – The manifest object, generally from get_manifest method

Returns:

Whether the manifest object is in the OCI format

Return type:

bool

list_tags(auth: Dict[str, Any]) Dict[str, Any]

Fetches the list of tags for the image from the distribution registry API. :param auth: A valid docker config JSON with auth into this image’s registry :type auth: Dict[str, Any]

Returns:

The tag list loaded into a dict

Return type:

Dict[str, Any]

validate() bool

Validates an image reference

Returns:

Whether the ContainerImage’s reference is valid

Return type:

bool

class image.containerimage.ContainerImageList

Bases: object

Represents a list of ContainerImages. Enables performing bulk actions against many container images at once.

append(image: Type[ContainerImage])

Append a new ContainerImage to the ContainerImageList

Parameters:

image (Type[ContainerImage]) – The ContainerImage to add

delete(auth: Dict[str, Any])

Delete all of the container images in the list from the registry

Parameters:

auth (Dict[str, Any]) – A valid docker config JSON dict

diff(previous: Type[ContainerImageList]) Type[ContainerImageListDiff]

Compare this ContainerImageList with another and identify images which were added, removed, updated, and common across both instances. Here, the receiver ContainerImageList is viewed as the current version, while the argument ContainerImageList is viewed as the previous version.

Parameters:

previous (Type[ContainerImageList]) – The “previous” ContainerImageList

Returns:

The diff between the ContainerImageLists

Return type:

Type[ContainerImageListDiff]

get_size(auth: Dict[str, Any]) int

Get the deduplicated size of all container images in the list

Parameters:

auth (Dict[str, Any]) – A valid docker config JSON dict

Returns:

The deduplicated size of all container images in the list

Return type:

int

get_size_formatted(auth: Dict[str, Any]) str

Get the deduplicated size of all container images in the list, formatted as a human readable string (e.g. 3.14 MB)

Parameters:

auth (Dict[str, Any]) – A valid docker config JSON dict

Returns:

List size in bytes formatted to nearest unit (ex. “1.23 MB”)

Return type:

str

class image.containerimage.ContainerImageListDiff

Bases: object

Represents a diff between two ContainerImageLists

image.containerimage.wrapped_default(self, obj)

image.containerimageinspect module

class image.containerimageinspect.ContainerImageInspect(inspect: Dict[str, Any])

Bases: object

Represents a collection of basic informataion about a container image. This object is equivalent to the output of skopeo inspect.

validate() Tuple[bool, str]

Validate a container image inspect instance

Returns:

Whether the container image inspect dict was valid str: Error message if it was invalid

Return type:

bool

static validate_static(inspect: Dict[str, Any]) Tuple[bool, str]

Validate a container image inspect dict using its json schema

Parameters:

inspect (dict) – The container image inspect dict to validate

Returns:

Whether the container image inspect dict was valid str: Error message if it was invalid

Return type:

bool

image.descriptor module

Contains a base ContainerImageDescriptor class which is implemented by the docker v2s2 and OCI specifications for layer, config, and blob descriptors

class image.descriptor.ContainerImageDescriptor(descriptor: Dict[str, Any])

Bases: object

Represents a descriptor defined by the OCI image specification. Descriptors simply describe some content stored by the registry, which include configs and layers.

A ContainerImageDescriptor follows a JSON schema which is a superset of the v2s2 config & layer schemas, which are effectively just descriptors. Hence, we reuse this class across both v2s2 layers / configs, and OCI descriptors.

get_annotations() Dict[str, Any] | None

Returns the annotations if found, else None

Args: None

Returns: Union[Dict[str, Any], None]: The descriptor annotations or None

get_digest() str

Returns the descriptor digest, validates the digest in the process

Args: None

Returns: str: The layer digest

get_media_type() str

Returns the layer mediaType

Args: None

Returns: str: The layer mediaType

get_size() int

Returns the layer size in bytes

Args: None

Returns: int: The layer size

get_urls() List[str] | None

Returns the descriptor URLs if found, else None

Args: None

Returns: Union[List[str], None]: The descriptor URLs or None

validate() Tuple[bool, str]

Validates a ContainerImageDescriptor instance

Args: None

Returns: Tuple[bool, str]: Whether the descriptor metadata is valid, error msg

static validate_static(descriptor: Dict[str, Any]) Tuple[bool, str]

Validates OCI descriptor metadata

Args: layer (Dict[str, Any]): The descriptor metadata to validate

Returns: Tuple[bool, str]: Whether the descriptor metadata is valid, error msg

image.errors module

Contains custom exceptions thrown by some components of containerimage-py

exception image.errors.ContainerImageError

Bases: Exception

A generic Exception extension for errors thrown by containerimage-py

image.inspectschema module

image.inspectschema.CONTAINER_IMAGE_INSPECT_SCHEMA

The JSON schema for validating a container image inspect dictionary Ref: - https://github.com/containers/image/blob/main/types/types.go#L474-L489 - https://github.com/containers/image/blob/main/types/types.go#L474-L489

image.inspectschema.CONTAINER_IMAGE_LAYER_INSPECT_SCHEMA

The JSON schema for validating a container image layer inspect dictionary Ref: https://github.com/containers/image/blob/main/types/types.go#L491-L497

image.manifest module

Contains a base ContainerImageManifest class which is extended by the docker v2s2 and OCI specifications for their respective manifest implementations

class image.manifest.ContainerImageManifest(manifest: Dict[str, Any])

Bases: object

Represents an arch manifest returned from the distribution registry API. This is a base class extended by the ContainerImageManifestV2S2 and ContainerImageManifestOCI since the two specs are very similar, with the v2s2 spec being more restrictive than the OCI spec.

get_config_descriptor() ContainerImageDescriptor

Returns the container image manifest config descriptor

Returns:

The container image manifest config descriptor

Return type:

ContainerImageDescriptor

get_layer_descriptors() List[ContainerImageDescriptor]

Returns a list of the container image’s layer descriptors, defaults to empty list

Returns:

The container image’s layer descriptors

Return type:

List[ContainerImageDescriptor]

get_media_type() str

Returns the mediaType of the container image manifest

Returns:

The container image manifest mediaType

Return type:

str

get_size() int

Returns the container image manifest size in bytes

Returns:

The container image manifest size in bytes

Return type:

int

image.manifestfactory module

Contains a base factory pattern implementation in which a generic manifest dict can be passed in, and the factory can determine which manifest type to return

class image.manifestfactory.ContainerImageManifestFactory

Bases: object

A factory pattern implementation. Given a distribution registry manifest response, this class can instantiate any of the following types, based on the manifest’s format - ContainerImageManifestListV2S2 - ContainerImageManifestV2S2 - ContainerImageIndexOCI - ContainerImageManifestOCI

create() ContainerImageManifestV2S2 | ContainerImageManifestListV2S2 | ContainerImageManifestOCI | ContainerImageIndexOCI

Given a manifest response from the distribution registry API, create the appropriate type of manifest / manifest list object based on the response schema - ContainerImageManifestV2S2 - ContainerImageManifestListV2S2 - ContainerImageManifestOCI - ContainerImageIndexOCI

Parameters:

manifest_or_list (Dict[str, Any]) – A manifest or manifest list dict

Returns:

Manifest or manifest list objects for the OCI & v2s2 specs

Return type:

Union[ContainerImageManifestV2S2,ContainerImageManifestListV2S2,ContainerImageManifestOCI,ContainerImageIndexOCI]

create_oci_image_index() ContainerImageIndexOCI

Given an image index response from the distribution registry API, create a ContainerImageIndexOCI, or raise an exception if it’s invalid

Parameters:

index (Dict[str, Any]) – An OCI image index dict

Returns:

An OCI image index object

Return type:

ContainerImageIndexOCI

create_oci_manifest() ContainerImageManifestOCI

Given a manifest response from the distribution registry API, create a ContainerImageManifestOCI, or raise an exception if it’s invalid

Parameters:

manifest (Dict[str, Any]) – An OCI manifest dict

Returns:

An OCI manifest object

Return type:

ContainerImageManifestOCI

create_v2s2_manifest() ContainerImageManifestV2S2

Given a manifest response from the distribution registry API, create a ContainerImageManifestV2S2, or raise an exception if it’s invalid

Parameters:

manifest (Dict[str, Any]) – A v2s2 manifest dict

Returns:

A v2s2 manifest object

Return type:

ContainerImageManifestV2S2

create_v2s2_manifest_list() ContainerImageManifestListV2S2

Given a manifest list response from the distribution registry API, create a ContainerImageManifestListV2S2, or raise an exception if it’s invalid

Parameters:

manifest_list (Dict[str, Any]) – A v2s2 manifest list dict

Returns:

A v2s2 manifest list object

Return type:

ContainerImageManifestListV2S2

image.manifestlist module

Contains a base ContainerImageManifestList class which is extended by the docker v2s2 and OCI specifications for their respective manifest list implementations

class image.manifestlist.ContainerImageManifestList(manifest_list: Dict[str, Any])

Bases: object

Represents a manifest list returned from the distribution registry API. This is a base class extended by the ContainerImageManifestListV2S2 and ContainerImageManifestListOCI since the two specs are very similar, with the v2s2 spec being more restrictive than the OCI spec.

get_config_descriptors(name: str, auth: Dict[str, Any]) List[ContainerImageDescriptor]

Retrieves the config descriptors for each manifest image combined into a list

Parameters:
  • name (str) – A valid image name, the name of the manifest

  • auth (Dict[str, Any]) – A valid docker config JSON dict

Returns:

The list of config descriptors across each of the manifests

Return type:

List[ContainerImageDescriptor]

get_entries() List[ContainerImageManifestListEntry]

Returns the manifest list entries as ContainerImageManifestListEntry instances

Returns:

The entries

Return type:

List[ContainerImageManifestListEntry]

get_entry_sizes() int

Returns the combined size of each of the entries in the list

Returns:

The combined size of each of the entries in the list

Return type:

int

get_layer_descriptors(name: str, auth: Dict[str, Any]) List[ContainerImageDescriptor]

Retrieves the layer descriptors for each manifest image combined into a list

Parameters:
  • name (str) – A valid image name, the name of the manifest

  • auth (Dict[str, Any]) – A valid docker config JSON dict

Returns:

The list of layer descriptors across each of the manifests

Return type:

int

get_manifests(name: str, auth: Dict[str, Any]) List[ContainerImageManifest]

Fetches the arch manifests from the distribution registry API

Parameters:
  • name (str) – A valid image name, the name of the manifest

  • auth (Dict[str, Any]) – A valid docker config JSON dict

Returns:

The arch manifests

Return type:

List[ContainerImageManifest]

get_media_type() str

Returns the mediaType of the container image manifest list

Returns:

The container image manifest list mediaType

Return type:

str

get_size(name: str, auth: Dict[str, Any]) int

Calculates the size of the image using the distribution registry API

Parameters:
  • name (str) – A valid image name, the name of the manifest

  • auth (Dict[str, Any]) – A valid docker config JSON dict

Returns:

The size of the manifest list in bytes

Return type:

int

image.manifestlistentry module

Contains a base ContainerImageManifestListEntry class which is extended by the docker v2s2 and OCI specifications for the entries in their respective manifest list implementations

class image.manifestlistentry.ContainerImageManifestListEntry(entry: Dict[str, Any])

Bases: object

Represents a manifest list entry in a manifest list response from the distribution registry API. This is a base class extended by the ContainerImageManifestListEntryV2S2 and ContainerImageIndexEntryOCI classes since the two specs are very similar, with the v2s2 spec being more restrictive than the OCI spec.

get_digest() str

Returns the entry digest, validates the digest in the process

Returns:

The entry digest

Return type:

str

get_media_type() str

Returns the entry mediaType

Returns:

The entry mediaType

Return type:

str

get_platform() Type[ContainerImagePlatform]

Returns the entry platform metadata as a ContainerImagePlatform

Returns:

The platform metadata

Return type:

Type[ContainerImagePlatform]

get_size() int

Returns the entry size in bytes

Returns:

The entry size in bytes

Return type:

int

image.manifestschema module

Contains various JSON schema constants which together form the overarching container image manifest schema

image.manifestschema.IMAGE_INDEX_ENTRY_PLATFORM_SCHEMA

The JSON schema for validating OCI image index entry platforms Ref: https://github.com/opencontainers/image-spec/blob/v1.0.1/image-index.md

This JSON schema is identical to the v2s2 platform JSON schema for manifest list entries. Hence, we reuse this schema across both v2s2 manifest lists, and OCI image indexes. Ref: https://distribution.github.io/distribution/spec/manifest-v2-2/

image.manifestschema.MANIFEST_DESCRIPTOR_SCHEMA

The JSON schema for validating manifest descriptors Ref: https://github.com/opencontainers/image-spec/blob/v1.0.1/descriptor.md

This JSON schema is a superset of the v2s2 config & layer schemas, which are effectively just descriptors. Hence, we reuse this schema across both v2s2 layers / configs, and OCI descriptors Ref: https://distribution.github.io/distribution/spec/manifest-v2-2/

image.mediatypes module

Contains various mediaType constants across the OCI, docker v2s2, and docker v2s1 specifications

image.mediatypes.DOCKER_V2S1_MEDIA_TYPE = 'application/vnd.docker.distribution.manifest.v1+json'

The mediaType for an unsigned docker v2s1 manifest

image.mediatypes.DOCKER_V2S1_SIGNED_MEDIA_TYPE = 'application/vnd.docker.distribution.manifest.v1+prettyjws'

The mediaType for a signed docker v2s1 manifest

image.mediatypes.DOCKER_V2S2_LIST_MEDIA_TYPE = 'application/vnd.docker.distribution.manifest.list.v2+json'

The mediaType for a docker v2s2 manifest list, also known as a multi-arch image

image.mediatypes.DOCKER_V2S2_MEDIA_TYPE = 'application/vnd.docker.distribution.manifest.v2+json'

The mediaType for a docker v2s2 manifest

image.mediatypes.OCI_INDEX_MEDIA_TYPE = 'application/vnd.oci.image.index.v1+json'

The mediaType for an OCI image index, also known as a multi-arch image

image.mediatypes.OCI_MANIFEST_MEDIA_TYPE = 'application/vnd.oci.image.manifest.v1+json'

The mediaType for an OCI manifest

image.oci module

Contains OCI-specific implementations of the container image manifest, manifest list entry, and manifest list classes

class image.oci.ContainerImageIndexEntryOCI(entry: Dict[str, Any])

Bases: ContainerImageManifestListEntry

static from_manifest_list_entry(entry: ContainerImageManifestListEntry)

Converts a generic ContainerImageManifestListEntry into an OCI image index entry

Parameters:

entry (ContainerImageManifestListEntry) – The generic entry

Returns:

The OCI image index entry

Return type:

ContainerImageIndexEntryOCI

validate() Tuple[bool, str]

Validates an image index entry instance

Returns:

Whether the index entry is valid, error msg

Return type:

Tuple[bool, str]

static validate_static(entry: Dict[str, Any]) Tuple[bool, str]

Validates an image index entry

Parameters:

entry (Dict[str, Any]) – The index entry to validate

Returns:

Whether the index entry is valid, error msg

Return type:

Tuple[bool, str]

class image.oci.ContainerImageIndexOCI(index: Dict[str, Any])

Bases: ContainerImageManifestList

static from_manifest_list(manifest_list: ContainerImageManifestList) ContainerImageIndexOCI

Convert a ContainerImageManifestList to an OCI image index instance

Parameters:

manifest_list (ContainerImageManifestList) – The generic manifest list instance

Returns:

The OCI image index instance

Return type:

ContainerImageIndexOCI

get_oci_entries() List[ContainerImageIndexEntryOCI]

Returns the manifest list entries as ContainerImageIndexEntryOCI instances

Returns:

The entries

Return type:

List[ContainerImageIndexEntryOCI]

get_oci_manifests(name: str, auth: Dict[str, Any]) List[ContainerImageManifestOCI]

Fetches the arch manifests from the distribution registry API and returns as a list of ContainerImageManifestOCI instances

Parameters:
  • name (str) – A valid image name, the name of the manifest

  • auth (Dict[str, Any]) – A valid docker config JSON dict

Returns:

The arch manifests

Return type:

List[ContainerImageManifestOCI]

validate() Tuple[bool, str]

Validates an OCI image index instance

Returns:

Whether the image index is valid, error message

Return type:

Tuple[bool, str]

static validate_static(manifest_list: Dict[str, Any]) Tuple[bool, str]

Validates an OCI image index

Parameters:

manifest_list (Dict[str, Any]) – The image index to validate

Returns:

Whether the image index valid, error message

Return type:

Tuple[bool, str]

class image.oci.ContainerImageManifestOCI(manifest: Dict[str, Any])

Bases: ContainerImageManifest

Represents an arch manifest returned from the distribution registry API. Contains validation logic and getters for manifest metadata following the manifest OCI specification.

static from_manifest(manifest: ContainerImageManifest)

Converts a generic ContainerImageManifest into an OCI manifst instance

Parameters:

manifest (ContainerImageManifest) – The generic manifest

Returns:

The OCI manifest instance

Return type:

ContainerImageManifestOCI

validate() Tuple[bool, str]

Validates an image manifest instance

Returns:

Whether the manifest is valid, error message

Return type:

Tuple[bool, str]

static validate_static(manifest: Dict[str, Any]) Tuple[bool, str]

Validates an image manifest

Parameters:

manifest (Dict[str, Any]) – The manifest to validate

Returns:

Whether the manifest is valid, error message

Return type:

Tuple[bool, str]

image.oci.UNSUPPORTED_OCI_INDEX_MEDIA_TYPES = ['application/vnd.docker.distribution.manifest.list.v2+json']

A list of mediaTypes which are not supported by the OCI image index spec. This mainly just includes the Docker v2s2 manifest list mediaType.

image.oci.UNSUPPORTED_OCI_MANIFEST_MEDIA_TYPES = ['application/vnd.docker.distribution.manifest.v2+json']

A list of mediaTypes which are not supported by the OCI manifest spec. This mainly just includes the Docker v2s2 manifest mediaType.

image.ocischema module

Contains OCI-specific JSON schema constants for OCI image indices, index entries, and manifests

image.ocischema.IMAGE_INDEX_ENTRY_OCI_SCHEMA

The JSON schema for validating OCI image index entries Ref: https://github.com/opencontainers/image-spec/blob/v1.0.1/image-index.md

image.ocischema.IMAGE_INDEX_OCI_SCHEMA

The JSON schema for validating OCI image indexes Ref: https://github.com/opencontainers/image-spec/blob/v1.0.1/image-index.md

image.ocischema.MANIFEST_OCI_SCHEMA

The JSON schema for validating OCI manifests Ref: https://github.com/opencontainers/image-spec/blob/v1.0.1/manifest.md

image.platform module

Contains the ContainerImagePlatform class which represents the OS, architecture, and optionally the variant on which the container image is built to run

class image.platform.ContainerImagePlatform(platform: Dict[str, Any])

Bases: object

Represents platform metadata, which is generally specified in an OCI image index / v2s2 manifest list entry. Contains validation logic and getters for platform metadata following the OCI and v2s2 specifications.

Note that the OCI and v2s2 specifications do not diverge in their schema for platform metadata, hence we reuse this class across both scenarios.

get_architecture() str

Returns the platform’s architecture

Returns:

The platform architecture

Return type:

str

get_features() List[str] | None

Returns the platform’s features, None if not found

Returns:

The features list, None if not found

Return type:

Union[List[str], None]

static get_host_platform() ContainerImagePlatform

Get the platform of the host machine

Returns:

The host machine platform

Return type:

ContainerImagePlatform

get_os() str

Returns the platform’s operating system name

Returns:

The platform operating system name

Return type:

str

get_os_features() List[str] | None

Returns the platform’s operating system features, None if not found

Returns:

The os features list, None if not found

Return type:

Union[List[str], None]

get_os_version() str | None

Returns the platform’s operating system version, None if not found

Returns:

The platform os version, None if not found

Return type:

Union[str, None]

get_variant() str | None

Returns the platform’s variant, None if not found

Returns:

The platform variant, None if not found

Return type:

Union[str, None]

validate() Tuple[bool, str]

Validates a ContainerImagePlatform instance

Returns:

Whether platform metadata is valid, error message

Return type:

Tuple[bool, str]

static validate_static(platform: Dict[str, Any]) Tuple[bool, str]

Validates image platform metadata from an image index entry

Parameters:

platform (Dict[str, Any]) – The platform metadata to validate

Returns:

Whether the platform metadata is valid, error msg

Return type:

Tuple[bool, str]

image.platform.PLATFORM_ARCHITECTURE_MAP = {'aarch64': 'arm64', 'amd64': 'amd64', 'arm64': 'arm64', 'armv6l': 'arm', 'armv7l': 'arm', 'i386': '386', 'i686': '386', 'x86_64': 'amd64'}

A map used to transform the output of the platform.machine method such that it matches the expected value of GoLang’s GOARCH environment variable

image.reference module

Contains the ContainerImageReference class, which can validate and parse references to container images in remote registries

class image.reference.ContainerImageReference(ref: str)

Bases: object

Represents a container image reference. Contains logic for validating and parsing container image references.

get_identifier() str

Gets the image identifier, which can be either a tag or a digest, based on whether the image is a tag or digest ref

Returns:

The image identifier, either a tag or digest

Return type:

str

get_name() str

Gets the image name, which is the image registry and path but without an identifier (tag or digest)

Returns:

The image name

Return type:

str

get_path() str

Gets the image path from the image name. This is the path only, with no inclusion of the registry domain.

Returns:

The image path

Return type:

str

get_registry() str

Gets the image registry domain from the image reference

Returns:

The image registry domain

Return type:

str

get_short_name() str

Gets the image short name, which is the component of the image name following the final forward slash. For example, for image name “ingress-nginx/controller”, the image short name is just “controller”

Returns:

The image short name

Return type:

str

is_digest_ref() bool

Determines if the image reference is a digest reference

Returns:

Whether the image is a digest reference

Return type:

bool

is_tag_ref() bool

Determine if the image reference is a tag reference

Returns:

Whether the image is a tag referenece

Return type:

bool

validate() bool

Validates an image reference

Returns:

Whether the ContainerImage’s reference is valid

Return type:

bool

static validate_static(ref: str) Tuple[bool, str]

Validates an image reference

Parameters:

ref (str) – The image reference

Returns:

Whether the reference is valid, error message

Return type:

Tuple[bool, str]

image.regex module

Regex patterns used for validating container image references, ported to python from official containers/image go module.

Ref: https://github.com/containers/image/blob/main/docker/reference/regexp.go

image.regex.ALPHA_NUMERIC = '[a-z0-9]+'

Defines the alpha numeric atom, typically a component of names. This only allows lower case characters and digits.

Ported to python from official containers/image go module

Ref: https://github.com/containers/image/blob/main/docker/reference/regexp.go

image.regex.ANCHORED_DIGEST = '^[A-Za-z][A-Za-z0-9]*(?:[-_+.][A-Za-z][A-Za-z0-9]*)*:[0-9a-fA-F]{32,}$'

Matches valid digests, anchored at the start and end of the matched string.

image.regex.ANCHORED_DOMAIN = '^(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])(?:(?:\\.(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]))+)?(?::[0-9]+)?$'

Matches valid domains, anchored at the start and end of the matched string.

image.regex.ANCHORED_NAME = '^(?:((?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])(?:(?:\\.(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]))+)?(?::[0-9]+)?)/)?([a-z0-9]+(?:(?:(?:[._]|__|[-]*)[a-z0-9]+)+)?(?:(?:/[a-z0-9]+(?:(?:(?:[._]|__|[-]*)[a-z0-9]+)+)?)+)?)$'

Used to parse a name value, capturing the domain and trailing components.

image.regex.ANCHORED_TAG = '^[\\w][\\w.-]{0,127}$'

Matches valid tag names, anchored at the start and end of the matched string.

image.regex.DIGEST_PAT = '[A-Za-z][A-Za-z0-9]*(?:[-_+.][A-Za-z][A-Za-z0-9]*)*:[0-9a-fA-F]{32,}'

The string counterpart for DIGEST_REGEXP.

image.regex.DOMAIN = '(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])(?:(?:\\.(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]))+)?(?::[0-9]+)?'

Defines the structure of potential domain components that may be part of image names. This is purposely a subset of what is allowed by DNS to ensure backwards compatibility with Docker image names.

image.regex.DOMAIN_COMPONENT = '(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])'

Repository name to start with a component as defined by DOMAIN and followed by an optional port.

image.regex.IDENTIFIER = '([a-f0-9]{64})'

The string counterpart for IDENTIFIER_REGEXP.

image.regex.NAME_COMPONENT = '[a-z0-9]+(?:(?:(?:[._]|__|[-]*)[a-z0-9]+)+)?'

Restricts registry path component names to start with at least one letter or number, with following parts able to be separated by one period, one or two underscore and multiple dashes.

image.regex.NAME_PAT = '(?:(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])(?:(?:\\.(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]))+)?(?::[0-9]+)?/)?[a-z0-9]+(?:(?:(?:[._]|__|[-]*)[a-z0-9]+)+)?(?:(?:/[a-z0-9]+(?:(?:(?:[._]|__|[-]*)[a-z0-9]+)+)?)+)?'

The format for the name component of references. The regexp has capturing groups for the domain and name part omitting the separating forward slash from either.

image.regex.REFERENCE_PAT = '^((?:(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])(?:(?:\\.(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]))+)?(?::[0-9]+)?/)?[a-z0-9]+(?:(?:(?:[._]|__|[-]*)[a-z0-9]+)+)?(?:(?:/[a-z0-9]+(?:(?:(?:[._]|__|[-]*)[a-z0-9]+)+)?)+)?)(?::([\\w][\\w.-]{0,127}))?(?:@([A-Za-z][A-Za-z0-9]*(?:[-_+.][A-Za-z][A-Za-z0-9]*)*:[0-9a-fA-F]{32,}))?$'

The full supported format of a reference. The regexp is anchored and has capturing groups for name, tag, and digest components.

image.regex.SEPARATOR = '(?:[._]|__|[-]*)'

Defines the separators allowed to be embedded in name components. This allows one period, one or two underscore and multiple dashes. Repeated dashes and underscores are intentionally treated differently. In order to support valid hostnames as name components, supporting repeated dash was added. Additionally double underscore is now allowed as a separator to loosen the restriction for previously supported names.

image.regex.SHORT_IDENTIFIER = '([a-f0-9]{6,64})'

The string counterpart for SHORT_IDENTIFIER_REGEXP.

image.regex.TAG_PAT = '[\\w][\\w.-]{0,127}'

Matches valid tag names. From the docker/docker library’s graph/tags.go source file

image.regex.anchored(res: List[str]) str

Anchors the regular expression by adding start and end delimiters.

Parameters:

res (List[str]) – The regular expressions to anchor

Returns:

The anchored regular expression

Return type:

str

image.regex.capture(res: List[str]) str

Wraps the expression in a capturing group.

Parameters:

res (List[str]) – The regular expressions to capture

Returns:

The captured regular expressions

Return type:

str

image.regex.expression(res: List[str]) str

Defines a full expression, where each regular expression must follow the previous

Parameters:

res (List[str]) – The regular expressions to combine

Returns:

The combined regular expressions

Return type:

str

image.regex.group(res: List[str]) str

Wraps the regexp in a non-capturing group.

Parameters:

res (List[str]) – The regular expressions to group

Returns:

The grouped regular expressions

Return type:

str

image.regex.literal(s: str) str

Compiles s into a literal regular expression, escaping any regexp reserved characters

Parameters:

s (str) – The literal to convert to a regular expression

Returns:

The converted regular expression literal

Return type:

str

image.regex.optional(res: List[str]) str

Wraps the expression in a non-capturing group and makes the production optional

Parameters:

res (List[str]) – The regular expressions to make optional

Returns:

The regular expressions made optional

Return type:

str

image.regex.repeated(res: List[str]) str

Wraps the regexp in a non-capturing group to get one or more matches

Parameters:

res (List[str]) – The regular expressions to repeat

Returns:

The repeated regular expressions

Return type:

str

image.v2s2 module

Contains docker v2s2-specific implementations of the container image manifest, manifest list entry, and manifest list classes

class image.v2s2.ContainerImageManifestListEntryV2S2(entry: Dict[str, Any])

Bases: ContainerImageManifestListEntry

static from_manifest_list_entry(entry: ContainerImageManifestListEntry)

Convert a ContainerImageManifestListEntry to a v2s2 manifest list entry instance

Parameters:

manifest_list (ContainerImageManifestList) – The generic manifest list entry instance

Returns:

The v2s2 manifest list entry instance

Return type:

ContainerImageManifestListEntryV2S2

validate() Tuple[bool, str]

Validates an image manifest list entry instance

Returns:

Whether the manifest list entry is valid, error msg

Return type:

Tuple[bool, str]

static validate_static(entry: Dict[str, Any]) Tuple[bool, str]

Validates an image manifest list entry

Parameters:

entry (Dict[str, Any]) – The manifest list entry to validate

Returns:

Whether the manifest list entry is valid, error msg

Return type:

Tuple[bool, str]

class image.v2s2.ContainerImageManifestListV2S2(manifest_list: Dict[str, Any])

Bases: ContainerImageManifestList

static from_manifest_list(manifest_list: ContainerImageManifestList) ContainerImageManifestListV2S2

Convert a ContainerImageManifestList to a v2s2 manifest list instance

Parameters:

ContainerImageManifestList (manifest_list) – The generic manifest list instance

Returns:

The v2s2 manifest list instance

Return type:

ContainerImageManifestListV2S2

get_v2s2_entries() List[ContainerImageManifestListEntryV2S2]

Returns the manifest list entries as ContainerImageManifestListEntryV2S2 instances

Returns:

The entries

Return type:

List[ContainerImageManifestListEntryV2S2]

get_v2s2_manifests(name: str, auth: Dict[str, Any]) List[ContainerImageManifestV2S2]

Fetches the arch manifests from the distribution registry API and returns as a list of ContainerImageManifestV2S2s

Parameters:
  • name (str) – A valid image name, the name of the manifest

  • auth (Dict[str, Any]) – A valid docker config JSON dict

Returns:

The arch manifests

Return type:

List[ContainerImageManifestV2S2]

validate() Tuple[bool, str]

Validates an image manifest list instance

Returns:

Whether the manifest list is valid, error message

Return type:

Tuple[bool, str]

static validate_static(manifest_list: Dict[str, Any]) Tuple[bool, str]

Validates an image manifest list

Parameters:

manifest_list (Dict[str, Any]) – The manifest list to validate

Returns:

Whether the manifest list is valid, error message

Return type:

Tuple[bool, str]

class image.v2s2.ContainerImageManifestV2S2(manifest: Dict[str, Any])

Bases: ContainerImageManifest

static from_manifest(manifest: ContainerImageManifest)

Convert a ContainerImageManifest to a v2s2 manifest instance

Parameters:

manifest_list (ContainerImageManifest) – The generic manifest instance

Returns:

The v2s2 manifest instance

Return type:

ContainerImageManifestV2S2

validate() Tuple[bool, str]

Validates an image manifest instance

Returns:

Whether the manifest is valid, error message

Return type:

Tuple[bool, str]

static validate_static(manifest: Dict[str, Any]) Tuple[bool, str]

Validates an image manifest

Parameters:

manifest (Dict[str, Any]) – The manifest to validate

Returns:

Whether the manifest is valid, error message

Return type:

Tuple[bool, str]

image.v2s2.UNSUPPORTED_V2S2_MANIFEST_LIST_MEDIA_TYPES = ['application/vnd.oci.image.index.v1+json']

A list of mediaTypes which are not supported by the v2s2 manifest list spec. This mainly just includes the OCI index mediaType.

image.v2s2.UNSUPPORTED_V2S2_MANIFEST_MEDIA_TYPES = ['application/vnd.oci.image.manifest.v1+json']

A list of mediaTypes which are not supported by the v2s2 manifest spec. This mainly just includes the OCI manifest mediaType.

image.v2s2schema module

Contains docker v2s2-specific JSON schema constants for v2s2 manifests, manifest list entries, and manifest lists

image.v2s2schema.MANIFEST_LIST_V2_ENTRY_SCHEMA

The JSON schema for validating v2s2 manifest lists Ref: https://distribution.github.io/distribution/spec/manifest-v2-2/

image.v2s2schema.MANIFEST_LIST_V2_SCHEMA

The JSON schema for validaing v2s2 manifests Ref: https://distribution.github.io/distribution/spec/manifest-v2-2/

Module contents