{{announcement.body}}
{{announcement.title}}

Introducing parse_it : A Python Configuration Parser

DZone 's Guide to

Introducing parse_it : A Python Configuration Parser

Make configuring your Python apps simple with the open-source parse_it.

· Open Source Zone ·
Free Resource

Whether you use Python for frontend, backend, Big Data, academics, or just need a simple script to automate an annoying task you will most likely need to pass a few configuration variables for your app. This can be done in many different ways:

  • Environment variables
  • Command line arguments
  • Configuration file(s)

Each method has its own pros and cons, and deciding which one to use can bring up a lot of questions:

  • Which method should I choose to configure my app?
  • Should I choose just one or multiple methods to configure my app?
  • Which file format should I use for my configuration files?

The list can go on and on as each question will only bring more follow up questions. This is why I decided to create a single “parse_it” package that can handle all of the needed work surrounding a Python project's settings and configuration work. parse_it handles all of that with ease — with the basic concept being that the end users, not the developer, should decide how to configure the app.

Installation

Installing is easy:

pip install parse_it


Using

Using parse_it is almost as easy as installing it:

# Load parse_it
from parse_it import ParseIt

# Create parse_it object.
parser = ParseIt()

# Now you can read your configuration values no matter how they are configured (cli args, envvars, json/yaml/etc files)
my_setting = parser.read_configuration_variable("my_setting")


parse_it allows you to do much more then just read a variable, including:

  1. Multiple file format support (JSON, YAML, TOML, HCL, INI, XML)
  2. Find the needed setting key form multiple configuration files (by default, all valid file formats are read from the working directory recursively)
  3. EnvVar support (Including configurable auto capitalization and prefix)
  4. Command line argument support
  5. Auto-correct data types (so your EnvVars and CLI args will return Dicts, Lists, Intgers, Boolens, etc…)
  6. Easily configurable
  7. Default values per setting and globally across all settings
  8. Easily flag a setting as required so it will raise an error if missing

All of the options above (and more) can be easily configured and are described in the single-page README guide at the project GitHub repo at https://github.com/naorlivne/parse_it.

Topics:
python ,open source ,parse_it ,app configuration ,tutorial

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}