Package allow configuration and section's option values of .ini file to be called as attributes, where the section and option are separated by dot notation.
Project description
dotmapini
Package allow configuration and section's option values of .ini file to be called as attributes, where the section and option are separated by dot notation.
The focus is to work with .ini configuration data using dot notation. Just call attributes and get their values in development flow while defining them in single place.
- No more configuration values in
config['section']['option']style, justconfig.section.option; - Can parse .ini files with dots between section names and convert them as several sections for corresponding values;
- Parse values and convert them to Python data types;
# Return parsed value types: Union[str, bool, int, None] # other types not implemented and will be parsed as str
- Your config is instance of
collections.MutableMapping(dict's like) and have the same features; - Less keystroke;
- No dependencies, only stdlib.
Installation:
pip install dotmapini
Usage:
Imagine you have following .ini configuration file:
# example.ini
[APP]
debug = False
[server]
host = 127.0.0.1
port = 8080
[server.db]
host = localhost
database = test
user = username
password = password
Minimal reproducible example:
from dotmapini import Config
config = Config.load(path='/your/path/to/example.ini')
print(config.APP.debug) # => False type bool
print(config.server.host) # => '127.0.0.1' type str
print(config.server.port) # => 8080 type int
print(config.server.db.database) # => 'test' type str
print(config.server.db.username) # => 'username' type str
Of course as always you can do this:
print(config['server']['db']['host']) # => 'localhost' type str
But for what...
IMPORTANT:
-
Uppercase strings for options will be parsed as lowercase.
Example:
[section] OPTION = ...
Will be:
config = Config.load(...) config.section.option # not self.section.OPTION
-
Float numbers in options always will be parsed as a string.
Example:
[section] option = 1.5
Will be:
config = Config.load(...) config.section.option: str = '1.5'
-
Only digits in section's name not allowed.
Example:
[section.1.subsection] ; A digit between dots not allowed as well ... [2] ... [3.section] ...
Will be:
config = Config.load(...) # will raise DigitInSectionNameError
-
If you have DEFAULT section it will be added to all other sections thus it can override same named option values.
Example:
[DEFAULT] option = value [section] option = value2
Will be:
config = Config.load(...) config.section.option = value # not value2
Most of this stuff is the default behavior of configparser.ConfigParser.
Need to mention:
Q: Why not dotmap?
A: I want to focus to work specifically with .ini/configparser. There is no need to me to create a lot of dict's like objects.
Q: Why not types.SimpleNamesapce?
A: It can instantiate attributes and nothing else, that is not the case here. Class collections.MutableMapping provide more control/isolation when create complex custom dict's like bjects, which is focus to work with .ini configuration files and modify receiving values.
LICENSE
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dotmapini-1.0.0.tar.gz.
File metadata
- Download URL: dotmapini-1.0.0.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31c87833241f63d7071d3f56ec3dd507b30916459b7f612229aa113b71d4a692
|
|
| MD5 |
d153bf86033ee73d6bc404fe1c4f7b8b
|
|
| BLAKE2b-256 |
c9925cec47017b94d69bbb524455c704b735faeef0897ed1f7f9f911f9634a3d
|
File details
Details for the file dotmapini-1.0.0-py3-none-any.whl.
File metadata
- Download URL: dotmapini-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f8f671ce6cf58916bb63325383eed1570845d9a76785549727d4f84bb47fd8ef
|
|
| MD5 |
dae51fc6b040cb537a403027540651dd
|
|
| BLAKE2b-256 |
024d2ed401779c875545c6c5d2c85454be57f7155ad6da4bef692b8dacf11ab0
|