Creates an .env.example file for your Python monorepo, based on all Pydantic settings classes found in your project. Env-example uses the abstract syntax tree of your project to discover settings instead of runtime introspection, to avoid side effects and having to deal with external project dependencies.
I recommend to use uvx to run env-example:
# Basic usage
uvx env-example
# Exclude specific directories from the search. Relative to the project root
uvx env-example --exclude-dir other/scripts
# Ignore optional settings fields
uvx env-example --ignore-optionalsfrom pydantic_settings import BaseSettings
class AppSettings(BaseSettings):
model_config = {
"env_prefix": "APP__"
}
debug: bool
log_level: str
class DatabaseSettings(BaseSettings):
model_config = {
"env_prefix": "DB__"
}
host: str
port: int
username: str
password: strenv-example will generate the following .env.example file:
# AppSettings
APP__DEBUG=
APP__LOG_LEVEL=
# DatabaseSettings
DB__HOST=
DB__PORT=
DB__USERNAME=
DB__PASSWORD=