Skip to content

Repository files navigation

PyConfParser

PyConfParser is a secure and flexible Python library for parsing, validating, and managing configuration files.

Installation

You can install this library via pip:

pip install git+https://github.com/spuerta10/PyConfParser.git

Or install it via uv:

uv add git+https://github.com/spuerta10/PyConfParser.git

Usage

Basic Usage

Here is a quick example of how to use this library:

{
    "PASS": "some-content",
    "ENDPOINTS": {
        "ENDPOINT1": "http://your-endpoint-1.com",
        "ENDPOINT2": "http://your-endpoint-2.com"
    }
}

configurations.json

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.

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'

About

A secure and flexible Python library for parsing, validating, and managing configuration files (YAML, JSON, and more).

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages