Loading configurations from multiple sources into a data model.
Project description
Confident
Confident helps you create configuration objects from multiple sources such as files, environment variables and maps.
Confident BaseConfig class is a data model that enforce validation and type hints by using pydantic library.
With Confident you can manage multiple configurations depends on the environment your code is deployed. While having lots of flexibility how to describe your config objects, Confident will provide visibility of the process and help you expose misconfiguration as soon as possible.
Example
import os
from confident import BaseConfig
# Creating your own config class by inheriting from `BaseConfig`.
class MyAppConfig(BaseConfig):
port: int = 5000
host: str = 'localhost'
labels: list
# Illustrates some environment variables.
os.environ['host'] = '127.0.0.1'
os.environ['labels'] = '["FOO", "BAR"]' # JSON strings can be used for more types.
# Creating the config object. `BaseConfig` will load the values of the properties.
config = MyAppConfig()
print(config.host)
# > 127.0.0.1
print(config.json())
# > {"port": 5000, "host": "127.0.0.1", "labels": ["FOO", "BAR"]}
print(config)
# > port=5000 host='127.0.0.1' labels=['FOO', 'BAR']
print(config.full_fields())
# > {
# 'port': ConfigField(name='port', value=5000, origin_value=5000, source_name='MyAppConfig', source_type='class_default', source_location=PosixPath('~/confident/readme_example.py')),
# 'host': ConfigField(name='host', value='127.0.0.1', origin_value='127.0.0.1', source_name='host', source_type='env_var', source_location='host'),
# 'labels': ConfigField(name='labels', value=['FOO', 'BAR'], origin_value='["FOO", "BAR"]', source_name='labels', source_type='env_var', source_location='labels')
# }
Installation
(.venv) $ pip install confident
Capabilities
Customized Fields Loaders
Built-in loaders:
- Environment variables.
- Config files such as 'json' and 'yaml'.
- Config maps to load fields depends on the environment. (See documentation)
It is possible to configure the loading priority and add your own loader classes.
Full Support of Pydantic BaseSettings
Confident core functionality is based on pydantic library.
That means BaseConfig
object has all the benefits of pydantic's BaseModel
and BaseSettings
including type validation, object transformation and many more features.
Config Loading visibility
BaseConfig
object stores details about the fields loading process and offers ways to understand the source of each loaded field.
Details about the origin value (before conversion), the location of the source and the type of loader, can all be accessed from the object.
Examples
More examples can be found in the project's repository.
Contributing
To contribute to Confident, please make sure any new features or changes to existing functionality include test coverage.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file confident-0.2.6.tar.gz
.
File metadata
- Download URL: confident-0.2.6.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.10.5 Linux/5.13.0-1031-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 432daf378cdd4d7838fae59db975a6e3b791bda1776bc3592cc4b198a9741edc |
|
MD5 | 5429c7ab204cf468b532060875e4925c |
|
BLAKE2b-256 | 7650cb21ac47f73741868f66e68f15df0e4780d66604ce0096e416418414ccaf |
File details
Details for the file confident-0.2.6-py3-none-any.whl
.
File metadata
- Download URL: confident-0.2.6-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.10.5 Linux/5.13.0-1031-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29339d6f8061675fe7d26492750ae025e2596f4a6c3381393a00e46f5e8eb532 |
|
MD5 | aa9c09a516d28532d230bcd8d4a86edd |
|
BLAKE2b-256 | 790a8526ed61439ffbeb09c2656251575bccba5a10843358ece73e00d474283d |