Skip to content

mosishon/fastapi-code-runner

Repository files navigation

Contributions Welcome License: MIT Python Version

Docker Version

FastAPI Code Runner

A simple web service built with FastAPI to execute code files in different programming languages within a Docker container. This project allows you to upload a code file along with arguments, specify the programming language, and execute the code. Currently, it supports Python, with plans to expand to more languages in the future.

Features

  • Execute code files in Python using FastAPI.
  • Upload files along with arguments to run the code.
  • Simple API endpoint for running code.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

  • Docker
  • Python 3

Installation

  1. Clone the repository:
git clone https://github.com/mosishon/fastapi-code-runner.git
  1. Navigate to the project directory:
cd fastapi-code-runner
  1. Build the Docker image:
docker build -t fastapi-code-runner .
  1. Run the FastAPI Code Runner Docker container named "runner" on port {PORT}, with automatic restart, CPU limit of 0.5, and memory limit of 512 MB, allowing users to customize CPU and RAM limits as needed.:
docker run --name runner -p {PORT}:8000 --restart=always --cpus=0.5 --memory="512m" -d fastapi-code-runner

Supported Languages

The FastAPI Code Runner currently supports the following programming languages:

  • python: A versatile and easy-to-learn programming language widely used for various applications.
  • javascript: A popular scripting language often used for web development.
  • php: A server-side scripting language commonly used for web development.
  • ruby: A dynamic, object-oriented programming language known for its simplicity and productivity.

Stay tuned for updates as we continue to expand language support in future releases!

API Documentation

POST /run

Executes the uploaded code file.

Request Body

  • file: The code file to be executed (multipart form-data).
  • args: Arguments to be passed to the code file (form field).
  • language: Programming language of the code file (form field).

Response

  • file-size: Size of the uploaded file.
  • result: Result of executing the code.
  • language: Programming language used.
  • file-path: File path of the uploaded code file.

Contributing

Contributions are welcome! Please feel free to submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • FastAPI - FastAPI framework for building APIs with Python.
  • Docker - Docker containerization technology.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published