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.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

masha-0.0.0.tar.gz (16.1 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.0-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

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

Hashes for masha-0.0.0.tar.gz
Algorithm Hash digest
SHA256 cf38e532cfd351aa120713399d536a00112ba025885048ac67b2fd5ea60a57fa
MD5 5e2af268a6146e723e638106ac327934
BLAKE2b-256 f441fe8dc3b9a0f40019c60553dd6a97346d71dc758ba2a6704ae45a948160f0

See more details on using hashes here.

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

Hashes for masha-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4d8de7155227fbc75206ca40ec941527ef7cf21cf913d661264731658f487b6c
MD5 220492a1860042369df96a73db7597f7
BLAKE2b-256 34bf2b139956e3d20161674b73b3957bd292c88b25d8524212f48bb24abc7520

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