Skip to main content

Basic portable abstractions for Pip.Services in Python

Project description

Pip.Services Logo
Tokenizers, parsers and expression calculators in Python

This module is a part of the Pip.Services polyglot microservices toolkit. It provides syntax and lexical analyzers and expression calculator optimized for repeated calculations.

The module contains the following packages:

  • Calculator - Expression calculator
  • CSV - CSV tokenizer
  • IO - input/output utility classes to support lexical analysis
  • Mustache - Mustache templating engine
  • Tokenizers - lexical analyzers to break incoming character streams into tokens
  • Variants - dynamic objects that can hold any values and operators for them

Quick links:

Use

Install the Python package as

pip install pip-services3-expressions

The example below shows how to use expression calculator to dynamically calculate user-defined expressions.

from pip_services4_expressions.variants.Variant import Variant
from pip_services4_expressions.calculator.variables.Variable import Variable
from pip_services4_expressions.calculator.ExpressionCalculator import ExpressionCalculator
from pip_services4_expressions.calculator.variables.VariableCollection import VariableCollection

# ...

clalculator = ExpressionCalculator()

clalculator.expression = "A + b / (3 - Max(-123, 1)*2)"
vars = VariableCollection()
vars.add(Variable("A", Variant(1)))
vars.add(Variable("B", Variant(3)))

result = clalculator.evaluate_with_variables(vars)
print('The result of the expression is ' + result.as_string)
# ...

This is an example to process mustache templates.

mustache = MustacheTemplate()
mustache.template = "Hello, {{{NAME}}}{{#ESCLAMATION}}!{{/ESCLAMATION}}{{#unless ESCLAMATION}}.{{/unless}}"
result = mustache.evaluate_with_variables({ 'NAME': 'Mike', 'ESCLAMATION': True }) 
print("The result of template evaluation is '" + result + "'")

Develop

For development you shall install the following prerequisites:

  • Python 3.7+
  • Visual Studio Code or another IDE of your choice
  • Docker

Install dependencies:

pip install -r requirements.txt

Run automated tests:

python test.py

Generate API documentation:

./docgen.ps1

Before committing changes run dockerized build and test as:

./build.ps1
./test.ps1
./clear.ps1

Contacts

The module is created and maintained by:

  • Sergey Seroukhov
  • Danil Prisiazhnyi

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

pip_services4_expressions-0.0.3.tar.gz (52.7 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file pip_services4_expressions-0.0.3.tar.gz.

File metadata

File hashes

Hashes for pip_services4_expressions-0.0.3.tar.gz
Algorithm Hash digest
SHA256 fc7bc5015cbb773eefba1a991a03cd8cb5e26f3cdba8a9f4dfd9cd08c970b19b
MD5 5c5e64a5859d2c49d0fa3a7331e4a442
BLAKE2b-256 76be1b50c188cefbb3c8a5864a1a8af05c3987dc773193eb9e481f63a144e9be

See more details on using hashes here.

File details

Details for the file pip_services4_expressions-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for pip_services4_expressions-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f2f96b6475de00dd600040e8cf2e31ad28c0ae33bb3ab4036bb7aba39a470128
MD5 1124b0dc173f29a90cc613ec30956db4
BLAKE2b-256 2851e1b2593051a4a762186e53e05d30ba4689d054de514b117b5820a540e556

See more details on using hashes here.

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