Small API project using Flask for reading SA-MP server info and sending RCON commands via UDP
- Create a virtualenv (recommended)
python3 -m venv .venv
source .venv/bin/activate # macOS/Linux or Windows: .venv\\Scripts\\activate- Install dependencies
pip install -r requirements.txt- Run in debug mode
python samp.py
# Will run at http://127.0.0.1:5000- Run in production (example with gunicorn)
gunicorn -w 2 -b 0.0.0.0:8000 samp:app- POST
/server/info- Request server info (hostname, gamemode, players, etc.)
- Example
curl -X POST http://127.0.0.1:5000/server/info \
-H "Content-Type: application/json" \
-d '{
"host": "127.0.0.1",
"port": 7777
}'- POST
/server/rcon- Send RCON command to server (requires password)
- Example
curl -X POST http://127.0.0.1:5000/server/rcon \
-H "Content-Type: application/json" \
-d '{
"host": "127.0.0.1",
"port": 7777,
"password": "your_rcon_password",
"command": "echo hello"
}'samp.py: Main Flask API coderequirements.txt: List of required packages.gitignore: List of files/folders to exclude from Git
- This code sends/receives data via UDP directly to the SA-MP server. Please check your firewall and connection settings.
- For production, it is recommended to run behind a WSGI server (such as
gunicorn) and place it behind a reverse proxy (such as Nginx)