A modern FastAPI application demonstrating REST API development with Python, featuring a patient management system with realistic healthcare data.
This repository showcases a complete FastAPI learning journey, building a patient management REST API from scratch. Perfect for developers learning modern Python web development, API design, and data validation patterns.
π Key Learning Areas:
- Building RESTful APIs with FastAPI
- Data validation using Pydantic models
- Working with JSON datasets
- API documentation and testing
- Modern Python development practices
FastAPI/ βββ main.py # FastAPI application with all endpoints βββ patient_dataset.json # Sample patient data (50+ records) βββ 00_Introduction.md # API fundamentals and concepts βββ 01_Pydantic.md # Pydantic usage and validation guide βββ LICENSE # MIT License βββ README.md # This documentation - Python 3.8 or higher
- pip or uv (recommended for faster installs)
# 1οΈβ£ Clone the repository git clone https://github.com/Sourabh-Kumar04/FastAPI.git cd FastAPI # 2οΈβ£ Install uv (if not already installed) curl -LsSf https://astral.sh/uv/install.sh | sh # 3οΈβ£ Install dependencies uv add fastapi uvicorn # 4οΈβ£ Run the development server uv run uvicorn main:app --reload# Clone and setup git clone https://github.com/Sourabh-Kumar04/FastAPI.git cd FastAPI # Create virtual environment python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate # Install dependencies pip install fastapi uvicorn # Run the server uvicorn main:app --reloadOnce running, access your API at:
- π₯ Interactive API Docs (Swagger UI): http://localhost:8000/docs
- π Alternative Docs (ReDoc): http://localhost:8000/redoc
- β‘ API Base: http://localhost:8000
| Method | Endpoint | Description | Example Response |
|---|---|---|---|
GET | / | Welcome message and API info | {"message": "Welcome to FastAPI Patient Management System"} |
GET | /about | About the API and developer | {"about": "Patient Management API", "developer": "Sourabh Kumar"} |
GET | /view | Get all patients | Array of patient objects |
GET | /patient/{id} | Get specific patient by ID | Single patient object |
GET | /sort | Sort patients by criteria | Sorted array of patients |
| Parameter | Type | Options | Default | Example |
|---|---|---|---|---|
sort_by | string | age, name | age | /sort?sort_by=name |
order | string | asc, desc | asc | /sort?order=desc |
curl http://localhost:8000/viewcurl http://localhost:8000/patient/1# Sort by age (oldest first) curl "http://localhost:8000/sort?sort_by=age&order=desc" # Sort alphabetically by name curl "http://localhost:8000/sort?sort_by=name&order=asc"import requests # Base URL base_url = "http://localhost:8000" # Get all patients response = requests.get(f"{base_url}/view") patients = response.json() print(f"Total patients: {len(patients)}") # Get specific patient patient_response = requests.get(f"{base_url}/patient/5") if patient_response.status_code == 200: patient = patient_response.json() print(f"Patient: {patient['name']}, Age: {patient['age']}") else: print("Patient not found") # Get sorted patients sorted_response = requests.get(f"{base_url}/sort", params={ "sort_by": "age", "order": "desc" }) sorted_patients = sorted_response.json() print(f"Oldest patient: {sorted_patients[0]['name']} ({sorted_patients[0]['age']} years)")The patient_dataset.json contains 50+ realistic patient records for testing and development purposes.
Each patient record includes:
| Field | Type | Description | Example |
|---|---|---|---|
id | Integer | Unique patient identifier | 1 |
name | String | Full patient name | "Sumer Saini" |
age | Integer | Patient age | 55 |
gender | String | Gender identity | "Male" |
contact | String | Contact number | "+915335225484" |
email | String | Email address | "sahotakiaan@shroff.info" |
address | String | Complete address | "H.No. 452, Hora Marg, Hindupur 334089" |
blood_group | String | ABO blood type | "A+" |
medical_history | Array | Medical conditions | ["Cardiac issues", "COVID-19"] |
admission_date | String | Admission date (YYYY-MM-DD) | "2025-07-09" |
discharge_date | String | Discharge date (YYYY-MM-DD) | "2025-07-19" |
doctor_assigned | String | Assigned physician | "Dr. Rohit Nair" |
current_status | String | Current patient status | "Discharged" |
{ "id": 1, "name": "Sumer Saini", "age": 55, "gender": "Male", "contact": "+915335225484", "email": "sahotakiaan@shroff.info", "address": "H.No. 452, Hora Marg, Hindupur 334089", "blood_group": "A+", "medical_history": [ "Cardiac issues", "COVID-19", "Hypertension" ], "admission_date": "2025-07-09", "discharge_date": "2025-07-19", "doctor_assigned": "Dr. Rohit Nair", "current_status": "Discharged" }This repository includes comprehensive learning materials:
π 00_Introduction.md
API Fundamentals & System Design
- What are REST APIs and why they matter
- HTTP methods and status codes
- Monolithic vs Microservice architectures
- API integration with Machine Learning systems
- Testing tools and best practices
π§ 01_Pydantic.md
Advanced Data Validation with Pydantic
- Pydantic models and type hints
- Data validation and serialization
- Nested models and complex data structures
- Environment variables and settings management
- Custom validators and error handling
- FastAPI Framework: Route definition, request handling, response formatting
- Pydantic Integration: Automatic data validation, type conversion, error messages
- API Design: RESTful principles, endpoint organization, query parameters
- Data Handling: JSON processing, sorting algorithms, error handling
- Development Tools: Virtual environments, package management, development servers
Use the built-in Swagger UI at http://localhost:8000/docs to:
- View all available endpoints
- Test API calls directly in the browser
- See request/response schemas
- Understand parameter requirements
# Test all endpoints curl http://localhost:8000/ curl http://localhost:8000/about curl http://localhost:8000/view curl http://localhost:8000/patient/10 curl "http://localhost:8000/sort?sort_by=name&order=asc"# Make changes to main.py # Server automatically reloads (thanks to --reload flag) # Test changes at http://localhost:8000/docs # Check logs in terminal for any errors# Using uv (recommended) uv add package-name # Using pip pip install package-name pip freeze > requirements.txt-
Database Integration
- Replace JSON file with PostgreSQL or SQLite
- Add SQLAlchemy ORM for database operations
- Implement connection pooling
-
Advanced Features
- POST endpoint to create new patients
- PUT endpoint to update patient information
- DELETE endpoint to remove patients
- Search functionality with filters
-
Authentication & Security
- JWT token-based authentication
- Role-based access control (Admin, Doctor, Nurse)
- API rate limiting and security headers
-
Production Deployment
- Docker containerization
- Environment configuration
- Logging and monitoring
- CI/CD pipeline with GitHub Actions
- Explore the interactive docs thoroughly
- Try modifying the patient data structure
- Add new endpoints for specific use cases
- Experiment with different query parameters
- Study the error handling patterns
Feel free to contribute to this learning project! Here's how:
- Fork the repository
- Create a feature branch (
git checkout -b feature/new-endpoint) - Make your changes and test them
- Commit your changes (
git commit -am 'Add new search endpoint') - Push to the branch (
git push origin feature/new-endpoint) - Create a Pull Request
- Check the existing issues on GitHub
- Create a new issue with detailed description
- Include steps to reproduce the problem
- FastAPI Documentation: https://fastapi.tiangolo.com/
- Pydantic Documentation: https://docs.pydantic.dev/
- Python Type Hints: https://docs.python.org/3/library/typing.html
- HTTP Status Codes: https://httpstatuses.com/
- REST API Design: https://restfulapi.net/
- FastAPI official tutorial
- REST API design principles
- Python async/await concepts
- JSON data handling in Python
This project is licensed under the MIT License - see the LICENSE file for details.
What this means:
- β Commercial use allowed
- β Modification allowed
- β Distribution allowed
- β Private use allowed
- β License and copyright notice required
Sourabh Kumar
CS Student @University of Delhi | AWS AIML Scholar'24
Passionate about AI/ML and software development, exploring modern web technologies and building practical applications for learning and growth.
- π GitHub: @Sourabh-Kumar04
- π University: University of Delhi (Computer Science)
If this repository helped you learn FastAPI or understand API development:
- β Star this repository to show your support
- π΄ Fork it to create your own version
- π’ Share it with fellow developers
- π‘ Contribute improvements or new features
- π Report issues to help others
Built with β€οΈ using FastAPI and Python
Happy Learning! π