Skip to content

TheSpacetimeDebugger/Astmize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

109 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

   β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ•—   β–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—
  β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β•β•β•β•šβ•β•β–ˆβ–ˆβ•”β•β•β•β–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β•šβ•β•β–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•”β•β•β•β•β•
  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—   β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ–ˆβ•”β• β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—  
  β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•‘β•šβ•β•β•β•β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ–ˆβ•”β•  β–ˆβ–ˆβ•”β•β•β•  
  β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘ β•šβ•β• β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—
  β•šβ•β•  β•šβ•β•β•šβ•β•β•β•β•β•β•   β•šβ•β•   β•šβ•β•     β•šβ•β•β•šβ•β•β•šβ•β•β•β•β•β•β•β•šβ•β•β•β•β•β•β•

Python β†’ C++ β€” AI-Powered Transpiler

Live Demo Product Hunt API License Flask Deploy Bilingual


The Problem

Python is the language developers think in. C++ is the language performance demands.

Rewriting Python to C++ by hand is slow, error-prone, and interrupts creative flow. Existing tools use regex-and-replace β€” they don't understand context, types, or idiomatic C++.

Astmize closes that gap.

Paste Python. Get production-ready C++. Run it instantly in the browser β€” no setup, no compiler, no context switching.


What It Does

Astmize sends your Python source through an AI orchestration engine that understands intent and context β€” not just syntax. The output is clean, compilable C++ with proper STL usage, type inference, and optional AI enhancement.

# Input β€” Python 3.x
def find_max(nums: list[int]) -> int:
    result: int = nums[0]
    for i in range(1, len(nums)):
        if nums[i] > result:
            result = nums[i]
    return result

print(find_max([3, 7, 2, 9, 1]))
// Output β€” C++17 (Astmize)
#include <iostream>
#include <vector>

int find_max(std::vector<int> nums) {
    int result = nums[0];
    for (int i = 1; i < (int)nums.size(); ++i) {
        if (nums[i] > result) result = nums[i];
    }
    return result;
}

int main() {
    std::cout << find_max({3, 7, 2, 9, 1}) << "\n";
    return 0;
}
β–Ά Output: 9   βœ“ Compiled & executed via GCC

Supported Versions

Input Output
Python 3.x (type hints, f-strings, modern syntax) C++11 / C++17

Type annotations are preserved as strongly-typed C++ equivalents. When hints are absent, the AI infers types from context.


Core Features

Feature Description
πŸ€– AI Orchestration 8 free AI models queried in sequence β€” automatic fallback ensures availability
πŸ” AST Fallback Engine If all AI models are unavailable, a pure-Python AST transpiler handles conversion locally
✦ AI Enhancement One-click C++ refactor β€” AI improves idioms, explains every change
β–Ά Live Execution Compiles and runs generated C++ in the browser via Wandbox (GCC)
⟳ Conversion History Last 7 sessions stored locally β€” restore any previous conversion instantly
🌐 Bilingual UI Full English & Arabic interface with RTL support
⬇️ Multi-Format Export Download .cpp, copy as Markdown, or plain text
πŸ“Š Complexity Indicator Real-time simple / moderate / complex estimate as you type
↔️ Resizable Panels Drag to resize editors β€” layout ratio saved across sessions
βš™οΈ Editor Settings Font size, tab size, line numbers β€” all configurable
πŸ›‘οΈ Rate Limiting 60 req/min on /convert, 20 req/min on /enhance
πŸ“± Mobile-First PWA Installable, offline-capable β€” full tab-switcher layout on small screens
⌨️ Keyboard Shortcuts Ctrl+Enter to transpile · full shortcut reference in-app

