Skip to main content

No project description provided

Project description

logo

A Docker client for Python, designed to be fun and intuivive!

Works on Linux, MacOS and Windows, for Python 3.7 and above.

The docs can be found at this address: https://gabrieldemarmiesse.github.io/python-on-whales/

The Github repo can be found at this adress: https://github.com/gabrieldemarmiesse/python-on-whales

How to install?

I have put several hundred of hours of work into this project, because I love Docker and
I hope to make it fun to use from Python.

I will likely put several hundred of hours more into Python-on-whales for bugfixes, maintenance and new features!

The 01/05/2021, the source code will be available at https://github.com/gabrieldemarmiesse/python-on-whales with a MIT licence and the packages will be available with pip install python-on-whales

Until May 1st 2021, this package is accessible only by sponsors:

  1. Go to https://github.com/sponsors/gabrieldemarmiesse

  2. Pick any tier

  3. I'll send you and invitation to access the repository at https://github.com/gabrieldemarmiesse/python-on-whales (one hour max, there is no API in Github for sponsors, I can't automate it).

  4. Do either pip install git+ssh://git@github.com/gabrieldemarmiesse/python-on-whales.git or if you use a requirements.txt or a setup.py, you can declare Python on whales as a dependency with

# setup.py

from setuptools import find_packages, setup

setup(
    name="my-package",
    install_requires=["python-on-whales @ git+ssh://git@github.com/gabrieldemarmiesse/python-on-whales.git"],
    packages=find_packages(),
)
# requirements.txt
python-on-whales @ git+ssh://git@github.com/gabrieldemarmiesse/python-on-whales.git
other-package-1
other-package-2
...

Some cool examples

>>> from python_on_whales import docker

>>> output = docker.run("hello-world")
>>> print(output)

Hello from Docker!
This message shows that your installation appears to be working correctly.

...
>>> from python_on_whales import docker
>>> print(docker.run("nvidia/cuda:11.0-base", ["nvidia-smi"], gpus="all"))
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 450.51.06    Driver Version: 450.51.06    CUDA Version: 11.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  Tesla T4            On   | 00000000:00:1E.0 Off |                    0 |
| N/A   34C    P8     9W /  70W |      0MiB / 15109MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+
>>> from python_on_whales import docker
>>> my_docker_image = docker.pull("ubuntu:20.04")
20.04: Pulling from library/ubuntu
e6ca3592b144: Downloading [=============>                                     ]  7.965MB/28.56MB
534a5505201d: Download complete
990916bd23bb: Download complete

>>> print(my_docker_image.repo_tags)
['ubuntu:20.04']

>>> my_docker_image.remove()
>>> from python_on_whales import docker
>>> my_image = docker.build(".", tags="some_name")  # uses Buildx/buildkit by default
[+] Building 1.6s (17/17) FINISHED
 => [internal] load build definition from Dockerfile                                                            0.0s
 => => transferring dockerfile: 32B                                                                             0.0s
 => [internal] load .dockerignore                                                                               0.0s
 => => transferring context: 2B                                                                                 0.0s
 => [internal] load metadata for docker.io/library/python:3.6                                                   1.4s
 => [python_dependencies 1/5] FROM docker.io/library/python:3.6@sha256:29328c59adb9ee6acc7bea8eb86d0cb14033c85  0.0s
 => [internal] load build context                                                                               0.1s
 => => transferring context: 72.86kB                                                                            0.0s
 => CACHED [python_dependencies 2/5] RUN pip install typeguard pydantic requests tqdm                           0.0s
 => CACHED [python_dependencies 3/5] COPY tests/test-requirements.txt /tmp/                                     0.0s
 => CACHED [python_dependencies 4/5] COPY requirements.txt /tmp/                                                0.0s
 => CACHED [python_dependencies 5/5] RUN pip install -r /tmp/test-requirements.txt -r /tmp/requirements.txt     0.0s
 => CACHED [tests_ubuntu_install_without_buildx 1/7] RUN apt-get update &&     apt-get install -y       apt-tr  0.0s
 => CACHED [tests_ubuntu_install_without_buildx 2/7] RUN curl -fsSL https://download.docker.com/linux/ubuntu/g  0.0s
 => CACHED [tests_ubuntu_install_without_buildx 3/7] RUN add-apt-repository    "deb [arch=amd64] https://downl  0.0s
 => CACHED [tests_ubuntu_install_without_buildx 4/7] RUN  apt-get update &&      apt-get install -y docker-ce-  0.0s
 => CACHED [tests_ubuntu_install_without_buildx 5/7] WORKDIR /python-on-whales                                  0.0s
 => CACHED [tests_ubuntu_install_without_buildx 6/7] COPY . .                                                   0.0s
 => CACHED [tests_ubuntu_install_without_buildx 7/7] RUN pip install -e .                                       0.0s
 => exporting to image                                                                                          0.1s
 => => exporting layers                                                                                         0.0s
 => => writing image sha256:e1c2382d515b097ebdac4ed189012ca3b34ab6be65ba0c650421ebcac8b70a4d                    0.0s
 => => naming to docker.io/library/some_image_name

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 (Mypy and IDE-friendly) compatible with pathlib and os.path

