geändert: .gitignore
geändert: README.md geändert: pyproject.toml geändert: src/config_parser/__init__.py neue Datei: src/config_parser/_configuration.py neue Datei: src/config_parser/exceptions.py neue Datei: src/config_parser/ini.py neue Datei: src/config_parser/json.py neue Datei: src/config_parser/parse/ini.py neue Datei: src/config_parser/parse/json.py neue Datei: tests/ini/test_ini.py neue Datei: tests/json/test.json neue Datei: tests/json/test_json.py neue Datei: tests/json/test_parser.py neue Datei: tests/test_configuration_class.py
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# config-parser
|
||||
|
||||
A library to parse configuration files. Currently it supports only INI format, but support for other formats is planned.
|
||||
A library to parse configuration files.
|
||||
|
||||
## Installation
|
||||
You can install the library using pip:
|
||||
@@ -10,20 +10,24 @@ pip install config-parser --index-url https://jcloud-services.ddns.net/simple/
|
||||
```
|
||||
|
||||
## Usage
|
||||
Here's a simple example of how to use the `config-parser` library to read an INI configuration file:
|
||||
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 import parse_ini
|
||||
from config_parser.ini import INIConfiguration
|
||||
|
||||
with open('config.conf', 'r') as file:
|
||||
config_content = file.read()
|
||||
|
||||
parsed = parse_ini(config_content)
|
||||
print(parsed)
|
||||
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
|
||||
@@ -35,4 +39,39 @@ hello=world
|
||||
key=value
|
||||
```
|
||||
|
||||
the result will be `{'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'}}`
|
||||
Reference in New Issue
Block a user