days
-7
-1
hours
0
-4
minutes
-1
-3
seconds
-2
-1
search
Settings management with Dynaconf

Dynaconf: Dynamic settings configuration for Python apps

Sarah Schlothauer
python
© Shutterstock /NothingIsEverything

Dynaconf is a dynamic configuration for Python applications. With it, you can set one canonical settings module to use for all instances. Users can also change their dynamic parameters without having to deploy their application. This settings config tool for Python offers extensions for both Flask and Django.

As Python’s popularity continues to grow, so too does its ecosystem of available open source tools. Many tools intend to streamline workflow and save developers time when creating apps.

Today we focus on one such tool: Dynaconf.

Dynaconf features

Dynaconf, the dynamic configuration system for Python apps, helps manage settings in newly created Python projects. It supports 12-factor applications and extensions.

SEE ALSO: Create, debug, and deploy Java & Python applications with AWS Toolkit for IntelliJ

The Flask extension guide shows how to initialize the extension and use FLASH_ environment variables. Dynaconf v2.0 also introduced the Django framework extension.

It’s also a good secret keeper. The additional secrets file stores sensitive information, such as PASSWORD and TOKEN, in the .secrets file or vault server.  With this feature, security sensitive data will not be sent to a public git repo by mistake.

Built-in support for the Vault Project from Hashicorp adds another layer of security for secrets protection. You can also have an extra secrets file available only when specific CI environments are running.

From the documentation, some more of its noteworthy features:

  • Follows the 12-factor application guide and separates settings from code.
  • Define comprehensive default values
  • Support for storing parameters in .toml, .json, .yaml (with PyYAML  installed), .ini and .py formats.
  • Feature flag system
  • Optional parameter storage in external services
  • Layered [environment] system.
  • Override parameters with environmental variables.
  • Support for .env files to automate the export of environment variables.
  • Correct data types
  • One canonical settings module can be used for all future instances
  • Manage settings via your console with $ dynaconf CLI
  • Validation of settings parameters
  • Change dynamic parameters without having to redeploy your application
  • Create your own custom loader
  • Tested on Windows and Linux

Hands-off settings management

Project contributor and Red Hat software engineer Bruno Rocha wrote an introduction to Dynaconf. This introduction explores its use cases and starting instructions. According to Bruno Rocha’s tutorial, Dynaconf only requires one line of code to set up:

python

He writes: “there is no magic, and the values can come from wherever you want, by default and following the recommendations of the 12 factor apps Dynaconf has preference for environment variables.”

SEE ALSO: Top Python use cases: Bringing machine learning to the enterprise

Before getting started, you will also need Python version 3.x.

Default installation supports .toml, .py, and .json file formats, as well as .env environmental variables.

Have you used it in your apps? Give Dynaconf feedback on how to improve new versions here.

Author
Sarah Schlothauer

Sarah Schlothauer

All Posts by Sarah Schlothauer

Sarah Schlothauer is an assistant editor for JAXenter.com. She received her Bachelor's degree from Monmouth University and is currently enrolled at Goethe University in Frankfurt, Germany where she is working on her Masters. She lives in Frankfurt with her husband and cat.

Leave a Reply

Be the First to Comment!

avatar
400
  Subscribe  
Notify of