Merges configuration from toml file and environment variables
Project description
Configula
Creates a single configuration by merging settings defined in: 1. in environment variables 2. in toml file
Values provided in environment variables have priority over values from toml configuration file.
By default all environment variables are prefixed with 'PAPERMERGE'.
By default __
(two underscores) is used as delimiter in environment variables
names. For example, given following toml file:
[main]
secret_key = 1234
[ocr]
default_language = 'deu'
corespondent environment variables names are PAPERMERGE__MAIN__SECRET_KEY and PAPERMERGE__OCR__DEFAULT_LANGUAGE - notice two underscores separate section name from prefix and variable name. Environment variable name format is (all in uppercase):
<prefix><delimiter><section_name><delimiter><variable_name>
Although in toml files you can place variable names outside sections, in Papermerge all variables must be placed in sections.
By default Configula looks up for following toml file:
- /etc/papermerge/papermerge.toml
- /etc/papermerge.toml
- papermerge.toml
If you have custom location (or custom file name), use PAPERMERGE__CONFIG
(notice double underscores) environment variable to point to it:
PAPERMERGE__CONFIG=/app/config/pm.toml
Installation
$ poetry add configula
Usage
from configula import Configula
config = Configula()
default_language = config.get('ocr', 'default_language')
secret_key = config.get('main', 'secret_key')
Where papermerge.toml
has the following content:
[main]
secret_key = 5432
[ocr]
default_language = 'deu'
Default language can be overwritten by environment
variable PAPERMERGE__OCR__DEFAULT_LANGUAGE
and secret_key can overwritten
by environment variable PAPERMERGE__MAIN__SECRET_KEY
If you want to read variable from a section use
configula.get(section, var_name, default_value)
method.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file configula-0.5.4.tar.gz
.
File metadata
- Download URL: configula-0.5.4.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.4 Linux/5.15.0-1041-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1d9d4f6dc48d024a4fcd0d5de2751cf1765ba9c9adeb0530c9ad1f8eed5cf79 |
|
MD5 | ed71c3a1a85df7e586586c7362927087 |
|
BLAKE2b-256 | 6bf4264ae6661d49eab4ab5e7a7571cf95fcfc0226316785525292b30124b74f |
File details
Details for the file configula-0.5.4-py3-none-any.whl
.
File metadata
- Download URL: configula-0.5.4-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.4 Linux/5.15.0-1041-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | acfb69fa1d86e40acec09c8822d518790f7d15ddfc0926939f1e40d2759234d8 |
|
MD5 | 4ad2d469d60c93f0fb2519337a57a431 |
|
BLAKE2b-256 | ffccda8d04e7a138bb4d7a64c2f32c2bc2fd145864311d34b2a1d9694f146e02 |