Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/belajarqywok/docpet_backend
Back-End services that are distributed and integrated with Cloud Computing and Machine Learning services in the Docpet Application service.
https://github.com/belajarqywok/docpet_backend
alembic fastapi restful-api swagger-ui tensorflow
Last synced: about 1 month ago
JSON representation
Back-End services that are distributed and integrated with Cloud Computing and Machine Learning services in the Docpet Application service.
- Host: GitHub
- URL: https://github.com/belajarqywok/docpet_backend
- Owner: belajarqywok
- Created: 2023-12-06T00:44:54.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-21T05:51:14.000Z (2 months ago)
- Last Synced: 2024-10-21T08:39:47.011Z (2 months ago)
- Topics: alembic, fastapi, restful-api, swagger-ui, tensorflow
- Language: Python
- Homepage:
- Size: 39.1 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
---
title: Docpet Backend Service
emoji: 👨⚕️
colorFrom: purple
colorTo: green
sdk: docker
python_version: "3.9"
---# Backend with FastAPI Docker Setup Guide
This guide walks you through setting up a FastAPI project with PostgreSQL using Docker and integrating Alembic for database migrations.
## Prerequisites
- Docker installed on your machine
- Python and pip install
```bash
pip install -r requirements.txt
```## Step 1: Init and Setup Project
Run the following commands in your terminal:
```bash
docker-compose up -d
docker-compose down
```## Step 2: Start PostgreSQL Docker Container
```bash
pip install fastapi[all]
pip install sqlalchemy psycopg2
```## Step 3: Start FastAPI Server
```bash
uvicorn app.main:app --host localhost --port 8000 --reload
```Make a GET request to http://localhost:8000/api/healthchecker in Postman or any API testing tool to verify the response:
```bash
{
"message": "Hello World!"
}
```
## Step 4: access the PostgreSQL Command Line in the Docker container and create admin role and grant
```bash
docker exec -it postgres psql -U postgresCREATE USER admin WITH PASSWORD 'your_password';
GRANT ALL PRIVILEGES ON DATABASE docpet TO admin;
```## Step 5: Access PostgreSQL Docker Container Shell
```bash
docker exec -it bash
```Access the running Postgres database with the command:
```bash
psql -U admin
```## Step 6: Install uuid-ossp Plugin
Execute the following SQL command to display and install the uuid-ossp extension:
```bash
select * from pg_available_extensions;CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
```## Step 7: Initialize Alembic for Database Migrations
Execute the following SQL command to display and install the uuid-ossp extension:
```bash
pip install alembic
alembic init alembic
```## Step 8: Create a Revision File for Database Changes
```bash
alembic revision --autogenerate -m "create users table"
```## Step 9: Apply Database Changes
```bash
alembic upgrade head
```## Step 10: View Documentation
FastAPI automatically generates API documentation complying with OpenAPI standards.
```bash
Visit http://localhost:8000/docs to explore the API documentation.
```