This is a FastAPI-based server that replicates and enhances the functionality of a Node.js-based terminal API. It allows:
- ✅ Running shell commands via API
- ✅ Retrieving real-time terminal logs
- ✅ Interrupting running processes
- ✅ Reading and writing large files
- ✅ Secure authentication for API requests
- ✅ WebSocket support for live updates
- ✅ Firebase integration for data storage
- ✅ Auto-generated OpenAPI documentation
Feature | Status |
---|---|
Run shell commands via API | ✅ |
Retrieve real-time logs | ✅ |
Interrupt terminal commands | ✅ |
Read & Write large files | ✅ |
WebSockets for live updates | ✅ |
Secure authentication | ✅ |
Firebase integration | ✅ |
Auto-generated API docs | ✅ |
Ensure you have Python 3.10+ installed.
git clone https://github.com/yourrepo/fastapi-terminal-server.git
cd fastapi-terminal-server
python -m venv venv
source venv/bin/activate # Mac/Linux
venv\Scripts\activate # Windows
pip install -r requirements.txt
Start the FastAPI server with:
uvicorn main:app --reload
The server runs on http://127.0.0.1:8000 by default.
- Swagger UI: http://127.0.0.1:8000/docs
- ReDoc: http://127.0.0.1:8000/redoc
Method | Endpoint | Description |
---|---|---|
POST | /api/run-terminal-script |
Execute a shell command |
GET | /api/get-terminal-logs |
Fetch terminal output |
POST | /api/interrupt |
Interrupt running processes |
Method | Endpoint | Description |
---|---|---|
GET | /api/read-file?filename={name} |
Read a file |
POST | /api/write-file |
Write to a file |
POST | /api/upload-file |
Upload a file |
- Live Logs: Connect to
/ws/logs
API requests require an Authorization Token:
{
"Authorization": "Bearer YOUR_SECRET_TOKEN"
}
Set your token in the .env
file:
AUTH_TOKEN=your_secret_token
This project integrates Firebase for data storage.
- Ensure you have a valid
firebaseAdmin.json
file in the root directory.
import firebase_admin
from firebase_admin import credentials, firestore
cred = credentials.Certificate("firebaseAdmin.json")
firebase_admin.initialize_app(cred)
db = firestore.client()
docker build -t fastapi-terminal .
docker run -p 8000:8000 fastapi-terminal
gunicorn -k uvicorn.workers.UvicornWorker main:app --bind 0.0.0.0:8000
Use a different port:
uvicorn main:app --host 0.0.0.0 --port 8080
MIT License. See LICENSE for details.
- Add database caching
- Improve security with JWT authentication
- Implement async task processing
For contributions, feel free to submit a pull request! 🚀