Skip to main content

M(ath)YAML: evaluate math expressions in YAML files.

Project description

myaml

workflow License pypi

M(ath)YAML: evaluate math expressions in YAML files.

Install

pip install myaml

Usage

myaml allows you to define math expressions in YAML files:

# test.yaml
---
- x1:
    x: !eval 2**(3 - 1)
    y: !eval (12 % 9) - sqrt(9)
- x2:
    x: !eval (2**3) - 1.0
    y: !eval -0.75 ** (9 - cos(3.1415) * log(2.718))
- x3:
    x: hello world
    y: /this/is/a/path

Expressions annotated with !eval tag will be evaluated at load-time. Any other strings will be left intact:

>>> import myaml
>>> xs = myaml.safe_load('test.yaml')
>>> xs
[
    {'x1': {'x': 4, 'y': 0}},
    {'x2': {'x': 7, 'y': -0.056315}},
    {'x3': {
        'x': 'hello world',
        'y': '/this/is/a/path'
    }}
]

Notes

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

myaml-1.0.1.tar.gz (2.5 kB view hashes)

Uploaded Source

Built Distribution

myaml-1.0.1-py3-none-any.whl (6.8 kB view hashes)

Uploaded Python 3

Supported by

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