<filename>src/common/config.py
from pydantic import BaseSettings


class Settings(BaseSettings):
    POSTGRES_HOST: str = 'localhost'
    POSTGRES_PORT: int = 5432
    POSTGRES_DB: str = 'postgres'
    POSTGRES_USER: str = 'postgres'
    POSTGRES_PASSWORD: str = '<PASSWORD>'
    DETECTIVE_URL: str = 'http://detective:3000/'
    SELENIUM_URL = 'http://selenium:4444/wd/hub'

    class Config:
        env_file = ".env"

    def _get_db_dsn(self, driver: str):
        return (f"postgresql+{driver}://{self.POSTGRES_USER}:{self.POSTGRES_PASSWORD}"
                f"@{self.POSTGRES_HOST}:{self.POSTGRES_PORT}/{self.POSTGRES_DB}")

    @property
    def async_db_dsn(self) -> str:
        return self._get_db_dsn('asyncpg')

    @property
    def sync_db_dsn(self) -> str:
        return self._get_db_dsn('psycopg2')


settings = Settings()

<filename>src/common/config.py
from pydantic import BaseSettings


class Settings(BaseSettings):
    POSTGRES_HOST: str = 'localhost'
    POSTGRES_PORT: int = 5432
    POSTGRES_DB: str = 'postgres'
    POSTGRES_USER: str = 'postgres'
    POSTGRES_PASSWORD: str = '<PASSWORD>'
    DETECTIVE_URL: str = 'http://detective:3000/'
    SELENIUM_URL = 'http://selenium:4444/wd/hub'

    class Config:
        env_file = ".env"

    def _get_db_dsn(self, driver: str):
        return (f"postgresql+{driver}://{self.POSTGRES_USER}:{self.POSTGRES_PASSWORD}"
                f"@{self.POSTGRES_HOST}:{self.POSTGRES_PORT}/{self.POSTGRES_DB}")

    @property
    def async_db_dsn(self) -> str:
        return self._get_db_dsn('asyncpg')

    @property
    def sync_db_dsn(self) -> str:
        return self._get_db_dsn('psycopg2')


settings = Settings()
