94 lines
2.2 KiB
Markdown
94 lines
2.2 KiB
Markdown
# jcloud-config-parser
|
|
|
|
A library to parse configuration files.
|
|
|
|
## Installation
|
|
You can install the library using pip:
|
|
|
|
```bash
|
|
pip install jcloud-config-parser --index-url https://repo.jcloud-services.ddns.net/simple/
|
|
```
|
|
|
|
## Usage
|
|
Here are a few simple examples of how to use the `jcloud-config-parser` library to read an configuration files:
|
|
|
|
### INI Configuration
|
|
```python
|
|
from jcloud_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 jcloud_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 0.2.0
|
|
- support for specifying mutability when parsing a configuration
|
|
|
|
### Version 0.1.1
|
|
- backward compatibility for Python < 3.12: in Python < 3.12, f-string expression parts could not contain backslashes. The code contained an f-string with backslahes in the expression part. As an alternative to the f-string, normal strings are concatenated now.
|
|
|
|
### Version 0.1.0
|
|
- Changed the name from `config-parser` to `jcloud-config-parser` |