Skip to main content

Execute LLM-Generated Python Code Automatically

Project description

llmexec: Execute LLM-Generated Python Code

llmexec is a Python library that allows you to automatically execute python code snippets generated by large language models (LLMs). It's useful for projects that require automated code generation and execution and is a drop-in replacement for the python exec() function.

Installation

pip install llmexec

Usage

from llmexec import llmexec

# LLM-generated code
llm_output = """
# Generate random data plot using matplotlib
import matplotlib.pyplot as plt
import numpy as np

x = np.random.rand(10)  # 10 random x values
y = np.random.rand(10)  # 10 random y values

fig, ax = plt.subplots()
ax.scatter(x, y)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_title('Random Data Plot')
plt.show()
"""

# Execute the LLM-generated code
llmexec(llm_output)

llmexec will automatically parse and execute the LLM-generated code snippet, displaying a random data plot using matplotlib.

Features

  • Automatically execute LLM-generated code snippets
  • Parses out code from LLM outputs
  • Trusted execution environment using restrictedpython
  • Detailed logs and execution status
  • Timeout and memory limits to prevent abuse

License

MIT License

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

llmexec-0.1.1.tar.gz (6.6 kB view hashes)

Uploaded Source

Built Distribution

llmexec-0.1.1-py3-none-any.whl (5.5 kB view hashes)

Uploaded Python 3

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