Skip to main content

Boolean Expressions Interpreter

Project description

Booleano is an interpreter of boolean expressions, a library to define and run filters available as text (e.g., in a natural language) or in Python code.

stable branche

https://img.shields.io/travis/Yupeek/booleano/master.svg https://readthedocs.org/projects/booleano/badge/?version=latest https://coveralls.io/repos/github/Yupeek/booleano/badge.svg?branch=master Latest PyPI version Number of PyPI downloads per month Code Climate

development status

https://img.shields.io/travis/Yupeek/booleano/develop.svg https://coveralls.io/repos/github/Yupeek/booleano/badge.svg?branch=develop

In order to handle text-based filters, Booleano ships with a fully-featured parser whose grammar is adaptive: Its properties can be overridden using simple configuration directives.

On the other hand, the library exposes a pythonic API for filters written in pure Python. These filters are particularly useful to build reusable conditions from objects provided by a third party library.

TLDR;

a string + some variable = safe boolean evaluation

# is this character a minor guy with a "0" in his name and born after 1983 ?
eval_boolean(
    'age < const:majority & "o" in name & birthdate > "1983-02-02"',
    {"name": "sokka", "age": 15, "birthdate": datetime.date(1984, 1, 1)},
    {'majority': 18},
    grammar_tokens={'belongs_to': 'in'}
) => True

The Fun Use Case

Booleano allow to safely evaluate an expression into something usable.

  • user:name is "john" and user:surname in {"doe", "shepard"}

+``{“user”: {“name”: “katara”}}`` => False +``{“user”: {“name”: “john”, “surname”: “doe”}}`` => True

with some code, you can provide any type you want, and the expression can still be in text:

+``user:birthdate > “03-07-1987”`` +``duration > 1m30s``

check the sample dirrectory to view more running examples !

Documentation

The full documentation is at http://django-rest-models.readthedocs.org/en/latest/.

Contribute

this project was not created by the current maintainer. in fact, the knowlege of this project from us is fare from perfect, but with 100% of test coverages, it’s not hard to keep it running.

if you find a bug, or want some feature, feel free to create a issues, or a Pull Request, but keep in mind that it can be hard for us to work on it. the best way to have it fixed, it’s to write a Pull Request with passing tests, and we will merge it if it’s a good piece of code.

see CONTRIBUTING.rst to know how work with ease on this project.

Upgrade Note

the old alpha release 1.0a1 is not compatible with newer version (starting with 1.1a1) because of heavy import path changes. all import from the modules (__init__.py) is discouraged.

Credit

forked from Gustavo Narea’s booleano project on launchpad.net.

maintened by yupeek

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

booleano-1.1a1.tar.gz (35.6 kB view details)

Uploaded Source

Built Distribution

booleano-1.1a1-py2.py3-none-any.whl (54.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file booleano-1.1a1.tar.gz.

File metadata

  • Download URL: booleano-1.1a1.tar.gz
  • Upload date:
  • Size: 35.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for booleano-1.1a1.tar.gz
Algorithm Hash digest
SHA256 f27c2769245bd7db006a7f859750e68a3a20328e4c2f637dff5cbb9da575cb9d
MD5 5d4fa8cfb5d2ee62962a50b7cffd2ff0
BLAKE2b-256 96bfe485f150fa7aedc9405f1ad2a703276ccb81f379fe8fe76d0e9e41543bb1

See more details on using hashes here.

File details

Details for the file booleano-1.1a1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for booleano-1.1a1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9465e35ee79ed6b8cd78b87f0fdcfa113c19d544c6ef1c887dd9729182154249
MD5 1f62c03655aec963ec18a1de9e0426d9
BLAKE2b-256 e8c40ca78efccedefd2eb9eb3b2b335d881049a96d29a3cc21c629e394bb7407

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