Skip to main content

Use docker-compose (V2) from within Python

Project description

Docker Composer

A library to interact with docker-compose V2 from a python Program. All commands and parameters are exposed as python classes and attributes to allow for full auto-completion of its parameters with IDEs that support it.

Runtime footprint: This library is stdlib-only (zero third-party runtime dependencies).

Install

pip install docker-composer

Usage

The main class is docker_composer.DockerCompose. Its parameters are all options from docker-compose.

Each docker-compose command has a corresponding function, e.g. DockerCompose.run or DockerCompose.scale. Their arguments again mirror the options of the corresponding command.

The resulting object has a call function. It takes arbitrary strings as input, as well as all keyword arguments from subprocess.run, and returns a subprocess.CompletedProcess

from docker_composer import DockerCompose


base = DockerCompose(file="docker-compose.yml", verbose=True)
base.run(detach=True, workdir="/tmp").call("app")
base.run(workdir="/tmp").call("app", "/bin/bash", "-l")

# /tmp $ ls /.dockerenv
# /.dockerenv
# /tmp $ exit

process = base.ps(all=True).call(capture_output=True)
print(process.stdout.encode("UTF-8"))
#          Name                      Command           State    Ports
# -------------------------------------------------------------------
# myapp_app_70fd8b786b76   myapp --start-server        Exit 0        
# myapp_app_6ac3db4e1b55   myapp --client              Exit 0   

Develop

Development Setup

The generate extra is maintainer tooling for code generation/formatting and is not required for normal package usage.

uv sync --group dev --extra generate

If you only need the generation tooling, you can install just the extra:

uv sync --extra generate

Coding Standards

Type Package Comment
Linter ruff Also for auto-formatted modules
Logging logging
Packaging uv
Tests pytest
Typing mypy Type all methods
Imports ruff

Project details


Download files

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

Source Distribution

docker_composer-5.1.3.tar.gz (26.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

docker_composer-5.1.3-py3-none-any.whl (41.6 kB view details)

Uploaded Python 3

File details

Details for the file docker_composer-5.1.3.tar.gz.

File metadata

  • Download URL: docker_composer-5.1.3.tar.gz
  • Upload date:
  • Size: 26.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for docker_composer-5.1.3.tar.gz
Algorithm Hash digest
SHA256 01c178fb67673cf7d6dbc92773cc62c1d3c35cc77a3f46bbc5b42737abb7c1bb
MD5 ec012bd6aaab31ef260e0184f8b5314c
BLAKE2b-256 c81a3b53f18ce67487ec30c96a7f8f1f21a9bf80ac3ffc0632aa7286fb686598

See more details on using hashes here.

Provenance

The following attestation bundles were made for docker_composer-5.1.3.tar.gz:

Publisher: python.yml on schollm/docker-composer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file docker_composer-5.1.3-py3-none-any.whl.

File metadata

  • Download URL: docker_composer-5.1.3-py3-none-any.whl
  • Upload date:
  • Size: 41.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for docker_composer-5.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 890c32591086abd55122ea2aa309085e6c6ddd2645cc2b24adbc41a575f1bebd
MD5 7138603aa8438a3d9995affa5d187fed
BLAKE2b-256 c70745fbd520e5c3c88bf1e3d5f1b8281ae264867952fa4df82370998f1b1588

See more details on using hashes here.

Provenance

The following attestation bundles were made for docker_composer-5.1.3-py3-none-any.whl:

Publisher: python.yml on schollm/docker-composer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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