Metadata-Version: 2.1
Name: confoid
Version: 0.2.0
Summary: Configuration Management for Python.
Home-page: https://github.com/saviof-hub/confoid
Author: Savio Fernandes
Author-email: savio@saviof.com
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Operating System :: POSIX
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Requires-Python: >=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*
Description-Content-Type: text/markdown
Provides-Extra: dev
License-File: LICENSE

# Confoid

Configuration Management for Python.


[![image](https://img.shields.io/pypi/v/confoid.svg)](https://pypi.org/project/confoid/)
[![image](https://img.shields.io/pypi/pyversions/confoid.svg)](https://pypi.org/project/confoid/)
[![GitHub license](https://img.shields.io/github/license/saviof-hub/confoid.svg)](https://github.com/saviof-hub/confoid/blob/main/LICENSE)

[![GitHub Actions (Python package)](https://github.com/artbycrunk/hyper-prompt/workflows/Tests/badge.svg)](https://github.com/artbycrunk/hyper-prompt)

[![Average time to resolve an issue](https://isitmaintained.com/badge/resolution/saviof-hub/confoid.svg)](https://isitmaintained.com/project/saviof-hub/confoid "Average time to resolve an issue")
[![Percentage of issues still open](https://isitmaintained.com/badge/open/saviof-hub/confoid.svg)](https://isitmaintained.com/project/saviof-hub/confoid "Percentage of issues still open")


## Install

```bash
$ pip install confoid
```

## Loading a single config file

```py
import confoid

new_settings = confoid.Config("application.yml")
```

## Loading multiple  config file

Multiple files can be provided in `order` and will merge with the previous configuration.

```py
import confoid

config_files = ["application.yml", "application.development.yml"]

new_settings = confoid.Config(
    config_files, 
    base_dir="config",
)
```

## Autoload based on provided environment

```py
import confoid

new_settings = confoid.Config("application.yml", current_env="development")
# this will load application.yml and application.{current_env}.yml
```

## Reading the settings

```py
settings.username == "admin"  # dot notation with multi nesting support
settings['password'] == "secret123"  # dict like access
settings.get("nonexisting", "default value")  # Default values just like a dict
settings.databases.name == "mydb"  # Nested key traversing
```

## Config merging

application.yml
```yml
default:
  prefix:
    otp: "user-otp"
    auth: "auth-tokens"
  type: inmemory
  redis:
    url: 
```

application.development.yml
```yml
default:
  type: redis
  redis:
    url: redis://saviof.com
    encoding: "utf8"
```

Will resolve to the following final config

```yml
default:
  prefix:
    otp: "user-otp"
    auth: "auth-tokens"
  type: redis
  redis:
    url: redis://saviof.com
    encoding: "utf8"
```

## Config environment vars

All fields can use environment variables with a fallback default value
```yml
password: ${TEST_SERVICE_DEFAULT_PASSWORD:test}
```

## Validators can be added for pre checks on loaded config
```python
from confoid import Validator

config_files = ["application.yml", "application.development.yml"]

new_settings = confoid.Config(
    config_files, 
    base_dir="config",
    validators=[
        Validator("default", "default.redis.password", must_exist=True)
        Validator("otp.length", gte=6, lte=20)
        Validator("default.type", values=["inmemory", "redis"])
    ]
)
```
