This project is a REST API for managing contact information, built using FastAPI and SQLAlchemy with PostgreSQL as the database backend. It allows for creating, retrieving, updating, and deleting contact details, as well as searching contacts and fetching contacts with upcoming birthdays.
- CRUD operations: Create, Read, Update, Delete contacts.
- Search contacts by name, surname, or email.
- Get contacts with birthdays in the next 7 days.
- The module for creating an account and logging in.
- PostgreSQL database integration.
- Asynchronous request handling.
- Pydantic models for data validation.
- User features such as login, auth, logout, verify email, reset password.
- SMTP server for verifying email and reset password.
- Auto-generated API documentation using Swagger UI.
- Docker with all dependencies.
- FastAPI: A modern, fast (high-performance), web framework for building APIs with Python 3.7+.
- SQLAlchemy: The Python SQL Toolkit and Object-Relational Mapper.
- PostgreSQL: An open-source relational database.
- Pydantic: Data validation and settings management using Python type annotations.
- asyncpg: A database interface library designed specifically for PostgreSQL and Python/asyncio.
- Python 3.7+
- PostgreSQL
- Clone the repository:
git clone https://github.com/TrippyFrenemy/FastApiPostgresEducation.git
- Navigate to the project directory:
cd FastApiPostgresEducation - Install the required packages:
pip install -r requirements.txt
- Ensure PostgreSQL is installed and running.
- Create a new PostgreSQL database for the project.
- Update the database connection details in
config.py.
- Start the FastAPI server:
uvicorn src.main:app --reload
- Access the Swagger UI documentation at
http://127.0.0.1:8000/docs.
The API supports the following operations:
- Create a Contact:
POST /contacts/ - List all Contacts:
GET /contacts/ - Retrieve a Contact by ID:
GET /contacts/{contact_id} - Update a Contact:
PUT /contacts/{contact_id} - Delete a Contact:
DELETE /contacts/{contact_id} - Search Contacts:
GET /contacts/search?name=...&surname=...&email=... - Contacts with Upcoming Birthdays:
GET /contacts/upcoming-birthdays
Refer to the Swagger UI documentation for more details on request and response formats.
To build docker app ise the code below
docker build . -t fastapi_app:latestdocker run -d -p 7329:8000 fastapi_app