Skip to main content

PyWhales

Run tests PyPI Code style: Ruff Types: ty License: MIT

PyWhales is a typed Python wrapper around the external Docker CLI. It builds docker command lines, runs them as subprocesses, and returns the results as Python objects. It isn't an HTTP SDK and doesn't call the Docker Engine API.

Requirements

  • Python 3.14.10 or newer, on Linux, macOS or Windows.
  • The Docker CLI, installed separately. See the Docker CLI guide.
  • A reachable Docker daemon for commands that talk to it.
  • The Compose and Buildx plugins for the commands that use them (docker.compose, docker.build).

Importing PyWhales or constructing a client doesn't check that the CLI, daemon or plugins are available. Problems show up when a command runs.

Install

uv pip install pywhales

Quickstart

from pywhales import docker

print(docker.run("hello-world", remove=True))
containers = docker.ps()
images = docker.image.list()

Building and Compose need local files: a Dockerfile for build (DockerClient.build is an alias for Buildx) and a Compose file for compose.

image = docker.build(".", tags="my-app:latest", load=True)
docker.compose.up(detach=True)

Custom configuration

docker is a shared default client. Create your own DockerClient to change its settings:

from pywhales import DockerClient

client = DockerClient(
    context="my-context",
    compose_files=["compose.yaml"],
    default_timeout=30,
)

The Docker context must already exist. default_timeout is in seconds and bounds each local CLI launch. Expiry kills and reaps the local CLI process, but doesn't roll back work the daemon has already started.

Good to know

  • Containers, images, volumes and other resources are typed handles. Reading a property may inspect the resource and cache the result briefly. Call reload() when you want a fresh copy.
  • Streaming calls that own a process return iterators. Close them, or use them as context managers, if you stop reading early.
  • PYWHALES_DEBUG=1 turns on execution diagnostics that withhold command arguments, environment values and captured output. DockerClient(raw_diagnostics=True) opts a single client into raw diagnostics, so use it only where its logs are safe to expose.
  • That redaction covers diagnostics only. Returned data, exception attributes and output PyWhales doesn't capture are not redacted.

More documentation

License

PyWhales is released under the MIT license. See LICENSE.

Metadata

Release files for pywhales 1.0.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 pywhales 1.0.0
File Size Uploaded Provenance Actions
pywhales-1.0.0.tar.gz 298.4 kB Without provenance Details for pywhales-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pywhales 1.0.0
File Interpreter ABI Platform Actions
pywhales-1.0.0-py3-none-any.whl Python 3 none any Details for pywhales-1.0.0-py3-none-any.whl

Total release size: 565.2 kB

Release files / pywhales-1.0.0.tar.gz

Download URL pywhales-1.0.0.tar.gz
Size 298.4 kB
Tags Source
SHA-256 checksum
How to use checksums
323d8d9f12d46424f0c21ad7db0bd5cc2d2ae96a4e53c0e506eb917d17ea2d62
BLAKE2b-256 checksum
How to use checksums
40715532a03dcae74937ec40a69516bfe8f16eee9182503f51afdfeaf32730a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / pywhales-1.0.0-py3-none-any.whl

Download URL pywhales-1.0.0-py3-none-any.whl
Size 266.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6ebf4b8b9b8f8e1d4584f1dc64f9d2fde9e11bb4459a8e976f8a77ea5d91ada7
BLAKE2b-256 checksum
How to use checksums
5282ae5397da0cefa65cc6d820a391b74263f93477dbb38a1b04dec40caa7d99
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for pywhales 1.0.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.

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