Hi everyone,
I wanted to share a standard-library-only developer framework designed to solve the common architectural headaches when building generative AI and script-execution tools inside Blender.
When working with local models (Ollama) or remote cloud endpoints (OpenRouter/OpenAI), integrations frequently suffer from background thread context violations (bpy crashes) or security vulnerabilities from raw string execution (exec).
To solve this, I’ve extracted and open-sourced Blender AI Runtime under the GPL-3.0 license, packaged cleanly for PyPI/pip installation.
What it Includes:
- Thread-Safe Async Dispatcher (async_loop.py) A 100% non-blocking background queue that securely routes execution blocks onto Blender’s main timeline via a recurring timer lifecycle, bypassing interface idling stalls.
- Customizable AST Security Validator (code_validator.py): Uses Python’s built-in ast.NodeVisitor to structurally analyze generated scripts at runtime. Exposes a public SecurityVisitor class and mutable allowed_modules hooks so you can easily extend or restrict sandbox policies (e.g., allowing specific math libraries while keeping system commands blacklisted).
- Multi-Format Response Parser (response_parser.py): Highly tolerant extraction layer that catches Markdown code fences, raw text fallbacks, or model-hallucinated XML tags seamlessly.
Technical Health:
The framework is completely isolated from UI dependencies, relies strictly on Python standard libraries, and passes 83 unit and integration tests covering both headless and multi-threaded modes.
- Fully compliant with modern packaging standards (pyproject.toml).
- Includes a py.typed marker for full PEP 561 static type-checker compliance.
- Support for editable local installation via pip install -e .
Repository Link:
I would love to get the community’s thoughts on the timer registration lifecycle or how you plan to customize the AST module whitelists for your own automation tools!