https://github.com/spuerta10/pyconfparser
A secure and flexible Python library for parsing, validating, and managing configuration files (YAML, JSON, and more).
https://github.com/spuerta10/pyconfparser
library pydantic python3
Last synced: over 1 year ago
JSON representation
A secure and flexible Python library for parsing, validating, and managing configuration files (YAML, JSON, and more).
- Host: GitHub
- URL: https://github.com/spuerta10/pyconfparser
- Owner: spuerta10
- Created: 2025-03-12T17:04:04.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-13T22:17:01.000Z (over 1 year ago)
- Last Synced: 2025-03-13T23:25:09.672Z (over 1 year ago)
- Topics: library, pydantic, python3
- Language: Python
- Homepage:
- Size: 25.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PyConfParser
PyConfParser is a secure and flexible Python library for parsing, validating, and managing configuration files.
## Installation
You can install this library via pip:
```shell
pip install git+https://github.com/spuerta10/PyConfParser.git
```
Or install it via [uv](https://docs.astral.sh/uv/):
```shell
uv add git+https://github.com/spuerta10/PyConfParser.git
```
## Usage
### Basic Usage
Here is a quick example of how to use this library:
```json
{
"PASS": "some-content",
"ENDPOINTS": {
"ENDPOINT1": "http://your-endpoint-1.com",
"ENDPOINT2": "http://your-endpoint-2.com"
}
}
```
*configurations.json*
```python
from pyconfparser import ConfigFactory
configurations_path: str = "/path/to/configurations.json" # the path can be relative or absolute
configurations = ConfigFactory.get_conf(configurations_path)
configurations.api_key # to obtain 'your-api-key'
configurations.enpoints["ENDPOINT1"] # to obtain 'http://your-endpoint-1.com'
configurations.enpoints["ENDPOINT2"] # to obtain 'http://your-endpoint-2.com'
```
### Using with a Schema
For stricter validation, you can define a schema using `pydantic` to ensure the configuration follows the expected structure.
```python
from pyconfparser import ConfigFactory
from pydantic import BaseModel
class ConfigSchema(BaseModel):
PASS: str
ENDPOINTS: dict[str, str]
configurations_path: str = "/path/to/configurations.json" # the path can be relative or absolute
configurations = ConfigFactory.get_conf(configurations_path, ConfigSchema)
configurations.api_key # to obtain 'your-api-key'
configurations.enpoints["ENDPOINT1"] # to obtain 'http://your-endpoint-1.com'
configurations.enpoints["ENDPOINT2"] # to obtain 'http://your-endpoint-2.com'
```