Introducing parse_it : A Python Configuration Parser
Make configuring your Python apps simple with the open-source parse_it.
Join the DZone community and get the full member experience.Join For Free
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.
Installing is easy:
pip install parse_it
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:
- Multiple file format support (JSON, YAML, TOML, HCL, INI, XML)
- Find the needed setting key form multiple configuration files (by default, all valid file formats are read from the working directory recursively)
- EnvVar support (Including configurable auto capitalization and prefix)
- Command line argument support
- Auto-correct data types (so your EnvVars and CLI args will return Dicts, Lists, Intgers, Boolens, etc…)
- Easily configurable
- Default values per setting and globally across all settings
- 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.
Opinions expressed by DZone contributors are their own.