Skip to main content

A Python tool for formatting Docker Compose YAML files

Project description

composefmt

A Python tool for formatting Docker Compose YAML files. It reorders top-level and service-level keys in a consistent, predefined order while preserving comments, quotes, and structure.

Features

  • Reorders top-level and service-level keys in Docker Compose files
  • Configure key orders and YAML indentation via a TOML config file
  • Preserves comments, quotes, and YAML structure
  • Supports files (glob patterns) and stdin piping
  • Outputs formatted content to stdout or overwrites files in-place
  • Check-mode for verify formatting without modifying files

Requirements

  • Python 3.13+
  • uv (for dependency management and installation)

For a full list of Python dependencies, see uv tree or check pyproject.toml.

Setup

git clone <repository-url>
cd composefmt
uv sync

Installation (Optional)

Install composefmt as a global tool:

uv tool install .
# or
uv tool install composefmt

Configuration (Optional)

Create a config file at $XDG_CONFIG_HOME/composefmt.toml to customize key orders and YAML indentation.
This is optional: If no configuration file exists or config options are omitted, the builtin defaults will be used (see src/composefmt/lib/defaults.py).
YAML keys that are not defined in the configuration will be appended in existing order.

# Custom top-level order
top_level_order = [
    "name",
    "services",
    "networks",
    "volumes",
]

# Custom service-level order
service_order = [
    "image",
    "build",
    "ports",
    "volumes",
    "environment",
]

# Custom YAML indentation
yaml_indent = 4

Usage (multiple ways)

# Format files and overwrite in-place
./src/composefmt/cli.py docker-compose.yml

# Format files and output to stdout
uv run composefmt docker-compose.yml --stdout

# Check if files are formatted (without modifying them)
composefmt docker-compose.yml --check

# Read from stdin (e.g., for piping)
cat docker-compose.yml | composefmt

see --help for further details

Testing

All tests are defined in ./tests/ and can be run via pytest.

Exit Codes

Exit codes are only relevant in check mode (--check).
In all other modes, the script exits with 0.

Code Meaning
0 No files would be changed
1 One or more files need formatting

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

composefmt-0.3.2.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

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

composefmt-0.3.2-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file composefmt-0.3.2.tar.gz.

File metadata

  • Download URL: composefmt-0.3.2.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"EndeavourOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for composefmt-0.3.2.tar.gz
Algorithm Hash digest
SHA256 ae6e48c7b130bf183cca3e0a3700de1c32a5aaf2f64355da4528afbc7f8e94e0
MD5 38f8d553cfcc7111c19d994b94130e8d
BLAKE2b-256 38eb22957066f1f692d357e70d261e87680cb354392559db941953da1a7d8096

See more details on using hashes here.

File details

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

File metadata

  • Download URL: composefmt-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"EndeavourOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for composefmt-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f24b1e498f845668827840277d041204685a8cc9c3d31b839ec3dbbbdcafd1b2
MD5 ef1fb4e95e4a3f7ccae615c8c4be842f
BLAKE2b-256 0198cc068dc74a6e51ea70b386c603736a6a25ef7a59d41dc03357fc5d931492

See more details on using hashes here.

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