-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsettings.py
More file actions
65 lines (48 loc) · 2.14 KB
/
settings.py
File metadata and controls
65 lines (48 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os
from typing import Optional
import pydantic
ENV_FILE = os.getenv("ENV_FILE", ".env")
class BaseSettings(pydantic.BaseSettings):
"""Base class for loading settings.
The setting variables are loaded from environment settings first, then from the defined env_file.
Different groups/contexts of settings are created using different classes, that can define an env_prefix which
will be concatenated to the start of the variable name."""
class Config:
env_file = ENV_FILE
class APISettings(BaseSettings):
"""Settings related with the FastAPI server"""
host: str = "0.0.0.0"
port: int = 5000
class Config(BaseSettings.Config):
env_prefix = "API_"
class APIDocsSettings(BaseSettings):
"""Settings related with the API autogenerated documentation"""
title: str = "{{ cookiecutter.app_name }}"
"""Title of the API"""
description: Optional[str] = None
"""Description of the API"""
version: str = "version"
"""Version of the API"""
{%- if cookiecutter.advanced_docs == "yes" %}
custom_logo: Optional[str] = None
"""URL of a custom logo to show in ReDoc (if not set, no logo will be shown)"""
static_path: Optional[str] = None
"""Path (absolute or relative) where to load static files from, used for the generated documentation.
If set, both OpenAPI/Swagger and ReDoc will load the required files from there, instead of the default CDN.
More information available in FastAPI documentation:
https://fastapi.tiangolo.com/advanced/extending-openapi/#download-the-files
- Swagger UI requires the files "swagger-ui.bundle.js", "swagger-ui.css", "favicon.ico"
- ReDoc requires the file "redoc.standalone.js", "favicon.ico"
"""
{%- endif %}
class Config(BaseSettings.Config):
env_prefix = "API_DOCS_"
class RequestLoggingSettings(BaseSettings):
"""Settings related with the logging of requests"""
level: str = "DEBUG"
serialize: bool = False
class Config(BaseSettings.Config):
env_prefix = "REQUEST_LOG_"
api_settings = APISettings()
api_docs_settings = APIDocsSettings()
request_logging_settings = RequestLoggingSettings()