Skip to main content

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

  • MASHA or Magnificient yASHA, is the name chosen, to show the amalgamation(MASHa UP) of my ideas and yasha tool. It has been inspired by these following magnificient tools or libraries:-
    • env-yaml-python helps in using ENV variable in the yaml configuration file.
    • j2yaml looks good tool to be used for having templates inside yaml configuration files.
    • cli_config_validator configuration validation.
    • yasha code 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:

  1. Clone the repository:

    git clone https://github.com/miteshbsjat/masha.git
    
  2. Navigate into the cloned directory:

    cd masha
    
  3. Install the package using setuptools:

    poetry shell
    poetry install
    poetry build
    pip3 install --force-reinstall dist/masha-0.0.2-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.

Sample 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

Basic 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

More Examples

More examples of masha usage are provided in examples.md.

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

masha-0.0.5.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

masha-0.0.5-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

Details for the file masha-0.0.5.tar.gz.

File metadata

  • Download URL: masha-0.0.5.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.13.1 Linux/6.11.0-1025-oem

File hashes

Hashes for masha-0.0.5.tar.gz
Algorithm Hash digest
SHA256 e9ad157043ca7adfdb68fda858e894cf72d99008d2fd09b86fa4527e7597b001
MD5 d3c4a6ed4c726f0559914b4e55f81dd0
BLAKE2b-256 2a019e980c20b03f42cf69077d0d065182309491315ba6c09b05ec4b8a28e860

See more details on using hashes here.

File details

Details for the file masha-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: masha-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 18.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.13.1 Linux/6.11.0-1025-oem

File hashes

Hashes for masha-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 9b22830ecd54e00a580a3b9ff59c45b4d6164c997f47cb6a4c725f53aa6c66e0
MD5 b043654d2b37a46a8965ff64dedfac5c
BLAKE2b-256 bef07fa304c876bfc7c3ebec04fa7cbd290a7097e837aaa50a3063c1b780769b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page