Which is better for creating a settings file for Python programs, the built-in module (ConfigParser), or the independent project (ConfigObj)?
The configparser module from Python's standard library defines functionality for reading and writing configuration files as used by Microsoft Windows OS. Such files usually have . INI extension.
An INI file is a configuration file for computer software. It contains key-value pairs that represent properties and their values. These key-value pairs are organized under sections.
I recently switched from configparser to configobj, and I'm thrilled to have done so.
For me, the big difference is configobj's validator. It lets me very easily/succinctly (1) define the type and acceptable values for each entry, and (2) set defaults.
Those two features save me a lot of code and prevent a lot from going wrong. Plus, there's really no extra overhead to using configobj in terms of the complexity of my code, and the library is quite small.
Depending on your Python version, it may be contentious whether this answers your question, but after a short look at ConfigParser and ConfigObj, I settled for configparser, the Python 3 version of ConfigParser. There’s also a backported version on PyPI.
ConfigParser seemed cumbersome to me, maybe even—dare I say it—unpythonic, and with ConfigObj I encountered an esoteric problem with lists (I’d prefer to be able to align them vertically, since mine get really long), and it didn’t help that the latest version was published more than two years ago. The API of configparser, however, looked as spiffy as that of ConfigObj (albeit not as feature-rich), and when we move to Python 3, I can probably switch to the built-in version easily.
By the way, it works great so far.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With