Git Product home page Git Product logo

rest-api's Introduction

REST API with FastAPI, PostgreSQL, Alembic, SQLAlchemy and Minio (S3 cloud storage)

flake8-linter

FastAPI is a Python framework and set of tools that allow developers to invoke commonly used functions using a REST interface.

SQLAlchemy is a package that makes it easier for Python programs to communicate with databases. Most of the time, this library is used as an Object Relational Mapper (ORM) tool, which automatically converts function calls to SQL queries and translates Python classes to tables on relational databases.

Many web, mobile, geospatial, and analytics applications use PostgreSQL as their primary data storage or data warehouse.

Alembic is a lightweight database migration tool for usage with the SQLAlchemy Database Toolkit for Python.

Minio is a popular open source object storage server compatible with Amazon S3 cloud storage.

How to run the REST API

Get this project from Github

git clone https://github.com/sav116/REST-API

Installing PostgreSQL

Adding environment variables

SRC_DB_DATA=~/db_data
POSTGRES_DB=back_end
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres

Creating directory for volume of database

mkdir $SRC_DB_DATA

Starting db container

docker run -d --name my_postgres \
 -v $SRC_DB_DATA:/var/lib/postgresql/data -p 5432:5432 \
 -e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
 -e POSTGRES_USER=$POSTGRES_USER \
 -e POSTGRES_DB=$POSTGRES_DB \
 postgres:14

Installing Minio

Adding environment variables

SRC_MINIO_DATA=~/minio_data
MINIO_BUCKET=bucket

Starting minio container

docker run --name my_minio -d -v $SRC_MINIO_DATA:/data \
  -p 9000:9000 \
  -p 9001:9001 \
  minio/minio server /data --console-address ":9001"

Installing minio-client for creating bucket

OS X:

wget https://dl.minio.io/client/mc/release/darwin-amd64/mc

Linux:

wget https://dl.minio.io/client/mc/release/linux-amd64/mc

Making executable and rename it

chmod +x mc && mv mc minio-client

Creating bucket

./minio-client alias set minio http://localhost:9000 minioadmin minioadmin
./minio-client mb minio/$MINIO_BUCKET

Migration db schema using Alembic

Installing Alembic

cd REST-API && pip install alembic psycopg2 environs

Creating new schema version

alembic revision --autogenerate -m "added table items"

Starting migrations

alembic upgrade head

Building and starting application

docker build -t back_end . && docker run -p 8080:8080 -it back_end

Swagger available to http://0.0.0.0:8080/docs

Author

Artem Solovev

rest-api's People

Contributors

sav116 avatar

Stargazers

 avatar Noyan Tendikov avatar Shirvani Akhmedov avatar Katya avatar Aleksey Karpov avatar Reinholds Zviedris avatar Arian avatar Mark avatar HeisenBerg? avatar huyunlei avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.