Skip to main content

LLM7-powered generator that creates a minimal single-function Python package and runner from a natural-language spec.

Project description

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.orchestrator 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.

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

py_llm7_code-0.1.0.tar.gz (23.1 kB view details)

Uploaded Source

Built Distribution

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

py_llm7_code-0.1.0-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file py_llm7_code-0.1.0.tar.gz.

File metadata

  • Download URL: py_llm7_code-0.1.0.tar.gz
  • Upload date:
  • Size: 23.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.11

File hashes

Hashes for py_llm7_code-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e2151fa322afd694043833b44431fabfc499e5b51bc6af9c9f3039566168d33d
MD5 6fcab302bcaaa15b890643fc182900aa
BLAKE2b-256 d876ab01c01e15fc9412c40a3019589b881bdcf03279e584372ccbde4254813a

See more details on using hashes here.

File details

Details for the file py_llm7_code-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: py_llm7_code-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 21.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.11

File hashes

Hashes for py_llm7_code-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c79b98c56596d9ae12d0e993e7376183dc9fc4a315f036940d98a0e84713a98e
MD5 9e69fff5250c49f6963b9654050773bd
BLAKE2b-256 fa1bb3b56b137c45efbc222d2caab07a70cd906b8915ac5f6e052828fc314d6a

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