Package: configur8
configur8Python type-safe configuration and validation library.IntroductionConfiguration validation is a common problem in Python. This library aims to
provide a simple, type-safe way to validate configuration either by file or
environment variables.An example:/path/to/config.yaml:mysql:host:localhostport:3306user:not_rootpassword:my_passwordimportconfigur8fromconfigur8importenvclassMySQL:# define the fields and their typeshost:str# default values are supportedport:int=3306# default values can programmatically be defined, e.g. from an env varuser:str=env.str("MYSQL_USER","definitely_not_root")password:strclassConfig:mysql:MySQLconfig=configur8.load(Config,"/path/to/config.yaml")assertisinstance(config.mysql,MySQL)# TrueThe above example will load the configuration from the file at/path/to/config.yamland validate it against theConfigclass. If the
configuration is invalid, an exception will be raised.Environment onlyAn example:fromconfigur8importenvSECRET_KEY=env.str("SECRET_KEY")NUM_WORKERS=env.int("NUM_WORKERS",2)DEBUG=env.bool("DEBUG",False)In the example above:SECRET_KEYis a required environment variable - attempting execute the
code without it defined will result in an exception. This is typically what
you want so that apps and services don't start in an unintended state.NUM_WORKERSwill be parsed into an integer. If the env var is not
defined,2will be used as a default. If a non integer value is parsed,
an error will be raised.DEBUGis a boolean with a default ofFalse. "Truthy" values can be
used, e.g. "on", "1", etc.Everything is designed to be type safe.Types of values supportedString -env.strInteger -env.intFloat -env.floatBoolean -env.boolUrl -env.urlPath -env.pathEmail -env.email- Validation provided byemail-validatorEach type can support optional values and work with lists:fromconfigur8importenvALLOWED_HOSTS=env.url.list("ALLOWED_HOSTS")Given the environment:ALLOWED_HOSTS=http://localhost,http://my-staging-serverThe python value ofALLOWED_HOSTSwould be:["http://localhost","http://my-staging-server"]Boolean flagsBoolean values are supported. Seeconfigur8.env.BOOLEAN_TRUTHY_VALUES:true1onyesokWill all result in aTruePython value. Anything else will result inFalse.UrlsThese are augmented objects that have extra attributes in case you need them:fromconfigur8importenv# https://my-bucket.s3.us-west-2.amazonaws.combucket=env.url("S3_BUCKET_URL")assertbucket.protocol=="https"assertbucket.host=="my-bucket.s3.us-west-2.amazonaws.com"There are a bunch more properties - seeconfigur8.url.Url.PathsThese are augmented objects that have extra attributes in case you need them:fromconfigur8importenv# /var/run/secrets/my-mounted-volume/my-secretmy_creds=env.path("SERVICE_CREDS").read()# my_creds will hold the contents of the file in the env varDevelopmentInstall PDMInstall TaskRunning teststasktestPublishing to PyPINOTEReplace__VERSION__with a semver identifier such as0.9.3Ensure that you are on a clean master.Update__version__insrc/configur8/__about__.pyto__VERSION__.UpdateCHANGELOG.mdwith the new version and changes.gitaddsrc/configur8/__about__.pyCHANGELOG.md
gitcommit-m"Bump to __VERSION__"gittagv__VERSION__
gitpushorigin--tagsWait for Github Actions to succeed and publish the library to the public PyPI.