How It Works

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    POST /convert     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Python Input  β”‚ ──────────────────▢ β”‚     Flask Backend         β”‚
β”‚   (Browser UI)  β”‚                      β”‚                           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                      β”‚  Model 1 (Qwen3 Coder)   β”‚
        β”‚                                β”‚  β†’ Model 2 (DeepSeek)    β”‚
        β”‚    C++ + Warnings              β”‚  β†’ Model 3 … (Γ—8 total)  β”‚
        β”‚ ◀────────────────────────────  β”‚  β†’ AST Fallback Engine   β”‚
        β–Ό                                β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    POST /enhance     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  C++ Output     β”‚ ──────────────────▢ β”‚  AI Refactor + Explain   β”‚
β”‚  (Highlighted)  β”‚ ◀────────────────── β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚                 β”‚
β”‚  [ ✦ Enhance ] β”‚    POST β†’ Wandbox    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  [ β–Ά Run     ] β”‚ ──────────────────▢ β”‚  GCC Compiler (Live)     β”‚
β”‚  Console Output β”‚ ◀────────────────── β”‚  stdout / stderr         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Reliability by design: No single point of failure. Every conversion attempt cascades through 8 AI models before falling back to the deterministic AST engine β€” ensuring output is always returned.


Output Reliability

Astmize approaches correctness at multiple layers:

Layer Mechanism
Compilation check All output is immediately runnable via Wandbox (GCC) β€” errors surface in the console, not silently
AI fallback chain 8 models tried in sequence; the first valid compilable response is used
AST fallback Deterministic rule-based transpiler activates when AI is unavailable
Warning system Non-fatal translation issues are surfaced as inline warnings, not discarded
Enhancement pass Optional AI refactor further improves correctness and C++ idiom compliance

Note: Astmize targets Python-to-C++ transpilation for prototyping, learning, and performance porting workflows. For safety-critical or production-compiled binaries, human review of the generated output is recommended β€” as with any code generation tool.


Architecture

astmize/
β”œβ”€β”€ app.py            # Flask API β€” AI orchestration, AST fallback, rate limiting
β”œβ”€β”€ index.html        # Full frontend (single-file, zero build step)
β”œβ”€β”€ requirements.txt  # Production dependencies
β”œβ”€β”€ Procfile          # Process definition (Render / Heroku)
β”œβ”€β”€ LICENSE
└── README.md

API Endpoints

Method Endpoint Description
GET / Health check β€” returns service version and status
POST /convert Accepts Python source, returns AI-generated C++
POST /enhance Accepts C++, returns AI-refactored version + explanation

API Reference

GET /

{
  "service": "Astmize API",
  "status": "ok",
  "version": "2.1.0"
}

POST /convert

Request

POST /convert
Content-Type: application/json

{
  "python_code": "def greet(name: str):\n    print(f'Hello, {name}!')"
}

Response 200

{
  "success": true,
  "cpp_code": "#include <iostream>\n#include <string>\n\nvoid greet(std::string name) {\n    std::cout << \"Hello, \" << name << \"!\\n\";\n}\n",
  "warnings": [],
  "error": null
}

Error responses

Code Meaning
429 Rate limit exceeded
413 Payload exceeds 64 KB limit
502 All AI models unavailable (AST fallback also failed)

POST /enhance

Request

POST /enhance
Content-Type: application/json

{
  "cpp_code": "#include <iostream>\n..."
}

Response 200

{
  "success": true,
  "enhanced_code": "#include <iostream>\n...",
  "explanation": "Replaced raw loop with std::max_element; renamed variable for clarity.",
  "error": null
}
Test with cURL / Python / Postman

cURL

# Health check
curl https://astmize.onrender.com/

# Transpile
curl -X POST https://astmize.onrender.com/convert \
  -H "Content-Type: application/json" \
  -d '{"python_code": "x: int = 42\nprint(x)"}'

# Enhance
curl -X POST https://astmize.onrender.com/enhance \
  -H "Content-Type: application/json" \
  -d '{"cpp_code": "#include <iostream>\nint main(){std::cout<<42;}"}'

Python

import requests

