This repository has been archived on 2026-03-12. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
config-parser/README.md
T

110 lines
2.5 KiB
Markdown

# config-parser
A library to parse configuration files.
## Installation
You can install the library using pip:
```bash
pip install config-parser --index-url https://repo.jcloud-services.ddns.net/simple/
```
## Usage
Here are a few simple examples of how to use the `config-parser` library to read an configuration files:
### INI Configuration
```python
from config_parser.ini import INIConfiguration
with open('config.conf', 'r') as file:
config_content = file.read()
parsed = INIConfiguration.from_string(config_content)
print(dict(parsed))
```
If the configuration file content is:
```ini
global1=global value1
global2=global value2
[section1]
key1=value1
key2=value2
[section2]
hello=world
[section3]
key=value
```
the result will be `{'section1': {'key1': 'value1', 'key2': 'value2'}, 'section2': {'hello': 'world'}, 'section3': {'key': 'value'}}`
### JSON Configuration
```python
from config_parser.json import JSONConfiguration
with open('config.json', 'r') as file:
config_content = file.read()
parsed = JSONConfiguration.from_string(config_content)
print(dict(parsed))
```
If the configuration file content is:
```json
{
"section1": {
"key1": "value1",
"key2": "value2",
"number": 42,
"number2": 3.14,
"number3": -1,
"boolean": true,
"boolean2": false,
"null": null
},
"section2": {
"hello": "world"
},
"section3": {
"key": "value"
}
}
```
the result will be `{'section1': {'key1': 'value1', 'key2': 'value2', 'number': 42, 'number2': 3.14, 'number3': -1, 'boolean': True, 'boolean2': False, 'null': None}, 'section2': {'hello': 'world'}, 'section3': {'key': 'value'}}`
## Full documentation
For the full documentation, see the Python docstrings.
## Changelog
### Version 1.3.0
- support for mutable and immutable configurations
### Version 1.2.1
- Bug fix: `jeb_utils.exceptions.ConfigurationSyntaxError` has inherited from `SyntaxError`, which is semantically wrong. Now it is a normal exception and it inherits from `Exception`.
### Version 1.2.0
- Support for a default configuration for INI files
- Consistent `__all__` lists in all modules
- Support for `in` at configuration classes
### Version 1.1.1
- Updated the `__init__.py` files in the packages. Now you do not need to run e. g. `import config_parser.parse`, you can simply run `import config_parser` to access `config_parser.parse`
### Version 1.1.0
- JSON and INI serializer
### Version 1.0.0
- JSON parser
- better API
### Version 0.1.0
- First release
- INI parser