[Python] How to separate dynaconf settings for each environment in its own file?

Discussão em 'Python' iniciado por Stack, Abril 13, 2025.

  1. Stack

    Stack Membro Participativo

    Im using dynaconf 3.2.4 to load my config files. I want have seperate files for each environment: config.dev.yaml, config.test.yaml, config.prod.yaml, etc. I want to keep my files simple and do without the unnecessary indentation.

    For config.dev.yaml instead of

    dev:
    version: 1
    name: 'dev settings'


    I want

    version: 1
    name: 'dev settings'


    My current settings:

    settings = Dynaconf(
    envvar_prefix="MYPREFIX",
    settings_files=["config/config.dev.yaml", "config/config.test.yaml", "config/config.prod.yaml"],
    environments=True,
    env="dev",
    )


    How do i need to configure dyaconf to load each environment correctly?

    Running with the above settings i get

    settings.current_env # 'DEVELOPMENT'
    settings.name # 'Settings' object has no attribute 'NAME'


    Setting environments=False results in

    settings.current_env # 'main'
    settings.name # 'prod settings'


    It seems to load only the last specified yaml file.

    Same problem (without solution) found here: https://github.com/dynaconf/dynaconf/discussions/956

    Continue reading...

Compartilhe esta Página