Package: gamma-config
Gamma ConfigAn opinionated way of setting up configuration for data science projects.OverviewGamma config provides a standard and flexible way of implementing application
configuration primarily based on YAML files. It promotes best practices by:simplify separation of code and config data;breaking large, complex configuration into multiple files;providing a way to write environment-aware config files;facilitating security best-practices, like proper secrets management;providing a immutable central global object storingallcontextual data.Another benefit of a standard config mechanism is allowing Gamma extension
libraries to provide configuration in a common way.FeaturesConfiguration expressed as a set of YAML files (by defaul) inside aconfigfolder in the root of the project.Multiple YAML files merged following simple rules. Simple file ordering convention
using two digit prefixes.Builtin support for environment specific parameters (production, development, etc.)Support for.envfiles viapython-dotenv, including.local.envthat
can be added to.gitignoreDynamic evaluation via YAML tags. For instance, the!reftag allow you to
reference other parameters in any config file.Custom tag support via simple and cool multiple dispatch mechanism.Round-trip dump of config back into YAML. Support for hiding sensitive data
on dump.Simplified key access via dot (.). Eg. forconfig: {foo: {bar: 100}},
this is True:config.foo.bar == 100Click here to view the full documentationGetting startedUsing pip:pipinstallgamma-configIn most cases, you'll want to use the!j2tag to interpolate values using Jinja2.
This requires manually installing thejinja2package or using thejinja2extras.pipinstallgamma-config[jinja2]You must installpydanticif using thestructured configurationfeature.pipinstallgamma-config[pydantic]Basic UsageThe package comes with "scaffolding" to help you get started. In your project folder:python-mgamma.config.scaffoldRemove the sample files, then create yourself aconfig/20-myconfig.yamlfile
with the contents:foo:1user:!envUSERTo access the config from within your Python program:importosfromgamma.configimportget_configdefrun():# it's safe and efficient to call this multiple timesconfig=get_config()# get static value using the dict keys or attribute accessassertconfig["foo"]==1assertconfig.foo==1# get dynamic variablesassertconfig["user"]==os.getenv("USER")assertconfig.user==os.getenv("USER")Most of the magic happen via tags. Look at the documentation for info on thebuilt-in tagsavailable.ChangelogBreaking in 0.8WeDEPRECATED!pyand!objtags, replacing them by the cleaner/simpler!calltag. Those are schedule to be removed by release 1.0.WeDEPRECATED"Structured configuration" support, We recommend directly usingPydantic's V2 discriminated unionsas an alternative.By default,!env,!exprand!callwill not dump the contents on ato_yamlcall. We provide!env:dump,!expr:dump,!call:dumpto force dumping. Tag!env_secretis still supported but use is discouraged.We have!j2:secretin addition to!j2_secretfor consistency. Use of!j2_secretis discouraged.Breaking in 0.7We'veDEPRECATEDour homegrown multiple dispatch systemgamma.dispatch,
replacing it byplum. Unless you were usinggamma.dispatchdirectly, or
extending viacustom tags, no need to worry. Thegamma.dispatchpackage will be removed by release 1.0.New in 0.7We have a new home inhttps://github.com/cjalmeida/gamma-config!Breaking in 0.6Strict support forYAML 1.2 Core Schema.
In practice, unquoted ISO8610 dates (eg.2022-12-20) won't get converted
todatetime.dateordatetime.datetimeobjects. Use!dateor!datetimeif needed..envfiles are loaded automatically and get precedence overconfig.envandconfig.local.env.Use ofconfig.envandconfig.local.envis deprecated.Default scaffoldedinclude_folderinterpretENVIRONMENTvariable string likefoo baras two separate environment subfolders.(dispatch)Valarguments passed as class (eg.foo(Val['bar'])) will be converted
to instance, as if it were calledfoo(Val['bar']())The!py:<module>:<func>will no longer a singleNoneargumentNew in 0.6Support forYAML Anchors and AliasesBreaking changes in 0.5When using the dot (.) syntax, missing values raiseAttributeErrorinstead of returning
a false-y object.Dropped support for Python 3.7New in 0.5We're now in PyPI!Options for installing extra dependencies (eg.jinja2,pydantic)