Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Small and simple expression language

Project Description

# aml Accounting Mini Language — Small and simple expression language running on Python.

aml is a very small programming language running on top of Python. aml is ideal for exposing a powerful but safe interface to users who need to define business rules but have no programming knowledge. In this respect aml is an alternative to cumbersome mouse-driven rule engine configurations.

The grammar and parser utilise the [pypeg2](http://fdik.org/pyPEG/) library which must be installed for aml to work.

To use aml the programmer creates a “language instace”. Calling the compile function yields an object (essentially an AST). This object can then be evaluated directly using the evaluate function or translated to Python or SQL using the respective functions.

Since the language is very simple, sufficient documentation can be given by example:

>>> lang_instance = create_lang_instance()
>>> lang_instance.aml_evaluate(lang_instance.aml_compile('1 = 1'))
True
>>> li = create_lang_instance()
>>> c = li.aml_compile
>>> e = li.aml_evaluate
>>> p = li.aml_translate_python
>>> s = li.aml_translate_sql
>>> u = li.aml_suggest
>>> e(c('1 = 0'))
False
>>> e(c('"1" = "1"'))
True
>>> e(c('(1=1)'))
True
>>> e(c('1 > 1'))
False
>>> e(c('not 1 > 1'))
True
>>> e(c('1 != 1'))
False
>>> e(c('-2 = -2'))
True
>>> eval(p(c('-2 = -2')))
True
>>> eval(p(c('null = null')))
True
>>> eval(p(c('1 = null')))
False
>>> e(c('"foo" = "foo"'))
True
>>> e(c('"foo" = \\'foo\\''))
True
>>> e(c('"fo\\'o" = "fo\\'o"'))
True
>>> e(c("'foo'" + '=' + '"foo"'))
True
>>> li = create_lang_instance({'foo' : 1});
>>> c = li.aml_compile
>>> e = li.aml_evaluate
>>> e(c('foo = 1'))
True
>>> li = create_lang_instance({'foo' : 1.00})
>>> c = li.aml_compile
>>> e = li.aml_evaluate
>>> e(c('foo = 1'))
True
>>> li = create_lang_instance({'foo' : 2.24})
>>> c = li.aml_compile
>>> e = li.aml_evaluate
>>> e(c('foo = 2.24'))
True
>>> li = create_lang_instance({'foo' : 'foo'})
>>> c = li.aml_compile
>>> e = li.aml_evaluate
>>> e(c('foo = "foo"'))
True
>>> li = create_lang_instance()
>>> c = li.aml_compile
>>> p = li.aml_translate_python
>>> s = li.aml_translate_sql
>>> s(c('null = null'))
u'null is null'
>>> p(c('null = null'))
u'None == None'
>>> s(c('null != null'))
u'null is not null'
>>> p(c('null != null'))
u'None != None'
>>> s(c('5 != 3'))
u'5 <> 3'
>>> p(c('5 != 3'))
u'5 != 3'
>>> li = create_lang_instance({'foo' : 'bar', 'fo2' : 'ba2'})
>>> c = li.aml_compile
>>> p = li.aml_translate_python
>>> e = li.aml_evaluate
>>> u = li.aml_suggest
>>> u('1 = fo')
[u'fo2', u'foo']
>>> u('1 = FO')
[u'fo2', u'foo']
>>> p(c('null = null'))
u'None == None'
>>> e(c('foo = "bar"'))
True
>>> e(c('fo2 = "ba2"'))
True
Release History

Release History

This version
History Node

1.0.0

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
amlang-1.0.0.tar.gz (4.9 kB) Copy SHA256 Checksum SHA256 Source Feb 28, 2016
amlang-1.0.0.zip (6.4 kB) Copy SHA256 Checksum SHA256 Source Feb 28, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting