Skip to content

Commit ceb70a9

Browse files
committed
init
0 parents  commit ceb70a9

5 files changed

Lines changed: 44 additions & 0 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
__pycache__
2+
env

project/app/__init__.py

Whitespace-only changes.

project/app/config.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# project/app/config.py
2+
3+
4+
import logging
5+
import os
6+
from functools import lru_cache
7+
8+
from pydantic import BaseSettings
9+
10+
11+
log = logging.getLogger(__name__)
12+
13+
14+
class Settings(BaseSettings):
15+
environment: str = os.getenv("ENVIRONMENT", "dev")
16+
testing: bool = os.getenv("TESTING", 0)
17+
18+
19+
@lru_cache()
20+
def get_settings() -> BaseSettings:
21+
log.info("Loading config settings from the environment...")
22+
return Settings()

project/app/main.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# project/app/main.py
2+
3+
4+
from fastapi import FastAPI, Depends
5+
6+
from app.config import get_settings, Settings
7+
8+
9+
app = FastAPI()
10+
11+
12+
@app.get("/ping")
13+
async def pong(settings: Settings = Depends(get_settings)):
14+
return {
15+
"ping": "pong!",
16+
"environment": settings.environment,
17+
"testing": settings.testing
18+
}

project/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fastapi==0.55.1
2+
uvicorn==0.11.5

0 commit comments

Comments
 (0)