Skip to main content

Generate traefik labels easily

Project description


Tool for generating Traefik labels. Written in Python.


Laebelmaker is published on PyPI. You can use pip to install it:

python3 -m pip install --user laebelmaker

It is recommended that you also install the docker module. You can install both Laebelmaker and docker as its dependency with:

python3 -m pip install --user laebelmaker[docker]

This will allow Laebelmaker to use metadata of Docker images to prevent redundant prompts from the user, e.g. when an image exposes a single port.


Laebelmaker can be used to automatically generate Traefik labels from various sources, such as docker-compose.yml files, running Docker containers and user-given options.

You can always consult the help menu for all features with short (and hopefully clear) explanations:

$ laebelmaker
usage: laebelmaker [-h] [-i] [-c NAME] [-f FORMAT] [FILES ...]

Generate Traefik labels

positional arguments:
  FILES                 list of Compose files to generate labels for

  -h, --help            show this help message and exit
  -i, --interactive     use interactive mode
  -c NAME, --container NAME
                        generate labels for a given container on the system
  -f FORMAT, --format FORMAT
                        set output format, one of: [docker, none, yaml]


CLI Interactive Mode

$ laebelmaker -i
Enter value for 'deploy name': myapp
Enter value for 'url':
Enter value for 'port' (integer): 25565
Enter value for 'https redirection' (yes/No): no

With Compose YAML file

Invoking laebelmaker on a Docker Compose YAML file, the program will prompt the user for different options, with the defaults given in parentheses. This example also modifies the output format with -f yaml, which means the labels are immediately ready to be used in a YAML file.

$ laebelmaker -f yaml examples/docker-compose-testapp.yml
Found multiple services.
 1. testapp
 2. testapp-db
Service number to use (default 1): 1
Enter value for 'url':
Enter value for 'https redirection' (yes/No): yes
Enter value for 'web entrypoint': https
Enter value for 'websecure entrypoint': https
Enter value for 'tls resolver': letsencrypt
  - traefik.enable=true
  - traefik.http.routers.testapp.rule=(Host(``) && PathPrefix(`/api`))
  - traefik.http.routers.testapp.entrypoints=https
  - traefik.http.routers.testapp-https.rule=(Host(``) && PathPrefix(`/api`))
  - traefik.http.routers.testapp-https.entrypoints=https
  - traefik.http.routers.testapp.middlewares=testapp-redir
  - traefik.http.middlewares.testapp-redir.redirectscheme.scheme=https
  - traefik.http.routers.testapp-https.tls=true
  - traefik.http.routers.testapp-https.tls.certresolver=letsencrypt

If an invalid file is given, Laebelmaker should hopefully print a sensible error message.

$ laebelmaker examples/invalid-image-tag.yml
Pulling image:
 ⠿ ubuntu:latestest Failed
Invalid image tag: 'ubuntu:latestest' in 'examples/invalid-image-tag.yml'.
Failed to produce output.
Try running: laebelmaker --help


  • Generate Traefik labels using an interactive CLI
  • Generate Traefik labels using command-line options
  • Generate labels from existing service definitions (e.g. Docker Compose YAML files)
  • Learn how to and publish this project to PyPi
  • Add combined Rule types (with logical operators)
  • Add automated tests
  • Add support for TCP/UDP routers and services
  • Remove pyyaml as a hard dependency
  • Add local Traefik config as data source (e.g. for entrypoint and TLS resolver names)
  • Add Dockerfile as a data source
  • Add K8s YAML as a data source
  • Add Docker Swarm YAML as a data source
  • Add more sophisticated Rule parsing (e.g. from a given URL)

Something to think about:

  • Expand out of Traefik into a more general use-case
  • Compatibility for Windows machines

Guidelines for development

  • Ease of use is a priority
  • Use sensible defaults without asking, when possible
  • When defaults are not possible, offer the user a sensible prefilled value
  • The code should be as Pythonic as possible
  • Use type hints as much as possible to catch logical errors

Local development setup

For local development, a virtual environment is highly recommended. The following section will assume you installed a virtual environment with the venv module:

python3 -m venv venv

All requirements for development are given in requirements-dev.txt. Install all of them before contributing. This is required for pre-commit.

Before commiting, install pre-commit hooks for Git by running:

pre-commit install

This will run the following programs to verify a commit:

  • Black - code formatting
  • MyPy - static type checking
  • PyLint - code linting

You can install the Laebelmaker project locally in Development Mode:

python3 -m pip install -e .

The project will be installed in the virtual environment but will remain editable.

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

laebelmaker-0.4.0.tar.gz (14.6 kB view hashes)

Uploaded source

Built Distribution

laebelmaker-0.4.0-py3-none-any.whl (14.1 kB view hashes)

Uploaded py3

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