Skip to main content

Configuration Management for Python.

Project description

Confoid

Configuration Management for Python.

image image GitHub license

GitHub Actions (Python package)

Average time to resolve an issue Percentage of issues still open

Install

$ pip install confoid

Loading a single config file

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.

import confoid

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

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

Autoload based on provided environment

import confoid

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

Reading the settings

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

default:
  prefix:
    otp: "user-otp"
    auth: "auth-tokens"
  type: inmemory
  redis:
    url: 

application.development.yml

default:
  type: redis
  redis:
    url: redis://saviof.com
    encoding: "utf8"

Will resolve to the following final config

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

password: ${TEST_SERVICE_DEFAULT_PASSWORD:test}

Validators can be added for pre checks on loaded config

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"])
    ]
)

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

confoid-0.2.0.tar.gz (9.7 kB view details)

Uploaded Source

File details

Details for the file confoid-0.2.0.tar.gz.

File metadata

  • Download URL: confoid-0.2.0.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for confoid-0.2.0.tar.gz
Algorithm Hash digest
SHA256 185c77b98d54567ac71f8d71a79ff1c989c8548446d37e5483b5d1a2c36e0804
MD5 3ae774eb1a0abeccfd1e5ea3dc3f6bf3
BLAKE2b-256 0a1d932f45670f6108bff2df778e94fff07dc04e203be11c2b0aab8e3641c289

See more details on using hashes here.

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