Skip to content

PyServe installation

This guide provides instructions for system administrators to install, configure, deploy, and manage the PyServe backend service.

Overview

PyServe is a lightweight Python backend for code execution and formatting, designed for integration with other services.

Requirements

  • Python version 3.11 or newer
  • pip package manager

Installation

  1. Clone the repository and navigate to the project directory.
  2. Move into the /opt directory and change ownership to bao-admin:
    mv pyserve /opt/pyserve
    chown -R bao-admin:bao-admin /opt/pyserve
    
  3. Create a virtual environment:
python -m venv venv
source venv/bin/activate

Install dependencies

pip install -r requirements.txt

Deployment

Run the installation script to set up dependencies and environment.

sh div/script/install.sh

Deploy and start the service

sh div/script/deploy.sh

The application listen at the following address.

http://localhost:8097

Systemd

Copy the file at div/conf/pyserve.service to /etc/systemd/system/ and enable the service.

sudo cp div/conf/pyserve.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable pyserve
sudo systemctl start pyserve

API endpoints

Format Python code.

POST /pyserve/format

Execute Python code.

POST /pyserve/execute

Example API request

Format code.

curl -X POST http://localhost:8097/pyserve/format \
-H "Content-Type: application/json" \
-d '{"code": " print (\"hello world\") "}'

nginx (optional)

Configure Nginx as a reverse proxy for PyServe. Example configuration is provided in the repository.

div/conf/nginx.conf

Logs

For troubleshooting and logs, check the systemd journal.

sudo journalctl -u pyserve
tail -f /var/log/pyserve.log
tail -f /var/log/pyserve.err