Metadata-Version: 2.1
Name: px-formula
Version: 0.1.0
Summary: Simple formula evaluator.
Home-page: UNKNOWN
Author: Alex Tkachenko
Author-email: preusx.dev@gmail.com
License: MIT License
Platform: UNKNOWN
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Programming Language :: Python :: 3
Classifier: Intended Audience :: Developers
Classifier: Topic :: Utilities
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.6
Description-Content-Type: text/markdown
Provides-Extra: dev
License-File: LICENSE

# Formula

Simple formula-like expression solver.

Parses formula into a reverse polish notation. Evaluates parsed to get result.

## Installation

```sh
pip install px-formula
```

## Usage

Uou can calculate formulas with different operators, and function calls. But it's not a python code, that executes - only simple maths expressions.

```python
from px_formula import Formula, defaults


formula = Formula(
  # Can change operators:
  operators=defaults.operators,
  # And available functions:
  functions=defaults.functions,
)

parsed = formula.parse('2/8+45*6+var1')
# > ['2', '8', '/', '45', '6', '*', '+', 'var1', '+']

# You can evaluate any formula you have/stored easily:
formula.evaluate(parsed, {'var1': 5})
# > 275.25

# Or in one shot:
formula('2/8+abs(45*6)+var1', {'var1': 5})
# > 275.25
```

### Supported

Operators:

- **`~`** - Inverse
- **`!`** - Not
- **`**`** - Pow
- **`*`** - Multiply
- **`/`** - Divide
- **`//`** - Floor divide
- **`%`** - Modulo
- **`+`** - Plus
- **`-`** - Minus
- **`|`** - Bitwise Or
- **`&`** - Bitwise And
- **`^`** - Bitwise Xor
- **`<=`** - LTE
- **`>=`** - GTE
- **`==`** - Equals
- **`<`** - LT
- **`>`** - GT

Functions:

- **`abs`** - operator.abs
- **`sin`** - math.sin
- **`cos`** - math.cos
- **`tan`** - math.tan
- **`exp`** - math.exp
- **`abs`** - abs
- **`trunc`** - Removes decimal part
- **`round`** - round
- **`hypot`** - math.hypot
- **`all`** - all(True, False, True) -> False
- **`any`** - any(True, False, False) -> True# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.1.0]
Initial version.


