Skip to main content

Gila

Gila is a python3 layered configuration library based very heavily on the viper config library for Go. It is designed to facilitate making 12 factor apps as easy as possible using python3.

Motivation

After having used the Viper config library in Go, I became very used to the ease of use and flexibility that it offered. After looking for a library to use in my python projects I was unable to find one that combined all of the very useful features that Viper supports.

Features

  • Allow default values to be set for each config key
  • Automatically find config files on multiple paths
  • Load in environment variables automatically that have a specific prefix
  • Support most popular config languages: yaml, toml, json, properties files, hcl, dotenv
  • Singleton pattern available for ease of use in most applications
  • Hierarchical loading for non-ambiguous results.

Installation

Requires python 3.6+

pip install gila

Simple Example

More examples can be found in the examples directory

import gila
from os import environ

# Setting default values for keys
gila.set_default('host', 'localhost:8080')
gila.set_default('allow_insecure', False)

# This will tell Gila to automatically load in ENV vars that start with GILA
gila.set_env_prefix('GILA')
gila.automatic_env()

# This would normally be done outside of program
# eg. in docker compose or k8s manifest
environ['GILA_HOST'] = 'localhost:9999'

# This is the preferred method of grabbing
# the configurations. Other methods exist (all_config, debug)
# but this method is the most performant for single
# value calls.
host = gila.get('host')
allow_insecure = gila.get('allow_insecure')

"""
Output:
Host: localhost:9999
Insecure allowed: false
"""
print(f'Host: {host}')
print(f'Insecure allowed: {allow_insecure}')

Supported Config Filetypes

  • yaml (.yaml, .yml)
  • json (.json)
  • toml (.toml)
  • hcl (.hcl)
  • environment variables
    • Values will be cast to strings
    • Keys are cast to lowercase: ENV_VAR -> gila.get('env_var')
  • properties file (.properties, .prop, .props)
    • Values will be cast to strings
  • dotenv (.env)
    • Values will be cast to strings
    • No nested values supported

Additional Help

Check out our documentation on ReadTheDocs or if you prefer minimum working examples, checkout the directory </examples/> which house a plethora of use cases from simple to more complex configurations.

Credits

Steve Francia spf13 for creating the Viper library

Authors of pyyaml, pyhcl, and toml packages, as Gila would have been much harder to create and maintain without them

Major differences from Viper

  • Case sensitivity - all keys in Gila are case sensitive, this allows for proper json, yaml, and toml support. ENV keys are not case sensitive unless manually bound.
  • No support for remote config - while I think that supporting consul and etcd is a very nice feature, I think at this moment in time that it is a feature that belongs in a seperate library.
  • No support for command flags - Viper relies pretty heavily on Cobra companionship for command flags. You should choose your own flavour of CLI parser (docopts, argparse, etc) and pair it with this library (check out our examples).
  • Watching for changes in config files - I would very much so like to add this feature, but it is not a feature that I felt was necessary at v1.0.0. If you would like this feature you can thumbs up the issue, or open a PR with an implementation.

Release files for gila 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for gila 0.5.0
File Interpreter ABI Platform
gila-0.5.0-py3-none-any.whl Python 3 none any Details

Release files / gila-0.5.0-py3-none-any.whl

Download URL gila-0.5.0-py3-none-any.whl
Size 15.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ad60bc37717d1c601333e67450e5fa9e554f9e3d7c4dd321ef803d7f56156d2c
BLAKE2b-256 checksum
How to use checksums
3ddc6c634e03acbf8adeb598f10298edcccb178924f14f2aba943f1091bb30c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.3.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.10

Release history Release notifications | RSS feed

This release

0.5.0 This release

1 release file

0.4.0

1 release file

0.3.0

1 release file

0.2.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page