FastAPi CRUD project is a RESTful API for managing users, built using FastAPI, SQLAlchemy, and SQLite. It demonstrates clean architecture, dependency injection, and best practices for Python web APIs.
- List all users
- Add new users
- Update existing users
- Delete users
- Uses SQLite for persistent storage
- Pydantic models for data validation
- SQLAlchemy for ORM and database operations
├── app/
│ ├── main.py # FastAPI app entrypoint
│ ├── database.py # DB engine & session setup
│ ├── models.py # SQLAlchemy & Pydantic models
│ └── routes/
│ └── users.py # User CRUD endpoints
├── users.db # SQLite database file
├── requirements.txt # Python dependencies
├── api_venv/ # Virtual environment
└── README.md # Project documentation
git clone <your-repo-url>
cd "Public Api"python -m venv api_venv
api_venv\Scripts\Activate.ps1pip install -r requirements.txtuvicorn app.main:app --reloadThe server will start at http://127.0.0.1:8000/
Request:
curl -X GET "http://127.0.0.1:8000/users/" -H "accept: application/json"Response:
[
{"id": 1, "name": "gg", "email": "gg@example.com"},
{"id": 2, "name": "kk", "email": "kk@example.com"}
]Request:
curl -X POST "http://127.0.0.1:8000/users/" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-d '{"id": 3, "name": "cc", "email": "cc@example.com"}'Response:
{
"message": "User added successfully",
"user": {"id": 3, "name": "cc", "email": "cc@example.com"}
}Request:
curl -X PUT "http://127.0.0.1:8000/users/3" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-d '{"id": 3, "name": "ccb", "email": "ccb@example.com"}'Response:
{
"message": "User updated successfully",
"user": {"id": 3, "name": "ccb", "email": "ccb@example.com"}
}Request:
curl -X DELETE "http://127.0.0.1:8000/users/3" -H "accept: application/json"Response:
{
"message": "User deleted successfully"
}- FastAPI provides automatic OpenAPI docs at
/docsand/redoc. - SQLAlchemy manages the SQLite database and user table.
- Pydantic validates request and response data.
- Dependency Injection is used for database sessions.
- If you get a 500 Internal Server Error, check that
users.dbexists and is writable. - Ensure all dependencies are installed and the virtual environment is activated.
- For database schema changes, delete
users.dband restart the server to recreate tables.