Example FastAPI application for the Devscale Indonesia AI-Enabled Python Webdev Program Batch III.
This is a complete library management system demonstrating production-ready REST API development with Python, FastAPI, and SQLModel.
- Books Management: CRUD operations for books with ISBN validation
- Members Management: Member registration and management
- Borrowing System: Track book loans with return functionality
- Availability Tracking: Real-time book availability status
- API Documentation: Interactive API docs via Scalar
- FastAPI - Modern, fast web framework
- SQLModel - SQL databases in Python, designed for simplicity
- SQLite - Lightweight database (production: PostgreSQL)
- Pydantic - Data validation using Python type hints
- UV - Fast Python package installer and resolver
- Python 3.11+
- UV installed
# Clone the repository
git clone <repository-url>
cd fastapi-apps
# Create virtual environment and install dependencies
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
uv sync# Development mode with auto-reload
uvicorn app.main:app --reload
# Production mode
uvicorn app.main:app --host 0.0.0.0 --port 8000The API will be available at http://localhost:8000
Once running, access the interactive API documentation:
- Scalar UI:
http://localhost:8000/scalar - OpenAPI JSON:
http://localhost:8000/openapi.json
GET /books- List all booksGET /books/{id}- Get book by IDPOST /books- Create new bookPUT /books/{id}- Update bookDELETE /books/{id}- Delete book
GET /members- List all membersGET /members/{id}- Get member by IDPOST /members- Create new memberPUT /members/{id}- Update memberDELETE /members/{id}- Delete member
GET /borrowings- List all borrowing recordsGET /borrowings/{borrow_id}- Get record by IDPOST /borrowings- Create borrowing recordPUT /borrowings/{borrow_id}- Update recordDELETE /borrowings/{borrow_id}- Delete recordPOST /borrowings/{borrow_id}/return- Return borrowed book
app/
├── main.py # Application entry point
├── router/ # API route handlers
│ ├── books.py # Books endpoints
│ ├── members.py # Members endpoints
│ └── borrowing_history.py # Borrowing records endpoints
├── models/ # Database models
│ ├── models.py # SQLModel table definitions
│ └── engine.py # Database engine & session
└── schema/ # Pydantic schemas
└── schemas.py # Request/response models
curl -X POST "http://localhost:8000/books" \
-H "Content-Type: application/json" \
-d '{
"title": "The Python Programming",
"author": "Guido van Rossum",
"isbn": "978-0-13-110362-7"
}'curl -X POST "http://localhost:8000/members" \
-H "Content-Type: application/json" \
-d '{
"name": "John Doe",
"email": "john@example.com"
}'curl -X POST "http://localhost:8000/borrowings" \
-H "Content-Type: application/json" \
-d '{
"book_id": 1,
"member_id": 1,
"borrow_date": "2024-01-15"
}'curl -X POST "http://localhost:8000/borrowings/1/return"This application is configured to accept requests from any origin (CORS enabled for *), making it suitable for frontend development on any domain.
By default, the application uses SQLite. The database file is created automatically on first run.
For production, configure a PostgreSQL connection string in your environment:
DATABASE_URL=postgresql://user:password@localhost/dbnameCreate a .env file in the project root:
# Optional: Custom database URL
DATABASE_URL=sqlite:///library.db
# Optional: Application settings
DEBUG=trueThis example demonstrates:
- ✅ FastAPI route handlers with dependency injection
- ✅ SQLModel ORM with relationships
- ✅ Pydantic data validation and serialization
- ✅ CRUD operations with proper HTTP semantics
- ✅ Error handling with HTTP exceptions
- ✅ CORS configuration for frontend integration
- ✅ Project structure and organization
- ✅ API documentation generation
MIT License - Created for educational purposes.
Devscale Indonesia - AI-Enabled Python Webdev Program Batch III