PyWhales
The Docker and its composer client for Python, designed to be fun and intuitive!
Works on Linux, macOS and Windows, for Python 3.14.10 and above.
How to install?
uv pip install pywhales
See the Docker CLI guide for instructions on installing Docker.
Some cool examples
Start by doing
from pywhales import docker
and then:
docker run hello-world->docker.run("hello-world")docker pull ubuntu->docker.pull("ubuntu")docker build ./->docker.build("./")docker compose up my_service->docker.compose.up(["my_service"])docker image ls->docker.image.list()docker ps->docker.ps()docker cp->docker.copy()
>>> from pywhales import docker
>>> output = docker.run("hello-world")
>>> print(output)
Hello from Docker!
This message shows that your installation appears to be working correctly.
...
>>> from pywhales import docker
>>> my_image = docker.build(".", tags="some_name") # uses Buildx/buildkit by default
[+] Building 1.6s (17/17) FINISHED
...
Some more docker.run() advanced examples with postgres
docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
becomes
from pywhales import docker
docker.run(
"postgres:9.6",
name="some-postgres",
envs={"POSTGRES_PASSWORD": "mysecretpassword"},
detach=True,
)
print(docker.ps())
# [pywhales.Container(id='f5fb939c409d', name='some-postgres')]
docker run -it --rm --network some-network postgres psql -h some-postgres -U postgres
becomes
from pywhales import docker
# since it's interactive, you'll be dropped into the psql shell. The python code
# will continue only after you exit the shell.
docker.run(
"postgres:9.6",
["psql", "-h", "some-postgres", "-U", "postgres"],
networks=["some-network"],
interactive=True,
tty=True,
remove=True,
)
docker run -d --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -e PGDATA=/var/lib/postgresql/data/pgdata -v /custom/mount:/var/lib/postgresql/data -v myvolume:/tmp/myvolume postgres -c shared_buffers=256MB -c max_connections=200
becomes
from pywhales import docker
docker.run(
"postgres:9.6",
["-c", "shared_buffers=256MB", "-c", "max_connections=200"],
name="some-postgres",
envs={
"POSTGRES_PASSWORD": "mysecretpassword",
"PGDATA": "/var/lib/postgresql/data/pgdata",
},
volumes=[
("/custom/mount", "/var/lib/postgresql/data"),
("myvolume", "/tmp/myvolume"),
],
detach=True,
)
Any Docker object can be used as a context manager to ensure it's removed even if an exception occurs:
from pywhales import docker
with docker.volume.create("random_name") as some_volume:
docker.run(
"postgres:9.6",
["-c", "shared_buffers=256MB", "-c", "max_connections=200"],
name="some-postgres",
envs={
"POSTGRES_PASSWORD": "mysecretpassword",
"PGDATA": "/var/lib/postgresql/data/pgdata",
},
volumes=[
(some_volume, "/var/lib/postgresql/data"),
("myvolume", "/tmp/myvolume"),
],
detach=True,
)
# so some stuff here
# here we are out of the context manager, so the volume has been removed, even if there was an exception.
Main features
- 1 to 1 mapping between the CLI interface and the Python API. No need to look in the docs what is the name of the function/argument you need.
- Support for the latest Docker features:
Docker buildx/buildkit,
docker run --gpu=all ... - Support for Docker stack, services and Swarm (same API as the command line).
- Progress bars and progressive outputs when pulling, pushing, loading, building...
- Support for some other CLI commands that are not in Docker-py:
docker cp,docker run --cpus ...and more. - Nice SSH support for remote daemons.
- Docker object as Python objects: Container, Images, Volumes, Services... and their attributes are updated in real-time!
- Each Docker object can be used as a context manager. When getting out of the context, the Docker object is removed automatically, even if an exception occurs.
- A fully typed API (ty and IDE-friendly) compatible with
pathlibandos.path - All Docker objects and the Docker client are safe to use with multithreading and multiprocessing.
- Enable execution diagnostics by setting
PYWHALES_DEBUG=1. Diagnostics omit command arguments, environment values, and captured output by default. UseDockerClient(raw_diagnostics=True)only when detailed diagnostics are appropriate for that client's logs. Only the exact value1enables debug output.
What about the license?
It's a MIT license, so quite permissive.
The license can be found in the git repository.
Metadata
Release files for pywhales 0.6.5
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 | Actions |
|---|---|---|---|---|
| pywhales-0.6.5.tar.gz | 282.3 kB | Without provenance | Details for pywhales-0.6.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pywhales-0.6.5-py3-none-any.whl | Python 3 | none | any | Details for pywhales-0.6.5-py3-none-any.whl |
Total release size: 532.6 kB
Release files / pywhales-0.6.5.tar.gz
| Download URL | pywhales-0.6.5.tar.gz |
|---|---|
| Size | 282.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5f54b1ae26229547640b01d0f87af80656a9e0f459f489866cb43ff92921a4e4
|
|
BLAKE2b-256 checksum How to use checksums |
c12eeb449fa8f1ef44868765d4527e710e5971ed22a494c7d78305bfd3eb1928
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / pywhales-0.6.5-py3-none-any.whl
| Download URL | pywhales-0.6.5-py3-none-any.whl |
|---|---|
| Size | 250.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6f3af9acd6c508f5ff8492cc847e22a5bce37a7545095af527574346a9eaa0f7
|
|
BLAKE2b-256 checksum How to use checksums |
8e0800ff869e290d067d66e04af93fc4c31ebd6e7420d761d998f5501ccf6084
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for pywhales 0.6.5
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.