This is a FastAPI-based social media API that includes basic CRUD operations, user authentication, schema validation, and database migrations using Alembic. It is designed for users to interact with posts, comments, and profiles.
- User authentication (login/signup)
- CRUD operations for posts and comments
- Database migrations with Alembic
- Fast and secure API built with FastAPI
- Python 3.8+
- PostgreSQL
git clone https://github.com/kanakOS01/social-media-fastapi.git
cd social-media-fastapipython3 -m venv venvActivate the virtual environment:
source venv/bin/activateInstall the required dependencies using pip:
pip install -r requirements.txtUpdate your database connection settings in the .env file.
Create secret key using openssl rand -hex 32
DB_HOSTNAME=
DB_PORT=
DB_PASSWORD=
DB_USERNAME=
DB_NAME=
SECRET_KEY=
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=
Create a database. Apply latest alembic revision.
alembic upgrade headYou can run the FastAPI application with the following command:
fastapi dev --app appThe API will be available at http://localhost:8000.
The FastAPI app automatically generates interactive API documentation using Swagger UI. Visit the following URL to view it:
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
.
├── alembic
├── alembic.ini
├── app
│ ├── routers
│ ├── __init__.py
│ ├── config.py
│ ├── database.py
│ ├── main.py
│ ├── models.py
│ ├── oauth2.py
│ ├── schemas.py
│ └── utils.py
├── README.md
├── requirements.txt
└── .env