Skip to main content

The dynamic configurator for your Python Project

Project description

Dynaconf

dynaconf - Configuration Management for Python.

MIT License PyPI PyPI PyPI - Downloads Build Status Azure DevOps builds (branch) Azure DevOps builds (branch) codecov Codacy Badge GitHub issues GitHub stars GitHub Release Date GitHub commits since latest release GitHub last commit Code Style Black Telegram

Features

  • Inspired by the 12-factor application guide
  • Settings management (default values, validation, parsing, templating)
  • Protection of sensitive information (passwords/tokens)
  • Multiple file formats toml|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 for Django and Flask web frameworks.
  • CLI for common operations such as init, list, write, validate, export.
  • full docs on https://dynaconf.com

Quick start

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 select toml|yaml|json|ini|py on dynaconf 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 setttings (optional)

On the file config.py Dynaconf init generates the following boilerpate

from dynaconf import Dynaconf

settings = 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 the init command as shown above and you can give any name you want instead of the default config.py (the file must be in your importable python path) - See more options that you can pass to Dynaconf class initializer on https://dynaconf.com

Using Dynaconf

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

username = "admin"
port = 5555
database = {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 the settings object

from path.to.project.config import settings

# Reading the settings

settings.username == "admin"  # dot notation with multi nesting support
settings.PORT == 9900  # case insensitive
settings['password'] == "secret123"  # dict like access
settings.get("nonexisting", "default value")  # Default values just like a dict
settings.databases.name == "mydb"  # Nested key traversing
settings['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 on t.me/dynaconf learn more about how to get involved on CONTRIBUTING.md guide

Top Contributors

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dynaconf-3.1.1rc4.tar.gz (265.2 kB view details)

Uploaded Source

Built Distribution

dynaconf-3.1.1rc4-py2.py3-none-any.whl (280.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file dynaconf-3.1.1rc4.tar.gz.

File metadata

  • Download URL: dynaconf-3.1.1rc4.tar.gz
  • Upload date:
  • Size: 265.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.5

File hashes

Hashes for dynaconf-3.1.1rc4.tar.gz
Algorithm Hash digest
SHA256 4a977f237d4d6691131ac85518fac304289858f1edf38a04498973f75883fccc
MD5 a90ff523556618fc3fd3271e20170307
BLAKE2b-256 d80241ec057e4faf6e13e73ff0a78c4d3aeb64ccba73b769cd08a41827021885

See more details on using hashes here.

File details

Details for the file dynaconf-3.1.1rc4-py2.py3-none-any.whl.

File metadata

  • Download URL: dynaconf-3.1.1rc4-py2.py3-none-any.whl
  • Upload date:
  • Size: 280.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.5

File hashes

Hashes for dynaconf-3.1.1rc4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 87028cce33d10e31acf8809473de2c78cd73db1f1da073b6d20f2336e3fd4f88
MD5 9c824ffec7b6ecfe5c9cc125f5548755
BLAKE2b-256 1fa7bd28fc08e3481975d1c450bb43a23eda932be92e9bf3fbcd133c0cab8799

See more details on using hashes here.

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