Python DXF (Docker Registry Client)

12.1.1 · active · verified Thu Apr 16

python-dxf is a Python module and command-line tool for storing and retrieving data in a Docker v2 registry. It functions as a Docker registry v2 client, enabling tasks like transferring Docker images between registries, especially useful for disconnected environments. The library creates payloads directly from the registry, which can be faster than `docker save` and `docker load`, and can compute diffs to reduce transfer size. The current version is 12.1.1 and it appears to be actively maintained.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `Dxf` client for a Docker registry, using environment variables for configuration. It shows the basic connection pattern. Actual registry operations (like listing repositories, pushing/pulling blobs or manifests) require specific API calls which might vary depending on the exact version and intended functionality. Ensure environment variables like `DXF_HOST`, `DXF_USERNAME`, and `DXF_PASSWORD` are set for authentication and host connection.

import os
from dxf import Dxf

# Configure registry connection via environment variables or direct arguments
# DXF_HOST, DXF_USERNAME, DXF_PASSWORD, DXF_INSECURE, etc.

host = os.environ.get('DXF_HOST', 'registry.example.com')
username = os.environ.get('DXF_USERNAME', '')
password = os.environ.get('DXF_PASSWORD', '')
insecure = os.environ.get('DXF_INSECURE', '0') == '1'

try:
    # Connect to the registry
    # In a real scenario, handle credentials securely (e.g., from a vault)
    client = Dxf(host, username=username, password=password, insecure=insecure)
    print(f"Connected to registry: {host}")

    # Example: List repositories (requires appropriate permissions)
    # NOTE: Dxf API might not directly expose 'list_repositories' in all versions,
    # this is a conceptual example based on its registry client nature.
    # Refer to the official library documentation for exact API calls.
    # if hasattr(client, 'list_repositories'): # Illustrative, actual method names vary
    #     repositories = client.list_repositories()
    #     print(f"Repositories: {repositories}")
    # else:
    #     print("Method to list repositories not found or not directly exposed by Dxf object.")

    # More likely usage involves specific image/layer operations, e.g.:
    # blob_digest = client.push_blob('my-repo/my-image', 'sha256:...')
    # manifest = client.get_manifest('my-repo/my-image', 'latest')
    print("Dxf client initialized. You can now perform registry operations.")

except Exception as e:
    print(f"Failed to connect or perform operation: {e}")

view raw JSON →