Skip to main content

Built-in functions, types, exceptions, and other objects.

Project description

Package to evaluate logical tag expressions by using a modified version of the Shunting Yard algorithm. This package is a Python port of cucumbers tag expression.

It’s also used by radish.

Build Status PyPI package version PyPI python versions

Installing

$ pip install tag-expressions

Here is a tease

>>> from tagexpressions import parse
>>>
>>> expression = '( a and b ) or ( c and d )'
>>> compiled_expression = parse(expression)
>>> print(compiled_expression)
( ( a and b ) or ( c and d ) )
>>>
>>> data = ['a', 'b', 'c', 'd']
>>> assert compiled_expression.evaluate(data) == True
>>>
>>> data = ['a', 'c']
>>> assert compiled_expression.evaluate(data) == False
>>>
>>>
>>> expression = 'not a or b and not c or not d or e and f'
>>> compiled_expression = parse(expression)
>>> print(compiled_expression)
( ( ( not ( a ) or ( b and not ( c ) ) ) or not ( d ) ) or ( e and f ) )
>>>
>>> data = ['b', 'e', 'f']
>>> assert compiled_expression.evaluate(data) == True
>>>
>>> data = ['a', 'c', 'd']
>>> assert compiled_expression.evaluate(data) == False

Usage

Available operators

  • or - “or” conjunction of two given variables

  • and - “and” conjunction of two given variables

  • not - negation of a single variable

Every other token given in an infix is considered a variable.

Operator precedence

From high to low:

  • ()

  • or

  • and

  • not

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tag_expressions-2.0.1.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

tag_expressions-2.0.1-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file tag_expressions-2.0.1.tar.gz.

File metadata

  • Download URL: tag_expressions-2.0.1.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for tag_expressions-2.0.1.tar.gz
Algorithm Hash digest
SHA256 11b4b07c01feb0bdc9196f8239f0c0d9fedc2c6c8a99032c6f2c831b2d772e48
MD5 fbc2b2a956711ab9b085eaa0b2965add
BLAKE2b-256 74ef4a21b9ea08301762a18a1f5b0c84909c7a6dacf75c4eb359915d46348e73

See more details on using hashes here.

Provenance

The following attestation bundles were made for tag_expressions-2.0.1.tar.gz:

Publisher: deploy.yml on timofurrer/tag-expressions

Attestations:

File details

Details for the file tag_expressions-2.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for tag_expressions-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2b7e544a5b7ed963082e2cd0f0fabca7e914638b679d0c04da125094e7cfa26d
MD5 a029c6d90ae2f786e4656cb30ee33ed3
BLAKE2b-256 8bae5d7ca47dcb8e043110da47b2ff8615b77f2c52bc1502c2c8c1ab713e1096

See more details on using hashes here.

Provenance

The following attestation bundles were made for tag_expressions-2.0.1-py3-none-any.whl:

Publisher: deploy.yml on timofurrer/tag-expressions

Attestations:

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