Skip to main content

Loading configurations from multiple sources into a data model.

Project description

Confident

PyPI - Python Version PyPI GitHub Actions Workflow Status GitHub Coverage

Documentation


Confident helps you create configuration objects from multiple sources such as files, environment variables and maps. Confident's BaseConfig class is a data model that enforces validation and type hints by using pydantic library.

With Confident you can manage multiple configurations depending on the environment your code is deployed in. While having lots of flexibility in 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.model_dump_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

pip install confident

Capabilities

Customized Fields Loaders

Built-in loaders:

  • Environment variables.
  • Config files such as 'json' and 'yaml'.
  • Config maps to load fields depending 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 serialization 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


Download files

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

Source Distribution

confident-2.0.0.tar.gz (90.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

confident-2.0.0-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file confident-2.0.0.tar.gz.

File metadata

  • Download URL: confident-2.0.0.tar.gz
  • Upload date:
  • Size: 90.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for confident-2.0.0.tar.gz
Algorithm Hash digest
SHA256 0301e99c2fa0b54975c75340dea975ef391fe19dbd6c338420c1c24456c28863
MD5 67774ef5d09fcdbac9d0b2c8bacb93e1
BLAKE2b-256 a6f62134002f83265287243d5b7ca7d1acc12a8162829076d2f6ea39b9c25ac2

See more details on using hashes here.

File details

Details for the file confident-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: confident-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 16.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for confident-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8de5dd26f00cd910319b7ebfe9ab6d64c4d9d676c6fc2ab94deca7e15323a024
MD5 78ae67dfc481b1ea821619841c17a629
BLAKE2b-256 6d77098a4f5edc954edd05d1fcf9dab32a513365758810779a7ffe6aa80c2c34

See more details on using hashes here.

Supported by

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