An open API service indexing awesome lists of open source software.

https://github.com/dejatori/store-api

Complete REST API built with FastAPI and Python 3.11. Features JWT authentication, background task processing with Celery and Redis, automatic Swagger documentation, and unit tests. Implements post creation, image generation, file uploads to B2, and email notifications.
https://github.com/dejatori/store-api

async backend background-tasks celery docker fastapi jwt-authentication microservices pydantic pylint python redis rest-api sqlalchemy testing

Last synced: 2 months ago
JSON representation

Complete REST API built with FastAPI and Python 3.11. Features JWT authentication, background task processing with Celery and Redis, automatic Swagger documentation, and unit tests. Implements post creation, image generation, file uploads to B2, and email notifications.

Awesome Lists containing this project

README

          

# ๐Ÿš€ Mastering REST APIs with FastAPI

[![Python](https://img.shields.io/badge/Python-3.11-blue.svg)](https://www.python.org/downloads/)
[![FastAPI](https://img.shields.io/badge/FastAPI-0.112.2-green.svg)](https://fastapi.tiangolo.com/)
[![License](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Project from the "Mastering REST APIs with FastAPI" course by Packt, edited by David Toscano.

## ๐Ÿ“‹ Contents

- [Requirements](#requirements)
- [Installation](#installation)
- [Useful Commands](#useful-commands)
- [Project Structure](#project-structure)
- [Documentation](#documentation)
- [Contributing](#contributing)
- [License](#license)

## ๐Ÿ”ง Requirements

- Python 3.11
- Redis (for background tasks)
- Docker and Docker Compose (optional)

## ๐Ÿ’ป Installation

1. Clone this repository:
```bash
git clone https://github.com/Dejatori/Store-API.git
cd Store-API
```

2. Create a virtual environment and install dependencies:
```bash
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
pip install -r requirements-dev.txt
```

```bash
# Alternative with Conda
conda create --name fastapi python=3.11
conda activate fastapi
conda install --file requirements.txt
conda install --file requirements-dev.txt
```

3. Start the server:
```bash
uvicorn storeapi.main:app --reload
```

## ๐Ÿ› ๏ธ Useful Commands

### ๐Ÿงน Code Cleaning and Formatting

```bash
# Ruff linter and automatic formatting
ruff check --select I --fix .
ruff format .

# Black formatting
black .

# Isort import sorting
isort .
```

### ๐Ÿš€ Server Execution

```bash
uvicorn storeapi.main:app --reload
```

### ๐Ÿ”„ Redis Management

#### Windows (using Docker)

```bash
# Start Redis server
docker-compose up -d

# Check running containers
docker ps

# Stop services
docker-compose stop

# Restart services
docker-compose restart

# Remove containers and network
docker-compose down
```

#### Linux

```bash
# Start Redis server
sudo service redis-server start

# Check status
redis-cli ping
sudo service redis-server status

# Restart server
sudo service redis-server restart

# Stop server
sudo service redis-server stop
```

### ๐Ÿ”„ Celery for Background Tasks

```bash
celery -A storeapi.celery_app worker --pool=solo --loglevel=INFO
```

## ๐Ÿ“‚ Project Structure

```
storeapi/
โ”œโ”€โ”€ database/ # Database configuration and models
โ”œโ”€โ”€ models/ # Pydantic models for data validation
โ”œโ”€โ”€ routers/ # API endpoints
โ”œโ”€โ”€ security/ # Authentication and authorization
โ”œโ”€โ”€ tasks/ # Background tasks with Celery
โ””โ”€โ”€ main.py # Application entry point
```

## ๐Ÿ“š Documentation

The API documentation is available at the following routes once you start the server:

- ๐Ÿ“ **Swagger UI**: [http://localhost:8000/docs](http://localhost:8000/docs)
- ๐Ÿ“˜ **ReDoc**: [http://localhost:8000/redoc](http://localhost:8000/redoc)

Documentation is also available in the project's `docs/` directory.

- ๐Ÿ“„ **Project documentation in HTML**: [docs/build/html/index.html](docs/build/html/index.html)
- ๐Ÿ“„ **Project documentation in PDF**: [docs/build/latex/StoreAPI.pdf](docs/build/latex/StoreAPI.pdf)

## ๐Ÿค Contributing

Contributions are welcome. Please follow these steps:

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add an amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

## ๐Ÿ“„ License

This project is licensed under the terms of the MIT license. See the `LICENSE` file for more details.