-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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. |
* Add doc and example for env var config * Syntax highlight for .env file * Add test for configuration docs * 📝 Update settings docs, add more examples * ✅ Add tests for settings * 🚚 Rename "Application Configuration" to "Metadata and Docs URLs" to disambiguate between that and settings * 🔥 Remove replaced example file Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
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.