Features
- ✨ Add support for
lifespan
async context managers (supersedingstartup
andshutdown
events). Initial PR #2944 by @uSpike.
Now, instead of using independent startup
and shutdown
events, you can define that logic in a single function with yield
decorated with @asynccontextmanager
(an async context manager).
For example:
from contextlib import asynccontextmanager
from fastapi import FastAPI
def fake_answer_to_everything_ml_model(x: float):
return x * 42
ml_models = {}
@asynccontextmanager
async def lifespan(app: FastAPI):
# Load the ML model
ml_models["answer_to_everything"] = fake_answer_to_everything_ml_model
yield
# Clean up the ML models and release the resources
ml_models.clear()
app = FastAPI(lifespan=lifespan)
@app.get("/predict")
async def predict(x: float):
result = ml_models["answer_to_everything"](x)
return {"result": result}
Note: This is the recommended way going forward, instead of using startup
and shutdown
events.
Read more about it in the new docs: Advanced User Guide: Lifespan Events.
Docs
Translations
- 🌐 Tamil translations - initial setup. PR #5564 by @gusty1g.
- 🌐 Add French translation for
docs/fr/docs/advanced/path-operation-advanced-configuration.md
. PR #9221 by @axel584. - 🌐 Add French translation for
docs/tutorial/debugging.md
. PR #9175 by @frabc. - 🌐 Initiate Armenian translation setup. PR #5844 by @har8.
- 🌐 Add French translation for
deployment/manually.md
. PR #3693 by @rjNemo.
Internal
- 👷 Update translation bot messages. PR #9206 by @tiangolo.
- 👷 Update translations bot to use Discussions, and notify when a PR is done. PR #9183 by @tiangolo.
- 🔧 Update sponsors-badges. PR #9182 by @tiangolo.
- 👥 Update FastAPI People. PR #9181 by @github-actions[bot].
- 🔊 Log GraphQL errors in FastAPI People, because it returns 200, with a payload with an error. PR #9171 by @tiangolo.
- 💚 Fix/workaround GitHub Actions in Docker with git for FastAPI People. PR #9169 by @tiangolo.
- ♻️ Refactor FastAPI Experts to use only discussions now that questions are migrated. PR #9165 by @tiangolo.
- ⬆️ Upgrade analytics. PR #6025 by @tiangolo.
- ⬆️ Upgrade and re-enable installing Typer-CLI. PR #6008 by @tiangolo.