Add documentation about configuration and env vars#1118
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1118 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 224 225 +1
Lines 6728 6733 +5
=========================================
+ Hits 6728 6733 +5
Continue to review full report at Codecov.
|
to disambiguate between that and settings
|
Thanks for starting this! 🚀 🍰 I have been intending to add these docs for awhile 😅 So I updated it with what I had in mind and to include a couple of extra explanations. Thanks for your contribution! 🎉 🍰 |
|
Question to @alexmitelman : any benefit to using Pydantic vs. Starlette's baked-in configuration stuff? |
IMHO, Starlette solution looks more low level, while using Pydantic you just declare class as usual. Starlette from starlette.config import Config
config = Config(".env")
DEBUG = config('DEBUG', cast=bool, default=False)Pydantic from pydantic import BaseSettings
class Settings(BaseSettings):
debug: bool = False
class Config:
env_file = '.env' |
|
@alexmitelman that's a description of syntax, not a functional differentiation. It also does not really explain the strengths / benefits of that syntactical difference, or if there is one. I've now used both. IMO - given FastAPI's reliance on simplicity, I think Starlette's setup should be the preferred structure for the following three reasons:
That said - I've very recently taken to using Pydantic for settings management in larger projects for the following three reasons:
Those three reasons are compelling (don't get me wrong, Pydantic is amazing; I use it in everything) but I'd imagine the first three would make Starlette's config preferable in most situations. |
|
I was surprised by this change, @leosussan summarized what I needed to know. |
In this pull request I add a new documentation page that describes the way to work with environment variables.
Related to this #190 and this #399 issues.