Skip to main content

Minimal engine to execute python code generated by LLMs, with a lot of customisation options.

Project description

exec-python

Minimal engine to execute python code generated by LLMs, with a lot of customisation options.

Requirements

  • Python 3.13+
  • uv (for development & testing)

Installation

pip install exec-python 

Running the tests

uv run test_engine.py

Usage

Quick Start

from exec_python import execute_python_code

def pair_sum(x: list[int], y: list[int]) -> list[int]:
    assert isinstance(x, list)
    assert isinstance(y, list)
    assert len(x) == len(y)
    return [x[i] + y[i] for i in range(len(x))]

code = """
x = [1, 2]
y = [2, 3]
z = pair_sum(x, y)
k = pair_sum(z, z)
"""

results = execute_python_code(
    code = code,
    functions=[pair_sum]
)
print(results)

Running the above code will output:

{
  "function_results": {
    "pair_sum": ["z","k"]
  },
  "variables": {
    "x": [1,2],
    "y": [2,3],
    "z": [3,5],
    "k": [6,10]
  },
  "errors": []
}

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

exec_python-0.1.4.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

exec_python-0.1.4-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file exec_python-0.1.4.tar.gz.

File metadata

  • Download URL: exec_python-0.1.4.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.15

File hashes

Hashes for exec_python-0.1.4.tar.gz
Algorithm Hash digest
SHA256 cb974f6e91be16736551233a27accc2b6b1531c47aa31494be47a5b42da7537b
MD5 6c99efc481b6c946f37f1b23ace82b1d
BLAKE2b-256 c9e6ef41cf86a1a6669f9f7b3ac83d8307ced5129afd5bfb69296bd86a30ee5f

See more details on using hashes here.

File details

Details for the file exec_python-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for exec_python-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 540cf38bf87dac8bd63b24dbe3e3f68a26050c5036de80195668d503aabff540
MD5 833e0bfd57d9561494bb6ab0cada16d3
BLAKE2b-256 4f5267e618b22431327f84d30e13a3317d81c88bed5544e19d216a5c6d86e19e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page