Why another project? Why not build on Docker-py?

In a sense this project is built on top of Docker-py because the implementation, the organisation and the API is inspired from the project, but the codebases could not be the same.

Two major differences do not permit that:

  1. The API is quite different. The aim of Python on Whales is to provide a 1-to-1 mapping between the Docker command line and Python, so that users don't even have to open the docs to do write code.

  2. While Docker-py is a complete re-implementation of the Docker client binary (written in Go), Python on whales sits on top of the Docker client binary, which makes implementing new features much easier and safer. For example, it's unlikely that docker-py supports Buildx/buildkit anytime soon because rewriting a large Go codebase in Python is hard work.

Where is the project now? Where is it going?

Currently, about 75% of the Docker CLI API is covered. Of course the most used functions were done first: docker run, docker pull, docker push, docker build (with buildx), docker volume...

The main parts missing are Docker swarm support, Docker buildx builders management, and a better inspection of Docker objects like volumes and images (for Docker containers, the inspection is pretty good).

This project aims at a 100% feature parity between the Docker CLI and Python on whales.

This includes Docker buildx, Docker app, Docker Swarm, Docker stacks and Docker compose.

You can consider that this software is in beta, some small API changes are still possible.

Project details


Release history Release notifications | RSS feed

This version

0.3.2

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-on-whales-0.3.2.tar.gz (45.4 kB view details)

Uploaded Source

Built Distribution

python_on_whales-0.3.2-py3-none-any.whl (48.8 kB view details)

Uploaded Python 3

File details

Details for the file python-on-whales-0.3.2.tar.gz.

File metadata

  • Download URL: python-on-whales-0.3.2.tar.gz
  • Upload date:
  • Size: 45.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.9.0

File hashes

Hashes for python-on-whales-0.3.2.tar.gz
Algorithm Hash digest
SHA256 91994524046ff4b36cba3fd21bc6c5fe5cc8fa0724acec72a7949670badd4822
MD5 0def19f11f0d467fb3e84a905cb913f9
BLAKE2b-256 9f7f822a1e2569c3357d81e1f1ba8d26aa9c626e6d1fb2852d284ff0e951ee4c

See more details on using hashes here.

Provenance

File details

Details for the file python_on_whales-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: python_on_whales-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 48.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.9.0

File hashes

Hashes for python_on_whales-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a411841871447f63fe32b419a046f214dd1b1497c5e909c2c72154d904659966
MD5 40686c8e5e565e2ab7db1c6b1652cee2
BLAKE2b-256 eb7782eb33262d2d2d28c4d5c64242bda2cbc1cfb7d4f66cf38852eb8b0770f8

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page