MASHup of Configuration Loading from several file types and run yAsha like Jinja2 template rendition with Validation
Project description
MASHA
MASHup of Configuration Loading from several file types and run yAsha like Jinja2 template rendition with Validation.
Motivation
MASHAorMagnificient yASHA, is the name chosen, to show the amalgamation(MASHa UP) of my ideas andyashatool. It has been inspired by these following magnificient tools or libraries:-env-yaml-pythonhelps in using ENV variable in the yaml configuration file.j2yamllooks good tool to be used for having templates insideyamlconfiguration files.cli_config_validatorconfiguration validation.yashacode generation tool based on jinja2 template rendition.
| MASHA (name) is inspired from Cartoon Series Masha and Bear. Like in this cartoon, a girl named `Masha` plays with the bear name `Mishka`, similarly, my daughter named `Diyanjali` plays with her father named `Mitesh` (i.e. me). :) The Masha logo is combination of Masha (the girl) and Yasha (the Katana Sword). |
Installation
You can install masha via pip. Ensure you have Python 3.10 or later installed on your system:
pip install masha
Alternatively, if you prefer to install from the source code (requires poetry), follow these steps:
-
Clone the repository:
git clone https://github.com/miteshbsjat/masha.git
-
Navigate into the cloned directory:
cd masha
-
Install the package using setuptools:
poetry shell poetry install poetry build pip3 install --force-reinstall dist/masha-0.0.0-py3-none-any.whl --user
Usage
masha help
$ masha --help
Usage: masha [OPTIONS] INPUT_FILE
Validate merged configurations against a Pydantic model and render an input
template.
Options:
-v, --variables FILE Path(s) to the various configuration files.
[required]
-m, --model-file FILE Path to the Python file containing the
Pydantic model class.
-c, --class-model TEXT Name of the Pydantic model class to validate
against.
-f, --template-filters-directory DIRECTORY
Directory containing custom Jinja2 filter
functions.
-t, --template-tests-directory DIRECTORY
Directory containing custom Jinja2 test
functions.
-o, --output FILE Path to the output file where the rendered
content will be written. [required]
--help Show this message and exit.
Basic Usage
To use masha, you can run it from the command line with various options to load configuration files and render templates.
masha -v test/config-a.yaml -v test/config-b.yaml \
-m test/model.py -c ConfigModel \
-f masha/filters -t masha/tests \
-o /tmp/demo.txt \
test/input.txt.j2
Advanced Usage
Specifying Multiple Configurations
You can load multiple configuration files which will be merged together:
masha -v config1.yaml -v config2.json -o result.txt advanced_template.j2
Using Environment Variables
masha also supports environment variables to override or extend configurations:
in env_example.j2 file This came from env MY_VAR = ${MY_VAR:some_default_value}
export MY_VAR="some_value"
masha -v default_config.yaml --output env_output.txt env_example.j2
output
This came from env MY_VAR = some_value
Example Configuration File (config.yaml)
Here is an example configuration file in YAML format:
app:
name: MyApplication
version: 1.0.0
database:
host: localhost
port: 5432
username: user
password: pass
Example Template File (template.j2)
Here is a simple Jinja2 template file:
Welcome to {{ app.name }} version {{ app.version }}!
Database configuration:
- Host: {{ database.host }}
- Port: {{ database.port }}
- Username: {{ database.username }}
- Password: {{ database.password }}
Output
Running the command with the above example files would produce an output file (output.txt) like this:
Welcome to MyApplication version 1.0.0!
Database configuration:
- Host: localhost
- Port: 5432
- Username: user
- Password: pass
License
This project is licensed under the Apache License 2.0.
Contributing
If you would like to contribute to this project, please check out our contributing guidelines.
Issues
For any issues or bug reports, please open an issue in our issue tracker.
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 masha-0.0.0.tar.gz.
File metadata
- Download URL: masha-0.0.0.tar.gz
- Upload date:
- Size: 16.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.5 CPython/3.13.2 Linux/5.15.0-56-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf38e532cfd351aa120713399d536a00112ba025885048ac67b2fd5ea60a57fa
|
|
| MD5 |
5e2af268a6146e723e638106ac327934
|
|
| BLAKE2b-256 |
f441fe8dc3b9a0f40019c60553dd6a97346d71dc758ba2a6704ae45a948160f0
|
File details
Details for the file masha-0.0.0-py3-none-any.whl.
File metadata
- Download URL: masha-0.0.0-py3-none-any.whl
- Upload date:
- Size: 18.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.5 CPython/3.13.2 Linux/5.15.0-56-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d8de7155227fbc75206ca40ec941527ef7cf21cf913d661264731658f487b6c
|
|
| MD5 |
220492a1860042369df96a73db7597f7
|
|
| BLAKE2b-256 |
34bf2b139956e3d20161674b73b3957bd292c88b25d8524212f48bb24abc7520
|