Skip to main content

Loading configurations from multiple sources into a data model.

Project description

Confident

Confident helps you create configuration objects from multiple sources of variables such as files and environment variables.
Confident configuration objects are data models that enforce validation and type hints by using pydantic library.

Example

import os

from confident import Confident


# Creating your own config class by inheriting from `Confident`.
class MyAppConfig(Confident):
    name: str
    port: int = 5000
    host: str = 'localhost'


# Illustrates some environment variables.
os.environ['name'] = 'my_name' 
os.environ['host'] = '127.0.0.1'

# Creating the config object. `Confident` will insert the values of the properties.
config = MyAppConfig()

print(config.name)
#> my_name
print(config.json())
#> {"name": "my_name", "port": 5000, "host": "127.0.0.1"}
print(config)
#> name='my_name' port=5000 host='127.0.0.1'
print(config.get_full_details())
#> {'name': ConfigProperty(name='name', value='my_name', value_type=<class 'str'>, source_name='environment', source_type=<ConfigSource.environment: 'environment'>),  
#> 'host': ConfigProperty(name='host', value='127.0.0.1', value_type=<class 'str'>, source_name='environment', source_type=<ConfigSource.environment: 'environment'>),  
#> 'port': ConfigProperty(name='port', value=5000, value_type=<class 'int'>, source_name='class_default', source_type=<ConfigSource.class_default: 'class_default'>)} 

Installation

pip install confident

Capabilities

Confident object can load config fields from multiple sources:

  1. Environment variables.
  2. Config files such as 'json' and 'yaml'.
  3. '.env' files.
  4. Explicitly given fields in the constructor level.
  5. Default values.

Confident object core functionality is based on pydantic library. That means the Confident config object has all the benefits of pydantic's BaseModel including Type validation, object transformation and many more features.

Usage

Load Config files

Contributing

To contribute to Confident, please make sure that any new features or changes to existing functionality include test coverage.

Creating Distribution

Build the distribution:
python3 setup.py sdist

Upload to pypi:
twine upload dist/*

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

confident-0.0.4.tar.gz (5.8 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page