A Python SDK for code compilation by Akash Halder. It allows developers to use this SDK and create their frontend for online code compilation
Project description
A lightweight Python SDK to compile and execute code using a powerful code-execution API. Perfect for building online code editors, testing environments, and educational platforms.
✅ A Python port of the original TypeScript SDK
🎯 Try the live demo here: https://www.akashhalder.in/code-compiler
✨ Features
- Fetch supported runtimes with versions
- Execute code in 50+ programming languages
- Built-in error/output handling
- Easy to plug into any Python backend or CLI tool
📦 Installation
pip install ah-code-compiler-sdk
🚀 Usage (Python)
import AHCodeCompiler.compiler as compiler
# Get all run-time Environment
runtimes = compiler.get_runtimes()
print("Available Runtimes: \n", runtimes)
# Execute Code of the Supported Language
result = compiler.execute_code(
language="javascript",
version="18.15.0",
files=[
{
"name": "main.js",
"content": "console.log('Hello from JavaScript!');"
}
]
)
# Extract output and error
stdout = result.get('run', {}).get('stdout')
stderr = result.get('run', {}).get('stderr')
# Conditional rendering
if stdout:
print("✅ Output:")
print(stdout.strip())
elif stderr:
print("❌ Error:")
print(stderr.strip())
else:
print("⚠️ No output or error received.")
Or,
from AHCodeCompiler import AHCodeCompiler
compiler = AHCodeCompiler()
# Get all run-time Environment
runtimes = compiler.get_runtimes()
print("Available runtimes: \n", runtimes)
# Execute Code of the Supported Language
result = compiler.execute(
language="javascript",
version="18.15.0",
files=[
{
"name": "main.js",
"content": "console.log('Hello from JavaScript!');"
}
]
)
# Extract output and error
stdout = result.get('run', {}).get('stdout')
stderr = result.get('run', {}).get('stderr')
# Conditional rendering
if stdout:
print("✅ Output:")
print(stdout.strip())
elif stderr:
print("❌ Error:")
print(stderr.strip())
else:
print("⚠️ No output or error received.")
📚 API Reference
class AHCodeCompiler
Main SDK wrapper for all functionality.
get_runtimes() -> list[dict]
Fetch all supported runtimes.
Returns:
[
{
"language": "python3",
"version": "3.10.0",
"aliases": ["py", "py3"],
"runtime": "python"
},
...
]
execute_code(language: str, version: str, files: list[dict]) -> dict
Execute code for the given language and version.
Example:
compiler.execute_code(
language="python3",
version="3.10.0",
files=[
{"name": "main.py", "content": "print('Hello World')"}
]
)
🌍 Supported Languages
Some of the popular languages supported:
- Python (
python3) - JavaScript (
node) - C++
- Java
- Go
- Rust
- TypeScript
- C#
- Ruby
- PHP
- ...and more
Use
get_runtimes()to fetch the latest list.
📄 License
MIT License © Akash Halder
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ahcodecompiler-1.0.2.tar.gz.
File metadata
- Download URL: ahcodecompiler-1.0.2.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
463732f0f167cea8d8f80322c56b38760f8820050a91a0b4394777d253fc86f7
|
|
| MD5 |
31c87500c58c6b2015b7d994703e096f
|
|
| BLAKE2b-256 |
92334c306c3a22b091f8dc580cbad31ad05601c381aee6a58e1a115ccd870a39
|
File details
Details for the file ahcodecompiler-1.0.2-py3-none-any.whl.
File metadata
- Download URL: ahcodecompiler-1.0.2-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0df5a30cc6a3a0cb8042dc518e4c59de9c115ff77f6c50abf487a873d31db4e6
|
|
| MD5 |
86a81eddc7b3e45955b771b34bb4287b
|
|
| BLAKE2b-256 |
35511b4c18ed2004b5bb482f9db2174624e4ab8bb50e5ceb3083caccff469001
|