Skip to main content

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_services3_expressions.variants.Variant import Variant
from pip_services3_expressions.calculator.variables.Variable import Variable
from pip_services3_expressions.calculator.ExpressionCalculator import ExpressionCalculator
from pip_services3_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

Release files for pip-services3-expressions 3.3.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pip-services3-expressions 3.3.6
File Size Uploaded
pip_services3_expressions-3.3.6.tar.gz 52.8 kB Details

Release files / pip_services3_expressions-3.3.6.tar.gz

Download URL pip_services3_expressions-3.3.6.tar.gz
Size 52.8 kB
Tags Source
SHA-256 checksum
How to use checksums
aab65b830ec12707633bd1b896a897c3d828dda6c674463570f3ae07101807b3
BLAKE2b-256 checksum
How to use checksums
9aad9be8e5c5626099e1488947a69d30e7a6366c2a7dd09009d4e7bc7d8e6130
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

Release history Release notifications | RSS feed

This release

3.3.6 This release

1 release file

3.3.5

1 release file

3.3.4

1 release file

3.3.3

1 release file

3.3.2

1 release file

3.3.1

1 release file

3.3.0

1 release file

3.2.0

1 release file

3.1.0

1 release file

3.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page