Parse static files such as YAML and insert in them data from environment variables
Project description
python-pie
Python-pie(python insert env) parses static files such as YAML and insert in them data from environment variables
Getting Started
pip install python-pie
You can use python-pie to insert env variables to static configurations, like that:
from pie import process_file
filepath = '/docker/configuration.yaml'
process_file(filepath)
The syntax of files supported by python-pie is similar to that of python fstrings:
f"54 {from_env or 'default_value'} some text"
Depends if your environment has a from_env variable or not, python-pie will load it, or in case of absence take the default value
Syntax example
hosts:
- f"{host}"
loglevel: 4
f"{'log_file_path'}": f"/file/path/{filename or 'tmp.log'}"
log_rotate_count: 1
after process_file(filepath)
hosts:
- localohst
loglevel: 4
log_file_path: /file/path/tmp.log
log_rotate_count: 1
Using as module from command line
You can use python-pie in command line.
python -m pie -f /node54/config.yml
Flags: (you should provide at least one of those)
-f --filepath to config file.-s --stringstring to precess.
optional:
-tf --to-filepath to output config file.--keep-fileif pie should keep original file without change.
Docker example
docker create -t --name pie -i python:3.9 || true;
docker start pie;
docker exec pie python -m pip install python-pie;
docker exec pie python -m pie -f /node54/config.yml;
during build:
FROM python:3.9-alpine AS builder
RUN pip install python-pie
RUN python -m pie -f /tmp/template.yml -tf /app/config.yml -e .env
Run tests
To run tests install pytest library and run the command:
pytest tests/
Project details
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python-pie-0.2.4.tar.gz.
File metadata
- Download URL: python-pie-0.2.4.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8229e60ff3727610783c310c2c9b51604fcfffd37fcd7e876529583fda641d71
|
|
| MD5 |
44f8dd4c2130749a68f814688e05e052
|
|
| BLAKE2b-256 |
d9d8c974b3cad0517d35ad1907e24fb8c17d3df43fe8c93acd144b404fd9cbf6
|
File details
Details for the file python_pie-0.2.4-py3-none-any.whl.
File metadata
- Download URL: python_pie-0.2.4-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ade5120ea92e4128f492d0f28bdd8802a0a14d9c51fd64c3d08346daaee9185f
|
|
| MD5 |
4ff43cdfbc44bfb9213c8b341c9714bc
|
|
| BLAKE2b-256 |
9345dc0b78b4953eaa27a86e5174cfd4587e19413a952e7639f1ba92e5a1d713
|