A simple RESTful API built with FastAPI for receiving and managing IoT telemetry data.
This project demonstrates how to build a clean backend API that:
- Accepts telemetry data in JSON format
- Validates incoming data
- Stores records in memory
- Exposes multiple REST endpoints
- Provides automatic interactive documentation
- ✅
GET /– API status check - ✅
GET /health– Health monitoring endpoint - ✅
POST /telemetry– Submit IoT telemetry data - ✅
GET /telemetry– Retrieve stored telemetry records - ✅ Input validation using Pydantic
- ✅ In-memory data storage
- ✅ Automatic Swagger documentation (
/docs)
- Python 3.10+
- FastAPI
- Uvicorn
- Pydantic
iot-telemetry-api/
│
├── main.py
├── requirements.txt
└── README.md
git clone https://github.com/1khaled-ctr/iot-telemetry-api.git
cd iot-telemetry-apiReplace 1khaled-ctr with your actual GitHub username.
py -m pip install -r requirements.txtpython3 -m pip install -r requirements.txtpy -m uvicorn main:app --reloadpython3 -m uvicorn main:app --reloadThe API will start at:
http://127.0.0.1:8000
Interactive API documentation:
http://127.0.0.1:8000/docs
Returns API status.
Example Response:
{
"message": "IoT Telemetry API is running",
"status": "ok"
}Simple health check endpoint.
Example Response:
{
"ok": true
}Submit telemetry data in JSON format.
Example Request:
{
"device_id": "sensor-001",
"temperature": 22.4,
"humidity": 55.1,
"timestamp": "2026-03-01T10:30:00"
}Example Response:
{
"ok": true,
"stored_records": 1,
"data": {
"device_id": "sensor-001",
"temperature": 22.4,
"humidity": 55.1,
"timestamp": "2026-03-01T10:30:00"
}
}Retrieve stored telemetry records.
Query Parameters:
limit(optional, default = 50) → Number of records to return
Example:
GET /telemetry?limit=10
| Field | Rule |
|---|---|
| device_id | 1–64 characters |
| temperature | -50 to 150 |
| humidity | 0 to 100 |
| timestamp | ISO 8601 datetime format |
Invalid data will automatically return a 422 validation error.
- Telemetry data is stored in memory only.
- Restarting the server will erase stored data.
- This project is intended for learning and demonstration purposes.
For production usage, consider integrating:
- SQLite
- PostgreSQL
- Authentication
- Persistent storage
- Logging and monitoring
- Add database persistence
- Add authentication (API key or JWT)
- Add Docker support
- Deploy to cloud (Render, Railway, AWS)
- Add structured logging
- Add unit tests
This project is licensed under the MIT License.
1khaled-ctrl