| Crates.io | logics-rs |
| lib.rs | logics-rs |
| version | 0.1.1 |
| created_at | 2025-03-26 18:45:40.968805+00 |
| updated_at | 2025-03-26 18:49:26.646313+00 |
| description | Logics is a user-friendly formula language with a subset of Python's expression syntax |
| homepage | |
| repository | https://github.com/viur-framework/logics |
| max_upload_size | |
| id | 1606930 |
| size | 15,309 |
Logics is a formula language with the aim of flexibly implementing programmable logics such as conditions, calculations or validations, so that developers as well as administrators and experienced users can use such expressions within a framework specified by the system to influence, calculate or otherwise dynamically adapt certain processes of a system.
The language can be compared to Excel's formula language, where expressions can be defined based on variables and calculated dynamically. But Logics has a Python-like syntax at this point, but provides its own semantics, so that numbers and strings, for example, can be directly linked, None-values are assumed as 0, and Exceptions are generally not raised during execution.
In addition, Logics provides a sandbox environment, which does not allow potential attackers to break out of the provided environment or slow down the system. There are appropriate security mechanisms integrated into the language for this purpose.
Logics has been developed at Mausbrand Informationssysteme GmbH as part of the ViUR ecosystem, but it is a standalone project that can also be used outside the ViUR context.
Previous uses of Logics included
Since Logics is used on both the client and server side, the language was made available in two separate implementations.
Both packages are stand-alone without any further dependencies. They are both under recent development and stable until a specific degree right now. They are maintained in separate version numbers, which is planned to be changed soon, when they become almost feature-complete.
Using Logics in JavaScript:
// npm install logics-js
import Logics from "logics-js";
let logics = new Logics("a + 2 * 3 + b");
console.log(logics.run({a: 1, b: "-Logics"}).toString()); // "7-Logics"
Using Logics in Python:
# pip install logics-py
from logics import Logics
logics = Logics("a + 2 * 3 + b")
print(logics.run({"a": 1, "b": "-Logics"})) # "7-Logics"
+, -, ~, not+, *, -, /, //, **==, !=, <>, <, <=, >, >=, in, not inand, ory if x else z[x for x in y if z]x[:]x[y]# comments in separate linesNoneTrue, Falseint, float, strlist for lists (similar to arrays)dict for dicts (similar to structured objects)Logics vs. PythonLogics does look like Python, but it isn't Python!
It differs both in syntax and semantics:
dict.keys() is keys(dict) in Logics";".join(["a", "b", "c"]) is join(["a", "b", "c"], ";") in LogicsNoneNone"#ERR: Division by zero""42" ** 3 produces 74088, and not a TypeError.Logics is built using the UniCC LALR(1) Parser Generator, which supports generating parsers in multiple target languages. UniCC should be compiled from source, as the latest version 1.9+ is required.
Whenever something is changed on the syntax, ensure unicc is installed properly and run make, which regenerates the parser modules.
Logics-related test cases are placed as *.lgx-files into the tests/ folder. They are shared by both implementations.
# In lgx-files, variables can be set using `#set:` as shown below.
# The part behind the second colon may contain any logics expression, including variables.
#set:x:6 * 7
#
# To verify if an expression produces an expected result, provide the expression followed by an `#expect:`.
#
x
#expect:42
x * x
#expect:1764
To format the source code, use prettier as follows:
cd logics-js
npm run fmt
Tests are implemented using Mocha:
cd logics-js
npm test
Publish on npmjs.com:
cd logics-js
npm publish
To format the source code, use Black as follows:
cd logics-py
pipenv run fmt
Tests are implemented using pytest:
cd logics-py
pipenv run test
Publish on PyPI:
cd logics-py
pipenv install --dev
pipenv run build
pipenv run publish
pipenv run clean
pipenv --rm
Copyright © 2025 by Mausbrand Informationssysteme GmbH.
Mausbrand and ViUR are registered trademarks of Mausbrand Informationssysteme GmbH.
Logics is free software under the MIT license.
Please see the LICENSE file for details.