This repository serves as the remote Python code execution backend for the Pennant notebook application. It uses Flask, Celery, RabbitMQ and Redis to handle code execution requests and manage notebook states.
- Clone the repository:
git clone https://github.com/marwan37/pennant-flask-server.git
- Install the required packages:
pip install -r requirements.txt
- Celery Configuration: Modify the settings in the config/celery.py file.
- Celery Worker Service: A systemd service file is provided in config/celery-worker.service.
Run the Flask application:
python app.py
- Navigate to the project directory.
- Run the following command to start the Celery worker:
celery -A app.celery worker
Submits code for execution.
URL: /api/submit
Method: POST
Parameter | Type | Required | Description |
---|---|---|---|
notebookId |
string |
Yes | The ID of the notebook. |
cells |
array |
Yes | An array of cells to be executed. |
Response:
Property | Type | Description |
---|---|---|
submissionId |
string |
Token to track the status of the submission. |
Retrieves the status of a submitted notebook.
URL: /api/status/:submissionId
Method: GET
Parameter | Type | Required | Description |
---|---|---|---|
submissionId |
string |
Yes | Token received by the submission endpoint. |
Resets the context for a notebook.
URL: /api/reset/:notebookId
Method: POST
Parameter | Type | Required | Description |
---|---|---|---|
notebookId |
string |
Yes | The ID of the notebook to reset. |
Checks if a notebook is active.
URL: /notebookstatus/:notebookId
Method: GET
Formats Python code.
URL: /format-python
Method: POST
Status code | Description |
---|---|
200 | OK |
202 | Accepted |
400 | Bad request |
404 | Not found |
500 | Internal server error |
Returns: 202 Accepted and submissionId
(token)
Initiates submission. Starts code execution process.
{
"notebookId": "111",
"cells": [
{
"cellId": "3",
"code": "print('Hello, world!')"
}
]
}
Returns: 200 OK and payload of results.
{
"submissionId": "0c5796d7-c8fb-4b4c-a13d-9ebedc914551",
"status": "success",
"results": [
{
"cellId": "3",
"type": "output",
"output": "Hello, world!"
}
]
}