title | emoji | colorFrom | colorTo | sdk | python_version |
---|---|---|---|---|---|
Docpet Backend Service |
👨⚕️ |
purple |
green |
docker |
3.9 |
This guide walks you through setting up a FastAPI project with PostgreSQL using Docker and integrating Alembic for database migrations.
- Docker installed on your machine
- Python and pip install
pip install -r requirements.txt
Run the following commands in your terminal:
docker-compose up -d
docker-compose down
pip install fastapi[all]
pip install sqlalchemy psycopg2
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:
{
"message": "Hello World!"
}
docker exec -it postgres psql -U postgres
CREATE USER admin WITH PASSWORD 'your_password';
GRANT ALL PRIVILEGES ON DATABASE docpet TO admin;
docker exec -it <container name> bash
Access the running Postgres database with the command:
psql -U admin <database name>
Execute the following SQL command to display and install the uuid-ossp extension:
select * from pg_available_extensions;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
Execute the following SQL command to display and install the uuid-ossp extension:
pip install alembic
alembic init alembic
alembic revision --autogenerate -m "create users table"
alembic upgrade head
FastAPI automatically generates API documentation complying with OpenAPI standards.
Visit http://localhost:8000/docs to explore the API documentation.