Logic2Code - Code Generation from Logic Files
Generate source code from Code2Logic output files.
Reads YAML, Hybrid YAML, or TOON format files and produces working code scaffolds.
✨ Features
- 🏗️ Code scaffolds - Complete class and function structures
- 📝 Type hints - Full type annotation support
- 📚 Docstrings - Auto-generated documentation
- 🤖 LLM integration - Optional AI-powered implementations
- 🔄 Refactoring support - Logic → Code → Logic workflow
🚀 Installation
pip install logic2code
Or with LLM support:
pip install logic2code[llm] # With lolm for LLM generation
📖 Quick Start
CLI
# Show what can be generated
logic2code out/code2logic/project.c2l.yaml --summary
# Generate Python code
logic2code out/code2logic/project.c2l.yaml -o out/logic2code/generated_code/
# Generate stubs only
logic2code out/code2logic/project.c2l.yaml -o out/logic2code/generated_code/ --stubs-only
# Generate specific modules
logic2code out/code2logic/project.c2l.yaml -o out/logic2code/generated_code/ --modules "analyzer.py,parsers.py"
Python API
from logic2code import CodeGenerator
# Create generator
generator = CodeGenerator('out/code2logic/project.c2l.yaml')
# Get summary
summary = generator.summary()
print(f"Modules: {summary['total_modules']}")
print(f"Classes: {summary['total_classes']}")
# Generate code
result = generator.generate('out/logic2code/generated_code/')
print(f"Generated {result.files_generated} files")
# Generate single module
code = generator.generate_module('analyzer.py')
print(code)
📋 Generated Code Example
@dataclass
class ProjectInfo:
"""Information about analyzed project."""
name: str
total_files: int = 0
total_lines: int = 0
modules: List[ModuleInfo] = field(default_factory=list)
async def analyze_project(
path: str,
use_treesitter: bool = True,
verbose: bool = False
) -> ProjectInfo:
"""Analyzes project and returns ProjectInfo."""
raise NotImplementedError("TODO: Implement analyze_project")
🤖 LLM-Enhanced Generation
from logic2code import CodeGenerator, GeneratorConfig
config = GeneratorConfig(
use_llm=True,
llm_provider='openrouter'
)
generator = CodeGenerator('out/code2logic/project.c2l.yaml', config)
result = generator.generate('out/logic2code/generated_code/')
🖥️ CLI Reference
| Option | Description |
|---|---|
-o, --output DIR |
Output directory |
-l, --language LANG |
Target language (default: python) |
--stubs-only |
Generate stubs only |
--no-docstrings |
Skip docstring generation |
--no-type-hints |
Skip type hints |
--no-init |
Skip __init__.py generation |
--flat |
Flat output structure |
--modules LIST |
Comma-separated modules to generate |
--summary |
Show summary without generating |
-v, --verbose |
Verbose output |
⚙️ Configuration
from logic2code import CodeGenerator, GeneratorConfig
config = GeneratorConfig(
language='python',
stubs_only=False,
include_docstrings=True,
include_type_hints=True,
generate_init=True,
preserve_structure=True,
use_llm=False,
llm_provider=None,
)
generator = CodeGenerator('project.c2l.yaml', config)
🔄 Refactoring Workflow
# 1. Analyze original code
code2logic src/ -f yaml -o out/code2logic/project.c2l.yaml
# 2. Modify logic file (add/change functions)
# Edit out/code2logic/project.c2l.yaml
# 3. Generate new code
logic2code out/code2logic/project.c2l.yaml -o out/logic2code/new_src/
# 4. Compare and merge
diff -r src/ out/logic2code/new_src/
🧰 Monorepo (code2logic) workflow
If you use logic2code inside the code2logic monorepo, you can manage all packages from the repository root:
make test-all
make build-subpackages
make publish-all
See: docs/19-monorepo-workflow.md.
🧪 Development
# Install dev dependencies
make install-dev
# Run tests
make test
# Format code
make format
# Lint
make lint
# Build package
make build
# Publish to PyPI
make publish
📄 License
Apache 2.0 License - see LICENSE for details.
🔗 Links
Metadata
Release files for logic2code 0.1.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| logic2code-0.1.9.tar.gz | 4.5 kB | Without provenance | Details for logic2code-0.1.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| logic2code-0.1.9-py3-none-any.whl | Python 3 | none | any | Details for logic2code-0.1.9-py3-none-any.whl |
Total release size: 8.1 kB
Release files / logic2code-0.1.9.tar.gz
| Download URL | logic2code-0.1.9.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b0ddc26d589ef1400c6d3739e1c8287d3d0223a40431f6c0e04f68dce016ecc6
|
|
BLAKE2b-256 checksum How to use checksums |
10bd8434853a43d8cb6773d531b2dd1d963edad6a788ff79a8a50af256a5030d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / logic2code-0.1.9-py3-none-any.whl
| Download URL | logic2code-0.1.9-py3-none-any.whl |
|---|---|
| Size | 3.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2782c6481667262a1867c6776f8896afebfdd63b2f97dbac228fcbec37026896
|
|
BLAKE2b-256 checksum How to use checksums |
b3e71d00a4395abe86d0471d47b40162536a5bdfb1fd59a37df5de2f31e97a1e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Security for logic2code 0.1.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.