Skip to main content

FastAPI service for executing Python code in session-scoped environments

Project description

fastpyrepl

fastpyrepl is a small FastAPI service that executes Python code in session-scoped environments over HTTP.

Install

From pypi:

pip install fastpyrepl

From source:

git clone https://github.com/gjyotin305/fastpyrepl
cd fastpyrepl
pip install .

After install, run the CLI:

fastpyrepl --help

Run the server

Default:

fastpyrepl

Custom host/port:

fastpyrepl --host 127.0.0.1 --port 9000

Enable reload during development:

fastpyrepl --reload

The server starts at http://<host>:<port>.

API Endpoints

GET /health

Check service health.

Example:

curl http://127.0.0.1:8000/health

Response:

{"status":"PYTHON REPL ACTIVE"}

POST /execute

Execute Python code in a session.

Request body:

{
  "code": "print('hello')",
  "context": "optional context string",
  "setup_code": "x = 10",
  "session_id": "optional-session-id",
  "return_locals": true,
  "locals_keys": ["x"]
}

Notes:

  • If session_id is omitted, a new one is created and returned.
  • Reuse the same session_id to keep variables between calls.
  • setup_code runs when a new session is created.

Example:

curl -X POST http://127.0.0.1:8000/execute \
  -H "Content-Type: application/json" \
  -d '{"code":"x = 2\nprint(x)","return_locals":true,"locals_keys":["x"]}'

Response shape:

{
  "stdout": "2\n",
  "stderr": "",
  "locals": {"x": 2},
  "execution_time": 0.001,
  "session_id": "...",
  "error": null
}

POST /reset

Reset one session or all sessions.

Reset one:

curl -X POST http://127.0.0.1:8000/reset \
  -H "Content-Type: application/json" \
  -d '{"session_id":"your-session-id"}'

Reset all:

curl -X POST http://127.0.0.1:8000/reset \
  -H "Content-Type: application/json" \
  -d '{}'

Local development

python3 -m pip install -e .
fastpyrepl --reload

Security warning

This service executes arbitrary Python code. Do not expose it to untrusted users or public networks without sandboxing and strict isolation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastpyrepl-0.1.1.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastpyrepl-0.1.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file fastpyrepl-0.1.1.tar.gz.

File metadata

  • Download URL: fastpyrepl-0.1.1.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for fastpyrepl-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8abc0e8dd24fdc3a0708f12629a6edcb85a15935b2f9c03b11b6605171c0ebe9
MD5 0cd6a3a2d6a511633ed2def8a2c3078e
BLAKE2b-256 77d2c34509b63cf676207b4a393d8e17d8ec7e9fc2331c4236ee91f6376eaead

See more details on using hashes here.

File details

Details for the file fastpyrepl-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: fastpyrepl-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for fastpyrepl-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0e177c68d3fda9dafafd9e65ede11e1e91901b22dd02b2b1e4800ba075317939
MD5 0e4c9953437310474f05ce62323e4b0e
BLAKE2b-256 b3913d69a34f3254bd65de81900db209ed56f572e4020c7ac0fc2935dfad2651

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page