Skip to main content

A simple Javascript expression builder written for Python.

Project description


synopsis:A silly little JS expression builder to let you use native Python to build Javascript expression strings.

This package only allows the creation of simple (that is, non-assignment) Javascript expressions using an intuitive Python DSL.

Logical Expressions

>>> from jexp import J
>>> e = J('var_1') & J('var_2')
>>> str(e)


>>> str(e | 'abc')


The argument to the J class will be output as a str in the resulting JS- so J('my_var') is a good way to refer to a var, and J(5) to the number literal 5. If you need an actual string, you can either add the quotes yourself in the J call - J('"my string"') - or otherwise combine the J object with a str, as shown above.

Mathematical Expressions

>>> str(J(5) + 28)


>>> str(J('my_var') + 28)


Division hasn’t been implemented, but other things you expect are there.


>>> e = J(5) <= 6
>>> str(e)


>>> str(e == "test_string")


Attribute Access

>>> e = J('my_var').attribute
>>> str(e)


This should work for any attribute that doesn’t start with an underscore (and some that do).

Function Calling

>>> e = J('func')('a','b')
>>> str(e)


You can also try this with other J objects.

>>> str(J('func')(J('arg1'),J('arg2')))


Project details

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
jexp-0.1.2.tar.gz (3.8 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page