Skip to main content

PyPI version License: MIT Downloads LinkedIn

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 install requested packages.
  • Retry loop: automatically retries generation with feedback.
  • Allow-list for imports: restrict third-party imports to a provided list.
  • Custom indexes: supports --index-url and --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: bool
  • package_dir: str
  • package_name: str
  • init_py_code: str
  • runner_code: str
  • run_cmd: str
  • stdout: str
  • stderr: str
  • attempt_count: int
  • pip_packages_installed: list[str]
  • venv_python: str

Notes

  • Memory limits rely on POSIX resource and 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.

Metadata

Release files for py-llm7-code 2025.9.121052

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

Source distribution (sdist)

Source distribution for py-llm7-code 2025.9.121052
File Size Uploaded
py_llm7_code-2025.9.121052.tar.gz 23.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py-llm7-code 2025.9.121052
File Interpreter ABI Platform
py_llm7_code-2025.9.121052-py3-none-any.whl Python 3 none any Details

Total release size: 45.2 kB

Release files / py_llm7_code-2025.9.121052.tar.gz

Download URL py_llm7_code-2025.9.121052.tar.gz
Size 23.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6721bdd63dd82583fcaa8612327a6c55ac536467f728ac76ac49a3a9950e667f
BLAKE2b-256 checksum
How to use checksums
52540ffd9fb1e31c40a16c610526819511137ab6f4ba9f5cb02f12e226d3bb4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.11

Release files / py_llm7_code-2025.9.121052-py3-none-any.whl

Download URL py_llm7_code-2025.9.121052-py3-none-any.whl
Size 22.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7e132fb05005046d012e028bba34798aa899d3b3f70d0ec5c3b04b76c75d8523
BLAKE2b-256 checksum
How to use checksums
d785b9ba52c12136859287e106b520ff7287297b60bffb95c5481b871d777062
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.11

Release history Release notifications | RSS feed

This release

2025.9.121052 This release

2 release files

0.1.0

2 release files

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