https://github.com/sourabh-kumar04/fastapi
A modern FastAPI application demonstrating REST API development with Python, featuring a patient management system with realistic healthcare data. Perfect for learning API design, Pydantic validation, and modern Python web development.
https://github.com/sourabh-kumar04/fastapi
api-development data-validation fastapi healthcare json-data learning-projects patient-management pydantic python rest-api swagger-ui
Last synced: about 2 months ago
JSON representation
A modern FastAPI application demonstrating REST API development with Python, featuring a patient management system with realistic healthcare data. Perfect for learning API design, Pydantic validation, and modern Python web development.
- Host: GitHub
- URL: https://github.com/sourabh-kumar04/fastapi
- Owner: Sourabh-Kumar04
- License: mit
- Created: 2025-07-30T15:19:10.000Z (2 months ago)
- Default Branch: master
- Last Pushed: 2025-08-12T02:25:16.000Z (about 2 months ago)
- Last Synced: 2025-08-12T04:26:58.462Z (about 2 months ago)
- Topics: api-development, data-validation, fastapi, healthcare, json-data, learning-projects, patient-management, pydantic, python, rest-api, swagger-ui
- Language: Python
- Homepage:
- Size: 32.2 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ๐ FastAPI Patient Management System
[](https://www.python.org/downloads/)
[](https://fastapi.tiangolo.com)
[](https://docs.pydantic.dev)
[](https://github.com/astral-sh/uv)
[](https://opensource.org/licenses/MIT)> A modern **FastAPI** application demonstrating REST API development with Python, featuring a patient management system with realistic healthcare data.
## ๐ฏ About This Project
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---
## ๐ Repository Structure
```
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
```---
## ๐ Quick Start
### Prerequisites
- Python 3.8 or higher
- pip or uv (recommended for faster installs)### โก Installation with uv (Recommended)
```bash
# 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
```### ๐ Alternative Installation with pip
```bash
# 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 --reload
```### ๐ Access Your API
Once 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---
## ๐ API Endpoints
| 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 |### ๐ Query Parameters for `/sort`
| Parameter | Type | Options | Default | Example |
|-----------|------|---------|---------|---------|
| `sort_by` | string | `age`, `name` | `age` | `/sort?sort_by=name` |
| `order` | string | `asc`, `desc` | `asc` | `/sort?order=desc` |---
## ๐ API Usage Examples
### ๐ Get All Patients
```bash
curl http://localhost:8000/view
```### ๐ค Get Patient by ID
```bash
curl http://localhost:8000/patient/1
```### ๐ Sort Patients
```bash
# 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"
```### ๐ Python Example
```python
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)")
```---
## ๐๏ธ Dataset Overview
The `patient_dataset.json` contains **50+ realistic patient records** for testing and development purposes.
### ๐ Data Structure
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"` |### ๐ Sample Patient Record
```json
{
"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"
}
```---
## ๐ Learning Resources
This repository includes comprehensive learning materials:
### ๐ [`00_Introduction.md`](./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`](./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### ๐ Skills You'll Learn
- **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---
## ๐ ๏ธ Development
### ๐งช Testing Your API
#### Manual Testing
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#### Command Line Testing
```bash
# 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"
```### ๐ Development Workflow
```bash
# 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
```### ๐ฆ Adding New Dependencies
```bash
# Using uv (recommended)
uv add package-name# Using pip
pip install package-name
pip freeze > requirements.txt
```---
## ๐ What's Next?
### ๐ฏ Planned Enhancements
1. **Database Integration**
- Replace JSON file with PostgreSQL or SQLite
- Add SQLAlchemy ORM for database operations
- Implement connection pooling2. **Advanced Features**
- POST endpoint to create new patients
- PUT endpoint to update patient information
- DELETE endpoint to remove patients
- Search functionality with filters3. **Authentication & Security**
- JWT token-based authentication
- Role-based access control (Admin, Doctor, Nurse)
- API rate limiting and security headers4. **Production Deployment**
- Docker containerization
- Environment configuration
- Logging and monitoring
- CI/CD pipeline with GitHub Actions### ๐ก Learning Suggestions
- 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---
## ๐ค Contributing
Feel free to contribute to this learning project! Here's how:
1. **Fork** the repository
2. **Create** a feature branch (`git checkout -b feature/new-endpoint`)
3. **Make** your changes and test them
4. **Commit** your changes (`git commit -am 'Add new search endpoint'`)
5. **Push** to the branch (`git push origin feature/new-endpoint`)
6. **Create** a Pull Request### ๐ Found Issues?
- Check the existing issues on GitHub
- Create a new issue with detailed description
- Include steps to reproduce the problem---
## ๐ Additional Resources
### ๐ Helpful Links
- **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/### ๐ฅ Recommended Learning
- FastAPI official tutorial
- REST API design principles
- Python async/await concepts
- JSON data handling in Python---
## ๐ License
This project is licensed under the **MIT License** - see the [LICENSE](LICENSE) file for details.
**What this means:**
- โ Commercial use allowed
- โ Modification allowed
- โ Distribution allowed
- โ Private use allowed
- โ License and copyright notice required---
## ๐จโ๐ป About the Developer
**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](https://github.com/Sourabh-Kumar04)
- ๐ **University:** University of Delhi (Computer Science)---
## ๐ Support This Project
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---
## ๐ Repository Stats


---
**Built with โค๏ธ using FastAPI and Python**
*Happy Learning! ๐*