Skip to main content

PyPI version

Python code synthesis

This project is used to interpret Python code and generate Python code based on given values.

This project is heavily influenced by Barliman, which implemented this exact idea for Scheme. While Barliman works wonders, I don't think Scheme is a programming language that is widely used in production environments. This is the reason I created this project, so that the principle of Barliman could be applied to Python.

Examples

This project can do both interpreting from Python code to values and vica versa. For example, AST values will be converted to the correct interpreted values:

> from evalo import *
> x = var()
> run(1, x, eval_expro(ast.BinOp(left=ast.Num(n=1), op=ast.Add(), right=ast.Num(n=1)), [], x))

(2,)

Interpreting from values to Python code will generate AST objects, which can be directly translated to Python code using external libraries. For example, if we want 5 different versions of Python code that are interpreted to the value 2, we can do the following:

> from evalo import *
> x = var()
> run(5, x, eval_expro(x, [], 2))

(<_ast.Num at 0x7fdf44aabe48>,
 <_ast.BinOp at 0x7fdf44a87fd0>,
 <_ast.BinOp at 0x7fdf44a1d320>,
 <_ast.BinOp at 0x7fdf44a444e0>,
 <_ast.BinOp at 0x7fdf46ee36a0>)

To translate this to human-readable values, we can use ast_dump_if_possible:

> [ast_dump_if_possible(y) for y in run(5, x, eval_expro(x, [], 2, maxdepth=3))]

['Num(n=2)',
 'BinOp(left=Num(n=0), op=Add(), right=Num(n=2))',
 'BinOp(left=Num(n=0), op=Sub(), right=BinOp(left=Num(n=0), op=Sub(), right=Num(n=2)))',
 'BinOp(left=Num(n=1), op=Mult(), right=Num(n=2))',
 'BinOp(left=BinOp(left=Num(n=0), op=Add(), right=Num(n=0)), op=Add(), right=Num(n=2))']

Using the astunparse library we can directly translate this output to Python source code:

> [astunparse.unparse(y).strip() for y in run(10, x, eval_expro(x, [], 2, maxdepth=3))]

['2',
 '(0 + 2)',
 '(0 - (0 - 2))',
 '(1 * 2)',
 '((0 + 0) + 2)',
 '((0 + 0) - (0 - 2))',
 '((1 + 0) * 2)',
 '((0 - 0) + 2)',
 '((0 - 0) - (0 - 2))',
 '((1 - 0) * 2)']

Development

If you want to help develop on this project, you can install it like so using Python 3.7:

mkvirtualenv -a $(pwd) $(basename $(pwd)) -p python3
pip install -r requirements/development.txt
pre-commit install

This project uses tox with pytest for testing, so just run tox to run all tests.

Metadata

Release files for evalo 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for evalo 0.2.0
File Size Uploaded Provenance
evalo-0.2.0.tar.gz 6.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for evalo 0.2.0
File Interpreter ABI Platform
evalo-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.8 kB

Release files / evalo-0.2.0.tar.gz

Download URL evalo-0.2.0.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
df0fd4746dc3b33963c0f59f6ab8537049d1ccbec35dc8a98a9d61065a9c9ee7
BLAKE2b-256 checksum
How to use checksums
1fe892d9225f751602221b052dbf68ee762b27bc95598682e29545aeb8b9de96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.9

Release files / evalo-0.2.0-py3-none-any.whl

Download URL evalo-0.2.0-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
75cb0733aa04c01a419ce63c501efcb90c5a9c34bec4ea389bfce54f51a07ce0
BLAKE2b-256 checksum
How to use checksums
68d2517528c4107dfa9f88211f559a9e82ac4b96aff06ee740775b4597cdae55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.9

Security for evalo 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page