Skip to main content

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, just config.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 datatypes;
    # Return parsed value datatypes:
    Union[Config, str, bool, int, float, bytes, tuple, list, dict, set, None]
    # Other types as well as Python types that aren't presented correctly in .ini
    # not implemented and will be parsed as string.
    
  • Your config is instance of collections.MutableMapping (dict's like) and have the same features;
  • Support all keyword arguments for configparser.ConfigParser in Config.load(path, **kwargs) method;
  • 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

[complex.Python.datatypes]  ; Your complex Python datatype as is
example = [{'key': ({'value', 'value2'}, [True, 1.2, 3])}]

Minimal reproducible example:

from dotmapini import Config


config = Config.load(
    path='/your/path/to/example.ini',
    allow_no_value=True  # keyword for configparser.ConfigParser(...)
    )
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
print(config.complex.Python.datatypes.example)  # => [{'key': ({'value', 'value2'}, [True, 1.2, 3])}] type list

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
    
  • 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
    
  • Be aware not to memory overflow while represent complex Python datatypes in .ini file.

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 objects, which is focus to work with .ini configuration files and modify receiving values.

LICENSE

MIT

Metadata

Release files for dotmapini 1.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dotmapini 1.0.4
File Size Uploaded
dotmapini-1.0.4.tar.gz 9.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dotmapini 1.0.4
File Interpreter ABI Platform
dotmapini-1.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 16.3 kB

Release files / dotmapini-1.0.4.tar.gz

Download URL dotmapini-1.0.4.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
10a63882f1cd2551e7488df73cf4025fccc29563b044b4df61fc2aecff39284c
BLAKE2b-256 checksum
How to use checksums
aac312f7ff7be39a8585621b9f08d3e0bd50c39102e307f7cfdab0f08928eb92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.19

Release files / dotmapini-1.0.4-py3-none-any.whl

Download URL dotmapini-1.0.4-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b9341b7af6f1a0fdf4aa043e338eab8ea7f5c17c21dd10bf5dec17b898bfa9b2
BLAKE2b-256 checksum
How to use checksums
f20e9ec76257a5bd13d2e5bee646ceaca2dcae5d7d97a3cb495d1f8c09ac29d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.19

Release history Release notifications | RSS feed

This release

1.0.4 This release

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page