configobjectify 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sandeep Suryaprasad
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,101 @@
1
+ Metadata-Version: 2.4
2
+ Name: configobjectify
3
+ Version: 0.1.0
4
+ Summary: A lightweight Python library for converting Configuration Files into Python Objects.
5
+ Keywords: config-parsing,attribute-lookup,dot-access,config-files,config-ini
6
+ Author: Sandeep Suryaprasad
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Requires-Python: >=3.12
15
+ Project-URL: Homepage, https://github.com/sandeepsuryaprasad/configobjectify
16
+ Project-URL: Repository, https://github.com/sandeepsuryaprasad/configobjectify
17
+ Project-URL: Issues, https://github.com/sandeepsuryaprasad/configobjectify/issues
18
+ Description-Content-Type: text/markdown
19
+
20
+ ## configobjectify
21
+
22
+ [![CI](https://github.com/sandeepsuryaprasad/configobjectify/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/sandeepsuryaprasad/configbjectify/actions/workflows/ci.yml)
23
+ [![Development Status](https://img.shields.io/pypi/status/configobjectify)](https://pypi.org/project/configobjectify/)
24
+ [![Python versions](https://img.shields.io/pypi/pyversions/configobjectify?label=Python)](https://pypi.org/project/configobjectify/)
25
+
26
+ A lightweight Python library that provides an object-oriented
27
+ interface for accessing values from INI configuration files. Instead of retrieving
28
+ values using dictionary-style or section-based lookups, you can access configuration
29
+ keys through dot notation.
30
+
31
+ ## Installation
32
+ ```console
33
+ pip install configobjectify
34
+ ```
35
+
36
+ ## Usage
37
+ Consider the following `config.ini` file,
38
+ ```console
39
+ [APPLE]
40
+ device_name = iPhone
41
+ model = iPhone 17
42
+ os_version = 26.0
43
+
44
+ [ANDROID]
45
+ device_name = Pixel
46
+ model = Pixel 10
47
+ os_version = 16
48
+ ```
49
+
50
+ ```console
51
+ >>> from configobjectify import Config
52
+ >>> config = Config("config.ini", "APPLE")
53
+ >>> config.device_name.value
54
+ 'iPhone'
55
+ >>> config.model.value
56
+ 'iPhone 17'
57
+ >>> config.os_version.value
58
+ '26.0'
59
+ ```
60
+ ### Selecting a different section
61
+ ```console
62
+ >>> config = Config("config.ini", "ANDROID")
63
+ >>> config.device_name.value
64
+ 'Pixel'
65
+ >>> config.model.value
66
+ 'Pixel 10'
67
+ >>> config.os_version.value
68
+ '16.0'
69
+ ```
70
+ NOTE: Section names are normalized to uppercase by the library before lookup.
71
+
72
+ ### Handling missing configuration keys
73
+ ```console
74
+ >>> config = Config("config.ini", "APPLE")
75
+ >>> config.country_of_origin.value
76
+ >>> ''
77
+ ```
78
+
79
+ ### Installed version
80
+ To get to know the version of `configobjectify`,
81
+ ```console
82
+ >>> import configobjectify
83
+ >>> print(configobjectify.__version__)
84
+ ```
85
+ or
86
+ ```console
87
+ >>> from configobjectify import __version__
88
+ >>> print(__version__)
89
+ ```
90
+
91
+ ### Requirements
92
+ * Python 3.12 or later
93
+
94
+ ### Contributing
95
+ Contributions, bug reports, and feature suggestions are welcome. Please open an issue to
96
+ discuss a proposed change before submitting a pull request.
97
+
98
+ ### License
99
+
100
+ This package is distributed under the terms of [MIT](https://github.com/sandeepsuryaprasad/configobjectify/blob/main/LICENSE) license
101
+
@@ -0,0 +1,82 @@
1
+ ## configobjectify
2
+
3
+ [![CI](https://github.com/sandeepsuryaprasad/configobjectify/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/sandeepsuryaprasad/configbjectify/actions/workflows/ci.yml)
4
+ [![Development Status](https://img.shields.io/pypi/status/configobjectify)](https://pypi.org/project/configobjectify/)
5
+ [![Python versions](https://img.shields.io/pypi/pyversions/configobjectify?label=Python)](https://pypi.org/project/configobjectify/)
6
+
7
+ A lightweight Python library that provides an object-oriented
8
+ interface for accessing values from INI configuration files. Instead of retrieving
9
+ values using dictionary-style or section-based lookups, you can access configuration
10
+ keys through dot notation.
11
+
12
+ ## Installation
13
+ ```console
14
+ pip install configobjectify
15
+ ```
16
+
17
+ ## Usage
18
+ Consider the following `config.ini` file,
19
+ ```console
20
+ [APPLE]
21
+ device_name = iPhone
22
+ model = iPhone 17
23
+ os_version = 26.0
24
+
25
+ [ANDROID]
26
+ device_name = Pixel
27
+ model = Pixel 10
28
+ os_version = 16
29
+ ```
30
+
31
+ ```console
32
+ >>> from configobjectify import Config
33
+ >>> config = Config("config.ini", "APPLE")
34
+ >>> config.device_name.value
35
+ 'iPhone'
36
+ >>> config.model.value
37
+ 'iPhone 17'
38
+ >>> config.os_version.value
39
+ '26.0'
40
+ ```
41
+ ### Selecting a different section
42
+ ```console
43
+ >>> config = Config("config.ini", "ANDROID")
44
+ >>> config.device_name.value
45
+ 'Pixel'
46
+ >>> config.model.value
47
+ 'Pixel 10'
48
+ >>> config.os_version.value
49
+ '16.0'
50
+ ```
51
+ NOTE: Section names are normalized to uppercase by the library before lookup.
52
+
53
+ ### Handling missing configuration keys
54
+ ```console
55
+ >>> config = Config("config.ini", "APPLE")
56
+ >>> config.country_of_origin.value
57
+ >>> ''
58
+ ```
59
+
60
+ ### Installed version
61
+ To get to know the version of `configobjectify`,
62
+ ```console
63
+ >>> import configobjectify
64
+ >>> print(configobjectify.__version__)
65
+ ```
66
+ or
67
+ ```console
68
+ >>> from configobjectify import __version__
69
+ >>> print(__version__)
70
+ ```
71
+
72
+ ### Requirements
73
+ * Python 3.12 or later
74
+
75
+ ### Contributing
76
+ Contributions, bug reports, and feature suggestions are welcome. Please open an issue to
77
+ discuss a proposed change before submitting a pull request.
78
+
79
+ ### License
80
+
81
+ This package is distributed under the terms of [MIT](https://github.com/sandeepsuryaprasad/configobjectify/blob/main/LICENSE) license
82
+
@@ -0,0 +1,111 @@
1
+ [build-system]
2
+ requires = ["uv_build>=0.9.13, < 0.14.0"]
3
+ build-backend = "uv_build"
4
+
5
+ [project]
6
+ name = "configobjectify"
7
+ version = "0.1.0"
8
+ description = "A lightweight Python library for converting Configuration Files into Python Objects."
9
+ readme = "README.md"
10
+ requires-python = ">=3.12"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ keywords = [
14
+ "config-parsing",
15
+ "attribute-lookup",
16
+ "dot-access",
17
+ "config-files",
18
+ "config-ini",
19
+ ]
20
+ classifiers = [
21
+ "Development Status :: 3 - Alpha",
22
+ "Topic :: Software Development :: Libraries :: Python Modules",
23
+ "Programming Language :: Python :: 3.12",
24
+ "Programming Language :: Python :: 3.13",
25
+ "Programming Language :: Python :: 3.14",
26
+ ]
27
+ dependencies = []
28
+
29
+ [[project.authors]]
30
+ name = "Sandeep Suryaprasad"
31
+
32
+ [project.urls]
33
+ Homepage = "https://github.com/sandeepsuryaprasad/configobjectify"
34
+ Repository = "https://github.com/sandeepsuryaprasad/configobjectify"
35
+ Issues = "https://github.com/sandeepsuryaprasad/configobjectify/issues"
36
+
37
+ [dependency-groups]
38
+ test = ["pytest>=8.0.0"]
39
+ lint = ["ruff>=0.14.0"]
40
+
41
+ [tool.uv.build-backend]
42
+ module-root = "src"
43
+ module-name = "configobjectify"
44
+
45
+ [tool.ruff]
46
+ line-length = 119
47
+ exclude = [
48
+ "tests",
49
+ "sitepackages",
50
+ ".git",
51
+ ".github",
52
+ "__pycache__",
53
+ ".venv",
54
+ "build",
55
+ "dist",
56
+ ".pytest_cache",
57
+ ".tox",
58
+ ".vscode",
59
+ ".ruff_cache",
60
+ ".mypy_cache",
61
+ ".nox",
62
+ ".eggs",
63
+ ]
64
+
65
+ [tool.ruff.lint]
66
+ select = [
67
+ "F",
68
+ "N",
69
+ "E9",
70
+ "I",
71
+ "E501",
72
+ "RUF022",
73
+ "TID252",
74
+ "F841",
75
+ "N816",
76
+ "B007",
77
+ "D403",
78
+ "D101",
79
+ "D102",
80
+ "D103",
81
+ "D106",
82
+ "D201",
83
+ "D202",
84
+ "D204",
85
+ "D300",
86
+ "D404",
87
+ "D405",
88
+ "D419",
89
+ "E402",
90
+ "E401",
91
+ "E711",
92
+ "E712",
93
+ "E721",
94
+ "E722",
95
+ "E731",
96
+ ]
97
+ ignore = [
98
+ "D100",
99
+ "D101",
100
+ "D104",
101
+ "D105",
102
+ "D107",
103
+ "D212",
104
+ "D415",
105
+ ]
106
+
107
+ [tool.ruff.lint.pydocstyle]
108
+ convention = "google"
109
+
110
+ [tool.pytest.ini_options]
111
+ testpaths = ["tests"]
@@ -0,0 +1,106 @@
1
+ [build-system]
2
+ requires = ["uv_build>=0.9.13, < 0.14.0"]
3
+ build-backend = "uv_build"
4
+
5
+ [project]
6
+ name = "configobjectify"
7
+ version = "0.1.0"
8
+ description = "A lightweight Python library for converting Configuration Files into Python Objects."
9
+ readme = "README.md"
10
+ requires-python = ">=3.12"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ keywords =["config-parsing", "attribute-lookup", "dot-access", "config-files", "config-ini"]
14
+ authors = [
15
+ {name= "Sandeep Suryaprasad"}
16
+ ]
17
+ classifiers = [
18
+ "Development Status :: 3 - Alpha",
19
+ "Topic :: Software Development :: Libraries :: Python Modules",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Programming Language :: Python :: 3.13",
22
+ "Programming Language :: Python :: 3.14",
23
+ ]
24
+ dependencies = []
25
+
26
+ [project.urls]
27
+ Homepage = "https://github.com/sandeepsuryaprasad/configobjectify"
28
+ Repository = "https://github.com/sandeepsuryaprasad/configobjectify"
29
+ Issues = "https://github.com/sandeepsuryaprasad/configobjectify/issues"
30
+
31
+ [dependency-groups]
32
+ test = ["pytest>=8.0.0"]
33
+ lint = ["ruff>=0.14.0"]
34
+
35
+ [tool.uv.build-backend]
36
+ module-root = "src"
37
+ module-name = "configobjectify"
38
+
39
+ [tool.ruff]
40
+ line-length = 119
41
+ exclude = [
42
+ "tests",
43
+ "sitepackages",
44
+ ".git",
45
+ ".github",
46
+ "__pycache__",
47
+ ".venv",
48
+ "build",
49
+ "dist",
50
+ ".pytest_cache",
51
+ ".tox",
52
+ ".vscode",
53
+ ".ruff_cache",
54
+ ".mypy_cache",
55
+ ".nox",
56
+ ".eggs"
57
+ ]
58
+
59
+ [tool.ruff.lint]
60
+ select = [
61
+ "F",
62
+ "N",
63
+ "E9", # Checks for common syntax errors, indendation errors
64
+ "I",
65
+ "E501", # Checks for lines that exceed the specified maximum character length.
66
+ "RUF022",
67
+ "TID252",
68
+ "F841", # Checks for the presence of unused variables in function scopes.
69
+ "N816", # Checks for global variable names that follow the mixedCase convention.
70
+ "B007", # Checks for unused variables in loops (e.g., for and while statements).
71
+ "D403", # Checks for docstrings that do not start with a capital letter.
72
+ "D101",
73
+ "D102", # Checks for undocumented public method definitions.
74
+ "D103", # Checks for undocumented public function definitions.
75
+ "D106", # Checks for undocumented public class definitions, for nested classes.
76
+ "D201", # Checks for docstrings on functions that are separated by one or more blank lines from the function definition.
77
+ "D202", # Checks for docstrings on functions that are separated by one or more blank lines from the function body.
78
+ "D204", # Checks for class methods that are not separated from the class's docstring by a blank line.
79
+ "D300", # Checks for docstrings that use '''triple single quotes''' instead of """triple double quotes""".
80
+ "D404", # Checks for docstrings that start with This.
81
+ "D405", # Checks for section headers in docstrings that do not begin with capital letters.
82
+ "D419", # Checks for empty docstrings.
83
+ "E402", # Checks for imports that are not at the top of the file.
84
+ "E401", # Check for multiple imports on one line.
85
+ "E711", # Checks for comparisons to None which are not using the is operator.
86
+ "E712", # Checks for equality comparisons to boolean literals.
87
+ "E721", # Checks for object type comparisons using == and other comparison operators.
88
+ "E722", # Checks for bare except catches in try-except statements.
89
+ "E731", # Checks for lambda expressions which are assigned to a variable.
90
+ ]
91
+
92
+ ignore = [
93
+ "D100", # Missing docstring in public module
94
+ "D101", # Missing docstring in public class
95
+ "D104", # Missing docstring in public package
96
+ "D105", # Missing docstring in magic method
97
+ "D107", # Missing docstring in `__init__`
98
+ "D212", # Multi-line docstring summary should start at the first line
99
+ "D415" # Ignore if the doc string does not end with any punctuation
100
+ ]
101
+
102
+ [tool.ruff.lint.pydocstyle]
103
+ convention = "google"
104
+
105
+ [tool.pytest.ini_options]
106
+ testpaths = ["tests"]
@@ -0,0 +1,6 @@
1
+ from importlib.metadata import version
2
+ from .config import Config
3
+
4
+ __version__ = version("configobjectify")
5
+
6
+ __all__ = ["Config", "__version__"]
@@ -0,0 +1,88 @@
1
+ from pathlib import Path
2
+ from configparser import ConfigParser, SectionProxy
3
+ from typing import Optional
4
+
5
+
6
+ class Config:
7
+ def __init__(self, filepath: str | Path, section: str):
8
+ self.section: str = section.upper()
9
+ self.config_file = self._get_config_file(filepath)
10
+ self._parser: ConfigParser = self._get_parser()
11
+ self._data: SectionProxy = self._parse_to_dict
12
+ self._attr: Optional[str] = None
13
+
14
+ def _get_config_file(self, filename: str | Path) -> Path:
15
+ """Validate the configuration file path and return it as a Path object.
16
+
17
+ Args:
18
+ filename: Path to the configuration file.
19
+
20
+ Returns:
21
+ A Path object representing the validated INI file.
22
+
23
+ Raises:
24
+ FileNotFoundError: If the path does not point to an existing file.
25
+ ValueError: If the file does not have an .ini extension.
26
+ """
27
+ path = Path(filename)
28
+ if not path.is_file():
29
+ raise FileNotFoundError(f"{filename!r} not found")
30
+ if path.suffix.lower() != ".ini":
31
+ raise ValueError(f"Invalid file extension: {path.suffix!r}")
32
+ return path
33
+
34
+ def _get_parser(self) -> ConfigParser:
35
+ """Return a configured `ConfigParser` instance.
36
+ The parser reads configuration data from `valid.ini`.
37
+ """
38
+ parser = ConfigParser()
39
+ parser.read(self.config_file)
40
+ return parser
41
+
42
+ @property
43
+ def _parse_to_dict(self) -> SectionProxy:
44
+ """Return the selected configuration section as a dictionary.
45
+ Each configuration key in the selected section is stored as a
46
+ key-value pair in the returned dictionary.
47
+
48
+ Returns:
49
+ A dictionary containing the configuration values for the
50
+ selected section.
51
+
52
+ Raises:
53
+ KeyError: If the selected section does not exist.
54
+ """
55
+ if not self._parser.has_section(self.section):
56
+ raise KeyError(f"Invalid section {self.section!r}")
57
+ return self._parser[self.section]
58
+
59
+ @property
60
+ def value(self) -> str:
61
+ """Return the value of the most recently accessed configuration key.
62
+ Returns:
63
+ The configuration value associated with the accessed key,
64
+ or an empty string if the key does not exist.
65
+ """
66
+ return self._data.get(self._attr, "")
67
+
68
+ def __getattr__(self, name):
69
+ """Capture access to an undefined attribute.
70
+ The attribute name is stored internally and the current
71
+ `Config` instance is returned, allowing configuration values
72
+ to be accessed through expressions such as `config.device_name.value`.
73
+
74
+ Args:
75
+ name: Name of the configuration attribute being accessed.
76
+
77
+ Returns:
78
+ The current `Config` instance.
79
+ """
80
+ self._attr = name
81
+ return self
82
+
83
+ def __repr__(self):
84
+ """Return the string representation of the configuration object.
85
+ Returns:
86
+ A string containing the selected configuration section.
87
+ """
88
+ return f'Config("{self.section}")'