LLM7-powered generator that creates a minimal single-function Python package and runner from a natural-language spec.
Project description
py_llm7_code
py_llm7_code generates a minimal single-function Python package from a natural-language specification using an LLM7 ChatLLM7 client.
It enforces one public function in __init__.py, performs safety/syntax/import checks, and runs a minimal demo (run.py).
Installation
# From PyPI
pip install py_llm7_code
# Or install directly from source
pip install "git+https://github.com/chigwell/py_llm7_code"
Usage
from langchain_llm7 import ChatLLM7
from py_llm7_code import generate_package_with_llm7
llm = ChatLLM7(base_url="https://api.llm7.io/v1")
spec = """
Create a simple package with exactly one function `greet()` that returns 'hello'.
No network calls. Pure stdlib.
"""
result = generate_package_with_llm7(
llm=llm,
spec_text=spec,
package_name="greet_pkg",
verbose=True,
)
assert result["success"], result.get("error_message")
print("Package dir:", result["package_dir"])
print("Package name:", result["package_name"])
print("Run stdout:", result["stdout"]) # e.g. {"result": "hello"}
Generated structure (example):
/tmp/llm7_genpkg_xxxxxx/
├─ greet_pkg/
│ └─ __init__.py # contains exactly one function
└─ run.py # imports and executes the function
Features
- One-function enforcement: rejects multiple functions/classes in
__init__.py. - Safety checks: blocks dangerous imports (
subprocess, sockets, HTTP libs, etc.). - Syntax & import validation:
py_compile+ import reflection. - Sandboxed execution: timeouts and best-effort memory limits (POSIX
resource). - Optional venv & deps: create a temp venv and
pip installrequested packages. - Retry loop: automatically retries generation with feedback.
- Allow-list for imports: restrict third-party imports to a provided list.
- Custom indexes: supports
--index-urland--extra-index-url.
API
generate_package_with_llm7(
llm: ChatLLM7,
spec_text: str,
*,
package_name: str | None = None,
max_retries: int = 10,
exec_timeout_sec: int = 8,
memory_limit_mb: int = 256,
verbose: bool = False,
pip_packages: list[str] | None = None,
allowed_imports: list[str] | None = None,
pip_index_url: str | None = None,
pip_extra_index_urls: list[str] | None = None,
pip_no_deps: bool = False,
) -> dict[str, any]
Key return fields:
success: boolpackage_dir: strpackage_name: strinit_py_code: strrunner_code: strrun_cmd: strstdout: strstderr: strattempt_count: intpip_packages_installed: list[str]venv_python: str
Notes
- Memory limits rely on POSIX
resourceand may be ignored on non-POSIX systems. - By default, third-party imports are disallowed unless explicitly allow-listed via
allowed_imports. - Network/file-system side effects are restricted; the generator scans for disallowed patterns.
Contributing
Issues and PRs are welcome. Please use the issue tracker.
License
py_llm7_code is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_llm7_code-2025.9.121057.tar.gz.
File metadata
- Download URL: py_llm7_code-2025.9.121057.tar.gz
- Upload date:
- Size: 23.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5fd81a85240265e711a02198e6354c663847b85fb8173a3f768844d2fc750426
|
|
| MD5 |
4ad2f2ac8805651b959f9cfd21e6d877
|
|
| BLAKE2b-256 |
037cf8b14cd945f9184b29527989538a3ba7d936b29d693f7725198139b3ec52
|
File details
Details for the file py_llm7_code-2025.9.121057-py3-none-any.whl.
File metadata
- Download URL: py_llm7_code-2025.9.121057-py3-none-any.whl
- Upload date:
- Size: 22.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8bffc3ca466ff7c21afd2da0b7e4a27397483c6d89a30eeb87e2834b37714d5c
|
|
| MD5 |
ae838d10ccae186babf9dd410f4d9215
|
|
| BLAKE2b-256 |
88104c87fb7e7153d68f961f2e4f2eebae063eea9b51a481b4238457600cf19d
|