resp = requests.post(
    "https://astmize.onrender.com/convert",
    json={"python_code": "for i in range(5):\n    print(i)"},
)
data = resp.json()
if data["success"]:
    print(data["cpp_code"])

resp2 = requests.post(
    "https://astmize.onrender.com/enhance",
    json={"cpp_code": data["cpp_code"]},
)
print(resp2.json()["explanation"])

Local Development

# 1. Clone
git clone https://github.com/TheSpacetimeDebugger/Astmize.git
cd Astmize

# 2. Virtual environment
python -m venv .venv
source .venv/bin/activate    # Windows: .venv\Scripts\activate

# 3. Install dependencies
pip install -r requirements.txt

# 4. Set environment variables
export OPENROUTER_API_KEY="your-openrouter-api-key"
export FLASK_DEBUG=true

# 5. Start server
python app.py
# API available at http://localhost:5000

Open index.html directly in your browser β€” no build step required.

OpenRouter key: Free at openrouter.ai β€” all models Astmize uses are on free tiers.


Deploy to Render

  1. Push to GitHub
  2. render.com β†’ New Web Service β†’ connect repo
  3. Configure:
Field Value
Environment Python 3
Build Command pip install -r requirements.txt
Start Command gunicorn app:app --workers 4 --bind 0.0.0.0:$PORT
  1. Add OPENROUTER_API_KEY under Environment Variables

Cold start: Render's free tier spins down after inactivity. The first request after a sleep period may take 30–90 seconds β€” the UI notifies users automatically.


Changelog

v2.1.0 β€” Current

  • πŸ” AST Fallback Engine β€” deterministic transpiler activates when all AI models are unavailable
  • πŸ“¦ Python 3.x β†’ C++11 / C++17 version matrix documented
  • πŸ“Š Complexity Indicator β€” real-time simple / moderate / complex estimate
  • ↔️ Resizable Panels with saved layout ratio
  • – Export Dropdown β€” .cpp, Markdown, plain text
  • ❓ Keyboard Shortcuts Modal
  • πŸ“² PWA β€” installable with offline Service Worker
  • πŸͺ Privacy Consent Banner

v2.0.1

  • ✦ AI Enhancement β€” /enhance endpoint with refactor + explanation
  • ⟳ Conversion History β€” last 7 sessions in localStorage
  • πŸ”’ Live editor stats (line + character counter)
  • πŸ› Fixed program_message β†’ program_output (Wandbox stdout now displays correctly)

v2.0.0

  • πŸ€– Replaced pure AST engine with AI orchestration via OpenRouter
  • πŸ” 8-model fallback chain
  • πŸ›‘οΈ Rate limiting with bilingual error messages
  • β–Ά Live C++ execution via Wandbox (GCC)
  • πŸ“± Mobile-first layout with tab switcher
  • 🌐 Full Arabic UI with RTL support

v1.0.0

  • Initial release β€” pure Python AST transpiler engine
  • Flask backend, dark cyber frontend

Contributing

Contributions, issues, and feature requests are welcome.

  1. Fork the repository
  2. Create a branch: git checkout -b feature/your-feature
  3. Commit: git commit -m 'feat: describe your change'
  4. Push: git push origin feature/your-feature
  5. Open a Pull Request

For significant changes, open an issue first to align on approach.


Contact

Astmize Studio Β· Built by Ibrahim El-Shami

πŸ“§ sydbrahim02@gmail.com Β· 🐦 @AstmizeStudio Β· πŸš€ Product Hunt

For bugs or feature requests β€” open a GitHub issue or send an email.


License

MIT Β© Astmize Studio


If Astmize saved you time, a ⭐ helps others discover the project.

Built with ⚑ by Astmize Studio

About

Astmize is a high-performance compiler engine that parses Python code using AST and translates it into optimized, production-ready C++ code to unlock hardware-level speed and efficiency.

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors