Skip to main content

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

ah_code_compiler_banner_img

Python Version Website

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)

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(language: str, version: str, files: list[dict]) -> dict

Execute code for the given language and version.

Example:

compiler.execute(
    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

ahcodecompiler-1.0.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ahcodecompiler-1.0.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file ahcodecompiler-1.0.0.tar.gz.

File metadata

  • Download URL: ahcodecompiler-1.0.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for ahcodecompiler-1.0.0.tar.gz
Algorithm Hash digest
SHA256 a11b7a20b2be4f2a538d926126d0283170cf2cb1157ddfb31aa7ee14dad786a8
MD5 7e60850e05d791065edb3d5eb19e0af0
BLAKE2b-256 e3ef2a2832f7a4c4db9b1cd78c3cea0b202609bbd714c090b867deb7e0fdf155

See more details on using hashes here.

File details

Details for the file ahcodecompiler-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: ahcodecompiler-1.0.0-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

Hashes for ahcodecompiler-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 86d5a9407ddcc4cebc827f42f53d37854d33b49e59f4e62739c5b0097495d635
MD5 c3b136a81551519276ab00081947496b
BLAKE2b-256 45a1d42940f1a6d6d97251cb6c92e4240bb1366ffa41d96ffcc33a186033945e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page