Files
Database-FastAPI-Python-Bac…/app/config.py
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

24 lines
531 B
Python

from pydantic_settings import BaseSettings
from pydantic import computed_field
class Settings(BaseSettings):
POSTGRES_USER: str
POSTGRES_PASSWORD: str
POSTGRES_DB: str
API_PORT: int = 8000
DEBUG: bool = False
@computed_field
@property
def DATABASE_URL(self) -> str:
return (
f"postgresql+asyncpg://"
f"{self.POSTGRES_USER}:{self.POSTGRES_PASSWORD}"
f"@db/{self.POSTGRES_DB}"
)
class Config:
env_file = ".env"
settings = Settings()