Files
Database-FastAPI-Python-Bac…/README.md
Cookiez 17d3b1caac Add .env-example file and update configuration for environment variables
- Created .env-example for environment variable setup
- Updated README to reflect changes in .env file creation
- Modified config.py to include new environment variables and DATABASE_URL property
- Enhanced database.py with connect and disconnect functions
- Updated main.py to manage database connection lifecycle
- Adjusted compose.yaml for consistent environment variable usage
2026-02-24 13:38:54 +01:00

1.9 KiB

Project Name

Short one-line description of what this project does.

Tech Stack

  • FastAPI — Python REST API framework
  • PostgreSQL — Relational database
  • SQLAlchemy — Async database connection layer
  • Docker / Docker Compose — Containerized development environment

Project Structure

project/
├──Create.sql — Database schema and seed data
├──docker-compose.yml
├──Dockerfile
├──requirements.txt
├──.env — Local environment variables (not committed)
└──app/
    ├── main.py — App entry point, router registration
    ├── config.py — Environment variable configuration
    ├── database.py — Database connection and session
    └── routers/
        ├── init.py
        └── example.py — Route definitions

Getting Started

Prerequisites

Setup

Create a .env file, by copying .env-example, in the root directory and adjustign the vaulues as needed:

POSTGRES_USER=exampleUser
POSTGRES_PASSWORD=examplePasswd
POSTGRES_DB=exampleDB
API_PORT=8000
DEBUG=true

Start the stack:

docker compose up --build

The API will be available at http://localhost:8000. Interactive API docs are at http://localhost:8000/docs. Resetting the Database

If you need to reinitialize the database (e.g. after changing Create.sql):

docker compose down
rm -rf ./postgresData
docker compose up --build

⚠️ This will delete all data. Do not run in production.


The database schema is managed via Create.sql — no ORM migrations

The .env file is excluded from version control via .gitignore