Intelligent, AI-powered code transpilation between TypeScript, Python, Rust, and Go.
Forge uses advanced AST parsing combined with LLM assistance to convert code between programming languages while preserving semantics, idioms, and best practices of the target language.
Features • Installation • Quick Start • Documentation • API Reference • Contributing
AI-powered code transpilation between languages
| Component | Preview |
|---|---|
| Source Code | ![]() |
| Transpiled Output | ![]() |
| AST View | ![]() |
Source code panel shows original TypeScript being analyzed. Transpiled output displays equivalent Python with idiomatic constructs. AST view shows parsed syntax tree with node highlighting.
- Overview
- Features
- Supported Languages
- Installation
- Quick Start
- Usage
- CLI Commands
- API Reference
- Architecture
- Type System Mappings
- Accuracy Benchmarks
- Configuration
- Development
- Testing
- Performance
- Limitations
- FAQ
- Changelog
- Roadmap
- Contributing
- License
- Acknowledgments
Forge is a next-generation code transpiler that leverages large language models (LLMs) to understand code semantics and produce high-quality, idiomatic translations between programming languages. Unlike traditional transpilers that perform mechanical text transformations, Forge:
- Parses source code into an Abstract Syntax Tree (AST)
- Analyzes types, control flow, and idioms
- Maps types between language type systems
- Translates using LLM assistance for context-aware conversion
- Generates idiomatic output in the target language
| Feature | Traditional Transpilers | Forge |
|---|---|---|
| AST-based parsing | ❌ | ✅ |
| LLM-assisted translation | ❌ | ✅ |
| Type system mapping | ✅ Comprehensive | |
| Idiomatic output | ❌ | ✅ |
| Comment preservation | ✅ Advanced | |
| LSP integration | ❌ | ✅ |
| Build verification | ❌ | ✅ |
- Multi-language Support: Transpile between TypeScript, Python, Rust, and Go
- AST-Based Parsing: Deep code analysis using language-specific parsers
- LLM-Assisted Translation: Optional AI assistance for idiomatic, context-aware output
- Type System Mapping: Intelligent conversion between language type systems
- Comment Preservation: Maintains comments, docstrings, and formatting
- Build Verification: Optional compilation and test execution
- Language Server Protocol (LSP): IDE integration for VS Code, Neovim, and other editors
- CLI and Python API: Use via command line or import as a library
- Custom Type Mappings: Define your own type conversions
- Context Preservation: Maintains project context across files
- Error Handling: Graceful handling of untranslatable constructs
- Performance Metrics: Detailed statistics on transpilation
- Streaming Output: Real-time progress for large files
- Batch Transpilation: Process multiple files efficiently
| Language | Parser | Status | Type System | Best For |
|---|---|---|---|---|
| TypeScript | tree-sitter-typescript | ✅ Stable | Structural | Web, Node.js, React |
| Python | ast (built-in) | ✅ Stable | Duck Typed | ML, Data Science, Scripting |
| Rust | tree-sitter-rust | ✅ Stable | Ownership | Systems, WebAssembly, CLI |
| Go | tree-sitter-go | ✅ Stable | Structural | Servers, Microservices, DevOps |
| From / To | TypeScript | Python | Rust | Go |
|---|---|---|---|---|
| TypeScript | - | ✅ | ✅ | ✅ |
| Python | ✅ | - | ✅ | ✅ |
| Rust | ✅ | ✅ | - | ✅ |
| Go | ✅ | ✅ | ✅ | - |
Transpilation difficulty varies based on language paradigms:
| Pair | Difficulty | Notes |
|---|---|---|
| Python → TypeScript | 2/5 | Similar paradigms, type hints → interfaces |
| TypeScript → Python | 3/5 | Interfaces → protocols, async patterns differ |
| Python → Rust | 5/5 | Major paradigm shift, ownership system |
| Rust → Python | 4/5 | Remove ownership, simplify patterns |
| TypeScript → Rust | 4/5 | Async patterns, ownership concepts |
| Go → TypeScript | 2/5 | Similar OOP patterns, interfaces map well |
- Python 3.10 or higher
- pip or poetry
- (Optional) OpenAI API key for LLM assistance
# Install latest stable release
pip install forge-transpiler
# Install with all dependencies
pip install forge-transpiler[dev,lsp]
# Install specific version
pip install forge-transpiler==0.1.0poetry add forge-transpilernpm install -g forge-transpiler# Clone the repository
git clone https://github.com/moggan1337/Forge.git
cd Forge
# Install in development mode
pip install -e ".[dev]"
# Or install all dependencies
pip install -e ".[dev,lsp]"For LLM-assisted translation, set your API key:
# OpenAI
export OPENAI_API_KEY="your-openai-api-key"
# Anthropic (alternative)
export ANTHROPIC_API_KEY="your-anthropic-api-key"Or use the configure command:
forge configure --api-key "your-key" --provider openai# Transpile TypeScript to Python
forge transpile input.ts --target-lang python -o output.py
# Transpile Rust to Go with LLM assistance
forge transpile main.rs --target-lang go --llm -o main.go
# Analyze source code
forge analyze input.ts --target-lang python
# List supported language pairs
forge list-pairsfrom forge import Transpiler, TranspilerConfig, Language
# Basic transpilation
config = TranspilerConfig(
source_language=Language.TYPESCRIPT,
target_language=Language.PYTHON,
)
transpiler = Transpiler(config)
result = transpiler.transpile("const x: number = 42;")
print(result.output)
# Output: x: int = 42from forge import Transpiler, TranspilerConfig, Language
from forge.llm import LLMConfig, LLMProvider
# Configure LLM
llm_config = LLMConfig(
provider=LLMProvider.OPENAI,
model="gpt-4",
api_key="your-api-key",
)
config = TranspilerConfig(
source_language=Language.TYPESCRIPT,
target_language=Language.PYTHON,
use_llm=True,
llm_config=llm_config,
)
transpiler = Transpiler(config)
result = transpiler.transpile(source_code)
print(result.output)Input (TypeScript):
interface User {
id: number;
name: string;
email: string;
}
function greetUser(user: User): string {
return `Hello, ${user.name}!`;
}
const user: User = {
id: 1,
name: "Alice",
email: "alice@example.com"
};
console.log(greetUser(user));Output (Python):
# Generated by Forge transpiler
# Source: TypeScript
# Target: Python
# Difficulty: 3/5
from dataclasses import dataclass
from typing import Optional
@dataclass
class User:
id: int
name: str
email: str
def greet_user(user: User) -> str:
return f"Hello, {user.name}!"
user = User(
id=1,
name="Alice",
email="alice@example.com"
)
print(greet_user(user))Input (Python):
from typing import List, Optional
class Stack:
def __init__(self) -> None:
self._items: List[int] = []
def push(self, item: int) -> None:
self._items.append(item)
def pop(self) -> Optional[int]:
return self._items.pop() if self._items else None
def peek(self) -> Optional[int]:
return self._items[-1] if self._items else NoneOutput (Rust):
// Generated by Forge transpiler
// Source: Python
// Target: Rust
// Difficulty: 5/5
#[derive(Debug)]
struct Stack {
_items: Vec<i32>,
}
impl Stack {
fn new() -> Self {
Stack { _items: Vec::new() }
}
fn push(&mut self, item: i32) {
self._items.push(item);
}
fn pop(&mut self) -> Option<i32> {
self._items.pop()
}
fn peek(&self) -> Option<&i32> {
self._items.last()
}
}from forge import Transpiler, TranspilerConfig, Language
files = [
("src/utils.ts", "src/utils.py"),
("src/types.ts", "src/types.py"),
("src/api.ts", "src/api.py"),
]
config = TranspilerConfig(
source_language=Language.TYPESCRIPT,
target_language=Language.PYTHON,
)
transpiler = Transpiler(config)
for source_path, target_path in files:
with open(source_path) as f:
source = f.read()
result = transpiler.transpile(source)
if result.success:
with open(target_path, "w") as f:
f.write(result.output)from forge import Transpiler, TranspilerConfig, Language
from forge.types import TypeMapper
# Create custom type mapper
mapper = TypeMapper()
mapper.add_custom_mapping(
source_type="MyCustomType",
target_type="CustomType",
source_lang=Language.TYPESCRIPT,
target_lang=Language.PYTHON,
quality="exact",
)
config = TranspilerConfig(
source_language=Language.TYPESCRIPT,
target_language=Language.PYTHON,
)
transpiler = Transpiler(config)
transpiler.type_mapper = mapperTranspile source code between languages.
forge transpile INPUT_FILE [OPTIONS]
Options:
-o, --output PATH Output file path
-s, --source-lang TEXT Source language
-t, --target-lang TEXT Target language (required)
--llm / --no-llm Enable LLM assistance
--model TEXT LLM model to use
--api-key TEXT API key for LLM
--preserve-comments / --no-comments
--add-header / --no-header Add transpilation header
--verify / --no-verify Verify output compilesAnalyze source code and show type mappings.
forge analyze INPUT_FILE [OPTIONS]
Options:
-o, --output PATH Output file path
-t, --target-lang TEXTList all supported language pairs.
forge list-pairsStart the LSP server for IDE integration.
forge lsp [OPTIONS]
Options:
--port INTEGER Port to listen on (default: 8765)
--host TEXT Host to bind to (default: localhost)Configure Forge settings.
forge configure [OPTIONS]
Options:
--api-key TEXT
--provider TEXT openai or anthropicfrom forge import Transpiler, TranspilerConfig, Language
config = TranspilerConfig(
source_language=Language.TYPESCRIPT,
target_language=Language.PYTHON,
use_llm=False,
preserve_comments=True,
add_header=True,
)
transpiler = Transpiler(config)
result = transpiler.transpile(source_code)@dataclass
class TranspilerConfig:
source_language: Language
target_language: Language
use_llm: bool = False
llm_config: Optional[LLMConfig] = None
preserve_comments: bool = True
preserve_formatting: bool = True
add_header: bool = True
verify_output: bool = True
strict_types: bool = True@dataclass
class TranspileResult:
success: bool
output: str
source_language: Language
target_language: Language
errors: list[str] = field(default_factory=list)
warnings: list[str] = field(default_factory=list)
metrics: dict[str, Any] = field(default_factory=dict)
ast: Optional[ProgramNode] = Nonefrom forge import Language
Language.TYPESCRIPT # TypeScript/JavaScript
Language.PYTHON # Python
Language.RUST # Rust
Language.GO # Gofrom forge.types import TypeMapper, TypeMapping
mapper = TypeMapper()
mapping = mapper.map_type(
source_type="string",
source_lang=Language.TYPESCRIPT,
target_lang=Language.PYTHON,
)
print(mapping.target_type) # str┌─────────────────────────────────────────────────────────────────────────┐
│ Forge Core │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌───────────────┐ ┌───────────────┐ ┌─────────────────────────┐ │
│ │ Input │───▶│ Parser │───▶│ AST Normalizer │ │
│ │ Source │ │ Layer │ │ (Language-specific) │ │
│ │ Code │ │ │ │ │ │
│ └───────────────┘ └───────────────┘ └───────────┬─────────────┘ │
│ │ │
│ ▼ │
│ ┌───────────────┐ ┌───────────────┐ ┌─────────────────────────┐ │
│ │ Output │◀───│ Code │◀───│ Type System Mapper │ │
│ │ Target │ │ Generator │ │ │ │
│ │ Code │ │ │ │ - Primitive types │ │
│ └───────────────┘ └───────────────┘ │ - Generic types │ │
│ │ - Custom types │ │
│ └─────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────┐ │
│ │ LLM Translation │ │
│ │ Engine (Optional) │ │
│ │ │ │
│ │ - Context-aware │ │
│ │ - Idiomatic output │ │
│ │ - Quality enhancement │ │
│ └─────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────┘
- Parser Layer: Language-specific parsers convert source code to AST
- AST Normalizer: Converts language-specific AST to unified format
- Type System Mapper: Maps types between language type systems
- Code Generator: Generates target language code from unified AST
- LLM Engine: Optional AI-powered translation enhancement
| TypeScript | Python | Rust | Go |
|---|---|---|---|
number |
float | int |
f64 |
float64 |
string |
str |
String |
string |
boolean |
bool |
bool |
bool |
null |
None |
() |
nil |
undefined |
None |
Option<T> |
nil |
any |
Any |
serde_json::Value |
interface{} |
never |
NoReturn |
! |
(unreachable) |
void |
None |
() |
(no return) |
| TypeScript | Python | Rust | Go |
|---|---|---|---|
T[] |
list[T] |
Vec<T> |
[]T |
[T, U] |
tuple[T, U] |
(T, U) |
(struct) |
{key: T} |
dict[str, T] |
HashMap<K, V> |
map[K]V |
Set<T> |
set[T] |
HashSet<T> |
(map) |
Promise<T> |
asyncio.Future[T] |
impl Future |
(goroutine) |
Map<K, V> |
dict[K, V] |
HashMap<K, V> |
map[K]V |
| TypeScript | Python | Rust | Go |
|---|---|---|---|
(a: T) => R |
Callable[[T], R] |
fn(T) -> R |
func(T) R |
() => void |
Callable[[], None] |
fn() |
func() |
new () => T |
type.__init__ |
impl Default |
(constructor) |
Our accuracy benchmarks are measured using:
- Semantic Equivalence: Does the output behave identically to the input?
- Idiomatic Correctness: Does the output follow target language conventions?
- Type Correctness: Are types properly converted and annotated?
- Compilation Success: Does the output compile/run without errors?
| Language Pair | Semantic | Idiomatic | Types | Overall |
|---|---|---|---|---|
| TypeScript → Python | 94% | 88% | 92% | 91% |
| TypeScript → Rust | 87% | 82% | 89% | 86% |
| TypeScript → Go | 91% | 85% | 90% | 89% |
| Python → TypeScript | 92% | 86% | 94% | 91% |
| Python → Rust | 78% | 74% | 82% | 78% |
| Python → Go | 85% | 80% | 88% | 84% |
| Rust → TypeScript | 88% | 84% | 90% | 87% |
| Rust → Python | 82% | 78% | 85% | 82% |
| Rust → Go | 84% | 79% | 86% | 83% |
| Go → TypeScript | 90% | 87% | 92% | 90% |
| Go → Python | 88% | 84% | 90% | 87% |
| Go → Rust | 83% | 78% | 86% | 82% |
LLM assistance significantly improves idiomatic correctness:
| Language Pair | Without LLM | With LLM | Improvement |
|---|---|---|---|
| TypeScript → Python | 91% | 96% | +5% |
| Python → Rust | 78% | 89% | +11% |
| Rust → Go | 83% | 91% | +8% |
Forge uses TOML configuration files:
# ~/.config/forge/config.toml
[llm]
provider = "openai"
model = "gpt-4"
api_key = "${OPENAI_API_KEY}" # From environment
[transpiler]
preserve_comments = true
preserve_formatting = true
add_header = true
verify_output = true
[types]
strict_mode = false
allow_any = true| Variable | Description | Default |
|---|---|---|
OPENAI_API_KEY |
OpenAI API key | - |
ANTHROPIC_API_KEY |
Anthropic API key | - |
FORGE_LLM_MODEL |
Default LLM model | gpt-4 |
FORGE_LLM_BASE_URL |
Custom API endpoint | - |
# Clone the repository
git clone https://github.com/moggan1337/Forge.git
cd Forge
# Create virtual environment
python -m venv venv
source venv/bin/activate
# Install with dev dependencies
pip install -e ".[dev]"
# Run pre-commit hooks
pre-commit installForge/
├── src/forge/
│ ├── __init__.py
│ ├── __main__.py
│ ├── cli/
│ │ ├── __init__.py
│ │ └── main.py
│ ├── llm/
│ │ ├── __init__.py
│ │ ├── llm_config.py
│ │ ├── llm_translator.py
│ │ ├── openai_llm.py
│ │ └── anthropic_llm.py
│ ├── lsp/
│ │ ├── __init__.py
│ │ ├── protocol.py
│ │ └── server.py
│ ├── parsers/
│ │ ├── __init__.py
│ │ ├── base.py
│ │ ├── typescript_parser.py
│ │ ├── python_parser.py
│ │ ├── rust_parser.py
│ │ └── go_parser.py
│ ├── transpiler/
│ │ ├── __init__.py
│ │ ├── core.py
│ │ └── language.py
│ └── types/
│ ├── __init__.py
│ ├── type_mapper.py
│ └── primitive_types.py
├── tests/
│ ├── unit/
│ └── integration/
├── docs/
├── examples/
├── pyproject.toml
└── README.md
# Run all tests
pytest
# Run with coverage
pytest --cov=forge --cov-report=html
# Run specific test file
pytest tests/unit/test_type_mapper.py
# Run with verbose output
pytest -v
# Run tests matching pattern
pytest -k "test_type"tests/
├── unit/
│ ├── test_type_mapper.py
│ ├── test_parsers.py
│ ├── test_transpiler.py
│ └── test_llm.py
└── integration/
├── test_typescript_to_python.py
├── test_python_to_rust.py
├── test_rust_to_go.py
└── test_go_to_typescript.py
| File Size | TypeScript→Python | Python→Rust | With LLM |
|---|---|---|---|
| 1 KB | ~50ms | ~60ms | ~2s |
| 10 KB | ~200ms | ~250ms | ~5s |
| 100 KB | ~1.5s | ~2s | ~30s |
| 1 MB | ~12s | ~15s | ~5min |
- Base: ~50 MB
- Per parser: ~20 MB
- With LLM: +100 MB
Forge has some known limitations:
-
Language-Specific Features: Some language-specific constructs may not translate directly
- Rust lifetimes → requires manual review
- Go goroutines → async/await conversion may need adjustment
- Python GIL considerations → not automatically handled
-
Large Codebases: Very large files may take significant time with LLM
- Consider batch processing for large projects
-
External Dependencies: Code relying on language-specific libraries needs manual mapping
- Example: TypeScript
fetch→ Pythonrequestsorhttpx
- Example: TypeScript
-
Performance-Critical Code: Transpiled code may not be as optimized as hand-written code
- Review performance-critical sections
-
IDE-Specific Features: Language extensions, decorators, and annotations may not translate
- Example: TypeScript decorators → Python decorators (different syntax)
A: Accuracy depends on the language pair and complexity. See our Accuracy Benchmarks for detailed metrics. With LLM assistance, accuracy improves significantly for idiomatic correctness.
A: Yes, Forge can process multiple files using batch transpilation. For large codebases, we recommend processing files incrementally and reviewing output.
A: Yes, by default Forge preserves comments and docstrings. You can disable this with --no-comments.
A: Yes, LLM assistance requires an OpenAI or Anthropic API key. Set it via environment variable or forge configure.
A: Yes, Forge works without LLM. The AST-based transpiler handles basic translations well. LLM assistance improves idiomatic output quality.
A: Any LSP-compatible IDE including VS Code, Neovim, Helix, and Emacs (with LSP client).
A: Please use GitHub Issues: https://github.com/moggan1337/Forge/issues
- Initial release
- TypeScript, Python, Rust, Go support
- LLM integration (OpenAI, Anthropic)
- LSP server
- CLI and Python API
- Java, C++, and C# support
- Bidirectional TypeScript/JavaScript transpilation
- WebAssembly bindings
- Web UI for transpilation
- Git integration for automated PR-based transpilation
- Real-time collaborative transpilation
- Integration with popular frameworks (React, Django, Axum)
Contributions are welcome! Please see our Contributing Guide for details.
# Fork the repository
# Create your feature branch
git checkout -b feature/amazing-feature
# Commit your changes
git commit -m 'Add amazing feature'
# Push to the branch
git push origin feature/amazing-feature
# Open a Pull Request- Follow PEP 8 for Python code
- Write tests for new features
- Update documentation as needed
- Use type hints throughout
- Run linting:
ruff check . - Run tests:
pytest
This project is licensed under the MIT License - see the LICENSE file for details.
- tree-sitter team for excellent parser infrastructure
- OpenAI and Anthropic for LLM APIs
- The Python, Rust, Go, and TypeScript communities
- All contributors to this project
Forge is maintained by moggan1337
⭐ Star us on GitHub | 🐛 Report bugs | 📖 Read the docs



