PyJudgeAPI is an ExpressJS API designed to execute and grade Python code on the server-side. This API provides a reliable and secure environment for running educational exercises, grading programming assignments, or testing code snippets in Python.
This API is part of the larger project ObieCode, which is used to run Python in the backend.
-
Execute Python Code: PyJudgeAPI allows users to submit Python code for execution on the server, providing real-time feedback on the output and potential errors.
-
Code Grading: In addition to running Python code, PyJudgeAPI can be used to automatically grade assignments or code submissions based on predefined test cases and evaluation criteria.
-
Dockerized Deployment: The API comes with a Dockerfile, making it easy to deploy and manage the application in containerized environments.
To deploy PyJudgeAPI locally or in a server environment, follow these steps (please ensure that you installed python3
):
- Clone the repository:
git clone https://github.com/your_username/PyJudgeAPI.git
- Navigate to the project directory:
cd PyJudgeAPI
- Install dependencies:
npm install
- Run the API:
npm start
For Docker deployment:
- Build the Docker image:
docker build -t pyjudgeapi .
- Run the Docker container:
docker run -p 8080:8080 pyjudgeapi
- Endpoint:
POST /runcode
- Request body:
{
"code": "print('Hello, World!')",
"input": null
}
- Response:
{
"success": true,
"output": "Hello, World!\n"
}
- Error:
{
"success": false,
"output": "Code is required"
}
- Endpoint:
POST /grade
- Request body:
{
"code": "def add(a, b):\n return a + b",
"testCases": [
{"input": [2, 3], "output": 5},
{"input": [5, 7], "output": 12},
{"input": [10, -3], "output": 7}
]
}
- Response:
{
"results": [
{"success": true, "output": 5},
{"success": true, "output": 12},
{"success": true, "output": 7}
],
"grade": 100
}
- Endpoint:
GET /validate-python
- Response:
Python version: Python 3.8.10
Contributions to PyJudgeAPI are welcome! If you find any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request.