Skip to content

This repository contains the Python remote code execution engine for the pennant-notebook project.

Notifications You must be signed in to change notification settings

marwan37/pennant-flask-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pennant Flask Server

Overview

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.

Table of Contents

Installation

  1. Clone the repository:
git clone https://github.com/marwan37/pennant-flask-server.git
  1. Install the required packages:
pip install -r requirements.txt

Configuration

Usage

Run the Flask application:

python app.py

Running Celery Worker

From Terminal, or Linux (e.g., DigitalOcean Droplet)

  1. Navigate to the project directory.
  2. Run the following command to start the Celery worker:
celery -A app.celery worker

Endpoints

Submit Code

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.

Get Submission Status

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.

Reset Notebook

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.

Notebook Status

Checks if a notebook is active.

URL: /notebookstatus/:notebookId

Method: GET

Format Python Code

Formats Python code.

URL: /format-python

Method: POST

API Status Codes

Status code Description
200 OK
202 Accepted
400 Bad request
404 Not found
500 Internal server error

Examples

POST /api/submit

Returns: 202 Accepted and submissionId (token)

Initiates submission. Starts code execution process.

{
	"notebookId": "111",
	"cells": [
      {
        	"cellId": "3",
        	"code": "print('Hello, world!')"
      }
  ]  
}

GET /api/status/:submissionId

Returns: 200 OK and payload of results.

{
   "submissionId": "0c5796d7-c8fb-4b4c-a13d-9ebedc914551",
   "status": "success",
   "results": [
         {
           "cellId": "3",
           "type": "output",
           "output": "Hello, world!"
       }
   ]
}

About

This repository contains the Python remote code execution engine for the pennant-notebook project.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages