
- Set up project structure - Create FastAPI app with health endpoint - Implement SQLAlchemy with SQLite database - Set up Alembic for database migrations - Create CRUD operations for items - Add comprehensive documentation
Simple FastAPI Application
This is a simple FastAPI application with SQLite database integration, built to demonstrate best practices for API development with FastAPI.
Features
- RESTful API with FastAPI
- SQLite database with SQLAlchemy ORM
- Database migrations with Alembic
- CRUD operations for items
- Health check endpoint
- OpenAPI documentation
- Code linting with Ruff
Project Structure
├── app/
│ ├── api/
│ │ ├── endpoints/
│ │ │ ├── health.py
│ │ │ └── items.py
│ ├── core/
│ │ └── config.py
│ ├── db/
│ │ └── session.py
│ ├── models/
│ │ └── models.py
│ ├── schemas/
│ │ └── item.py
│ └── storage/
│ └── db/
├── migrations/
│ ├── versions/
│ │ └── 47e3b63e1a20_create_items_table.py
│ ├── env.py
│ └── script.py.mako
├── alembic.ini
├── main.py
├── README.md
└── requirements.txt
Installation
- Clone the repository
- Install dependencies:
pip install -r requirements.txt
Running the Application
Start the application with uvicorn:
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
API Documentation
Once the application is running, you can access:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
API Endpoints
Health Check
GET /health
- Check if the API and database are running
Items
GET /api/v1/items
- Get all itemsGET /api/v1/items/{item_id}
- Get an item by IDPOST /api/v1/items
- Create a new itemPATCH /api/v1/items/{item_id}
- Update an itemDELETE /api/v1/items/{item_id}
- Delete an item
Database Migrations
Run migrations:
alembic upgrade head
Create a new migration:
alembic revision --autogenerate -m "description"
License
MIT
Description
Languages
Python
95.5%
Mako
4.5%