Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
Introducing parse_it — a Python configuration parser
Photo by Chris Ried on Unsplash
No matter if you use Python for frontend, backend, big data, academics or just need a simple script to automate an annoying task you will most likely to pass a few configuration variables for said app, this can be done in many different ways:
- Environment variables
- Command line arguments
- Configuration file(s)
Each method has it’s own pros and cons & 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?
This list can go on and on as each question will only bring more follow up question, this is why I decided to create a single “parse_it” package which can handle all of the needed work surrounding a Python project settings & configuration work, parse_it handles all of that with ease with the basic concept being that deciding how to configure the app should be left to the app end-user and not for the developer.
Installation
Installing is easy:
pip install parse_it
Using
Using parse_it is almost as easy as installing it:
# Load parse_itfrom 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 & includes:
- 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 & prefix)
- Command line argument support
- Auto-correct data types (so your EnvVars & CLI args will return Dicts, Lists, Intgers, Boolens, etc…)
- Easily configurable
- Default values per setting & globally across all settings
- Easily flag a setting as required so it will raise a error if missing
All of the options above (& more) can be easily configured & is described in the single page README guide at the project GitHub repo at https://github.com/naorlivne/parse_it
Introducing parse_it — a Python configuration parser was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.