A ready-to-use FastAPI project template with sqlite-worker integration for building REST APIs quickly.
# Install dependencies
pip install -r requirements.txt
# Run the application
python app.py
# Or with uvicorn
uvicorn app:app --reloadVisit http://localhost:8000/docs for interactive API documentation.
fastapi_starter/
├── app.py # Main application
├── database.py # Database configuration
├── models.py # Pydantic models
├── requirements.txt # Dependencies
└── README.md # This file
- ✅ FastAPI with automatic OpenAPI docs
- ✅ sqlite-worker for thread-safe database operations
- ✅ Pydantic models for validation
- ✅ CRUD operations template
- ✅ Error handling
- ✅ Health check endpoint
GET /- Welcome messageGET /health- Health checkGET /items- List all itemsPOST /items- Create new itemGET /items/{item_id}- Get specific itemPUT /items/{item_id}- Update itemDELETE /items/{item_id}- Delete item
Edit models.py:
class YourModel(BaseModel):
field1: str
field2: intEdit app.py:
@app.post("/your-endpoint")
def your_endpoint(data: YourModel):
# Your logic here
passEdit database.py:
def init_database():
worker.execute("""
CREATE TABLE your_table (
id INTEGER PRIMARY KEY,
field TEXT
)
""")# Run with auto-reload
uvicorn app:app --reload
# Run on different port
uvicorn app:app --port 8080
# Run with custom host
uvicorn app:app --host 0.0.0.0from fastapi.testclient import TestClient
from app import app
client = TestClient(app)
def test_create_item():
response = client.post("/items", json={
"name": "Test Item",
"value": 123
})
assert response.status_code == 201FROM python:3.9
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]# Using gunicorn with uvicorn workers
pip install gunicorn
gunicorn app:app -w 4 -k uvicorn.workers.UvicornWorker- Add authentication (JWT, OAuth)
- Add middleware (CORS, logging)
- Implement pagination
- Add database migrations
- Set up monitoring
- Add tests
- Configure CI/CD