This project is a learning exploration of FastAPI, PostgreSQL, and Python best practices, with CRUD operations implemented for a Book entity.
During this project, I explored:
- FastAPI basics: routes, decorators, and syntax (
@app.get,@app.put) - Controllers and service logic: separating route handling from database operations
- Python packages:
- Pydantic: for data validation and schema definitions
- SQLAlchemy ORM: for interacting with PostgreSQL using classes and objects
- Uvicorn: as the ASGI server to run the FastAPI app
- Virtual environments: how to create and use
venvin Python to isolate dependencies - PostgreSQL + pgAdmin: connecting to and managing databases
- Models and Schemas: defining SQLAlchemy models and Pydantic schemas for data structure
- Project structure: organizing the project with
app/folder,models,schemas,routes,services - Environment variables: storing sensitive data like database URL
- Pydantic BaseSettings: how to manage environment variables and configuration using
BaseSettings - CRUD operations: performing create, read, update, and delete actions for a
Bookentity - Key functions and concepts learned:
model_dump,declarative_base(),db.add(),db.commit(), unpacking operator (**),response_model, and how they work in practice
- Routes handle HTTP requests, call service functions, and return responses
- Controllers/Services contain the business logic for database operations
- Database interactions are done via SQLAlchemy ORM and sessions
- Environment variables keep sensitive data safe and separate from code
- Models and Schemas define how data is structured in the database
This project helped me understand how to structure a FastAPI project properly, connect to PostgreSQL, manage configuration and secrets, and write clean, modular code.