Piny: envs interpolation for config files

PyPI Codecov MIT License

Piny is YAML config loader with environment variables interpolation for Python.

  • Keep your app’s configuration in a YAML file.

  • Mark up sensitive data in config as environment variables.

  • Set environment variables on application deployment.

  • Let Piny load your configuration file and substitute environment variables with their values.

Piny is developed with Docker and Kubernetes in mind, though it’s not limited to any deployment system.

Simple example

Set your environment variables, mark up your configuration file with them:

db:
  login: user
  password: ${DB_PASSWORD}
mail:
  login: user
  password: ${MAIL_PASSWORD:-my_default_password}
sentry:
  dsn: ${VAR_NOT_SET}

Then load your config with Piny:

from piny import YamlLoader

config = YamlLoader(path="config.yaml").load()
print(config)
# {'db': {'login': 'user', 'password': 'my_db_password'},
# 'mail': {'login': 'user', 'password': 'my_default_password'},
# 'sentry': {'dsn': None}}

CLI utility

Piny’s also got a command line tool working both with files and standard input and output:

$ export PASSWORD=mySecretPassword
$ echo "db: \${PASSWORD}" | piny
db: mySecretPassword

Rationale

Piny allows you to maintain healthy security/convenience balance when it comes to application’s configuration. Piny combines readability and versioning you get when using config files, and security that environment variables provide.

Read more about this approach in the blog post.

Misc