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.1-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.1.tar.gz (16.2 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.1-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: masha-0.0.1.tar.gz
  • Upload date:
  • Size: 16.2 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.1.tar.gz
Algorithm Hash digest
SHA256 bdce999c09508b8df7607f82482fa4d3596d3492360fb999ceaa4c07dd88da45
MD5 7a975e98074e19f34745f970b7f7bd71
BLAKE2b-256 e625e467b11e57b4d180c2e3624e736fedde00c8f6b067b0c2644e16fd309f29

See more details on using hashes here.

File details

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

File metadata

  • Download URL: masha-0.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b95fc4f218555a43ef74cf5cc8a28a68595843bd890624eaf820dc78b9689090
MD5 4c90208b7dd6119862340b36a6f4dd91
BLAKE2b-256 5ca1969aeaa281d218a2a03c7be33d757f82b80efc68575190dbef555f56d862

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