Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Configuration Management for Python ⚙

License

NotificationsYou must be signed in to change notification settings

dynaconf/dynaconf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dynaconf. new logo

dynaconf - Configuration Management for Python.

MIT LicensePyPIPyPIPyPI - DownloadsCIcodecovCodacy BadgeGitHub starsGitHub Release DateGitHub commits since latest releaseGitHub last commitCode Style Black

GitHub issuesUser ForumJoin the chat at https://gitter.im/dynaconf/dev Matrix

Features

  • Inspired by the12-factor application guide
  • Settings management (default values, validation, parsing, templating)
  • Protection of sensitive information (passwords/tokens)
  • Multiple file formatstoml|yaml|json|ini|py and also customizable loaders.
  • Full support for environment variables to override existing settings (dotenv support included).
  • Optional layered system for multi environments[default, development, testing, production]
  • Built-in support for Hashicorp Vault and Redis as settings and secrets storage.
  • Built-in extensions forDjango andFlask web frameworks.
  • CLI for common operations such asinit, list, write, validate, export.
  • full docs onhttps://dynaconf.com

Install

$ pip install dynaconf

Initialize Dynaconf on project root directory

$ cd path/to/your/project/$ dynaconf init -f toml⚙️  Configuring your Dynaconf environment------------------------------------------🐍 The file `config.py` was generated.🎛️  settings.toml created to hold your settings.🔑 .secrets.toml created to hold your secrets.🙈 the .secrets.* is also included in `.gitignore`  beware to not push your secrets to a public repo.🎉 Dynaconf is configured! read more on https://dynaconf.com

TIP: You can selecttoml|yaml|json|ini|py ondynaconf init -f <fileformat>toml is the default and also the most recommended format for configuration.

Dynaconf init creates the following files

.├── config.py       # This is from where you import your settings object (required)├── .secrets.toml   # This is to hold sensitive data like passwords and tokens (optional)└── settings.toml   # This is to hold your application settings (optional)

On the fileconfig.py Dynaconf init generates the following boilerpate

fromdynaconfimportDynaconfsettings=Dynaconf(envvar_prefix="DYNACONF",# export envvars with `export DYNACONF_FOO=bar`.settings_files=['settings.yaml','.secrets.yaml'],# Load files in the given order.)

TIP: You can create the files yourself instead of using theinit command as shown above and you can give any name you want instead of the defaultconfig.py (the file must be in your importable python path) - See more options that you can pass toDynaconf class initializer onhttps://dynaconf.com

Using Dynaconf

Put your settings onsettings.{toml|yaml|ini|json|py}

username ="admin"port =5555database = {name='mydb',schema='main'}

Put sensitive information on.secrets.{toml|yaml|ini|json|py}

password ="secret123"

IMPORTANT:dynaconf init command puts the.secrets.* in your.gitignore to avoid it to be exposed on public repos but it is your responsibility to keep it safe in your local environment, also the recommendation for production environments is to use the built-in support for Hashicorp Vault service for password and tokens.

Optionally you can now use environment variables to override values per execution or per environment.

# override `port` from settings.toml file and automatically casts as `int` value.export DYNACONF_PORT=9900

On your code import thesettings object

frompath.to.project.configimportsettings# Reading the settingssettings.username=="admin"# dot notation with multi nesting supportsettings.PORT==9900# case insensitivesettings['password']=="secret123"# dict like accesssettings.get("nonexisting","default value")# Default values just like a dictsettings.databases.name=="mydb"# Nested key traversingsettings['databases.schema']=="main"# Nested key traversing

More

  • Settings Schema Validation
  • Custom Settings Loaders
  • Vault Services
  • Template substitutions
  • etc...

There is a lot more you can do,read the docs:http://dynaconf.com

Contribute

Main discussions happens onDiscussions Tab learn more about how to get involved onCONTRIBUTING.md guide

More

If you are looking for something similar to Dynaconf to use in your Rust projects:https://github.com/rubik/hydroconf

And a special thanks toCaneco for the logo.


[8]ページ先頭

©2009-2025 Movatter.jp