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.8

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.8
File Size Uploaded Provenance Actions
pywhales-1.0.8.tar.gz 348.2 kB Without provenance Details for pywhales-1.0.8.tar.gz

Built distribution (wheel)

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

Total release size: 652.5 kB

Release files / pywhales-1.0.8.tar.gz

Download URL pywhales-1.0.8.tar.gz
Size 348.2 kB
Tags Source
SHA-256 checksum
How to use checksums
eaabdba3cae87c3e33c6eabc4e04e59f8bc6e7fbfe5a4aa55835f18f5c4571e4
BLAKE2b-256 checksum
How to use checksums
d787d309a74da4f5a46dac0b233adc22edf6c356bbe2a4c1b042d928ce6b4e3c
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.8-py3-none-any.whl

Download URL pywhales-1.0.8-py3-none-any.whl
Size 304.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0034bd16f276261880fb1b5723ba907885bdc11fb89ad96de94a6e565c98e021
BLAKE2b-256 checksum
How to use checksums
59fe7ede450816294006664b1e59063c5a3b94da932882bcb341b4dd03d0cb8f
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.8

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