Skip to content
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

fix(deps): update dependency fastapi to ^0.95.0 #2217

Merged
merged 1 commit into from
Mar 21, 2023

Conversation

renovate[bot]
Copy link
Contributor

@renovate renovate bot commented Mar 7, 2023

Mend Renovate

This PR contains the following updates:

Package Change Age Adoption Passing Confidence
fastapi ^0.92.0 -> ^0.95.0 age adoption passing confidence

Release Notes

tiangolo/fastapi

v0.95.0

Compare Source

Highlights

This release adds support for dependencies and parameters using Annotated and recommends its usage. ✨

This has several benefits, one of the main ones is that now the parameters of your functions with Annotated would not be affected at all.

If you call those functions in other places in your code, the actual default values will be kept, your editor will help you notice missing required arguments, Python will require you to pass required arguments at runtime, you will be able to use the same functions for different things and with different libraries (e.g. Typer will soon support Annotated too, then you could use the same function for an API and a CLI), etc.

Because Annotated is standard Python, you still get all the benefits from editors and tools, like autocompletion, inline errors, etc.

One of the biggest benefits is that now you can create Annotated dependencies that are then shared by multiple path operation functions, this will allow you to reduce a lot of code duplication in your codebase, while keeping all the support from editors and tools.

For example, you could have code like this:

def get_current_user(token: str):

### authenticate user
    return User()

@​app.get("/items/")
def read_items(user: User = Depends(get_current_user)):
    ...

@​app.post("/items/")
def create_item(*, user: User = Depends(get_current_user), item: Item):
    ...

@​app.get("/items/{item_id}")
def read_item(*, user: User = Depends(get_current_user), item_id: int):
    ...

@​app.delete("/items/{item_id}")
def delete_item(*, user: User = Depends(get_current_user), item_id: int):
    ...

There's a bit of code duplication for the dependency:

user: User = Depends(get_current_user)

...the bigger the codebase, the more noticeable it is.

Now you can create an annotated dependency once, like this:

CurrentUser = Annotated[User, Depends(get_current_user)]

And then you can reuse this Annotated dependency:

CurrentUser = Annotated[User, Depends(get_current_user)]

@​app.get("/items/")
def read_items(user: CurrentUser):
    ...

@​app.post("/items/")
def create_item(user: CurrentUser, item: Item):
    ...

@​app.get("/items/{item_id}")
def read_item(user: CurrentUser, item_id: int):
    ...

@​app.delete("/items/{item_id}")
def delete_item(user: CurrentUser, item_id: int):
    ...

...and CurrentUser has all the typing information as User, so your editor will work as expected (autocompletion and everything), and FastAPI will be able to understand the dependency defined in Annotated. 😎

Roughly all the docs have been rewritten to use Annotated as the main way to declare parameters and dependencies. All the examples in the docs now include a version with Annotated and a version without it, for each of the specific Python versions (when there are small differences/improvements in more recent versions). There were around 23K new lines added between docs, examples, and tests. 🚀

The key updated docs are:

Special thanks to @​nzig for the core implementation and to @​adriangb for the inspiration and idea with Xpresso! 🚀

Features
  • ✨Add support for PEP-593 Annotated for specifying dependencies and parameters. PR #​4871 by @​nzig.
Docs
  • 📝 Tweak tip recommending Annotated in docs. PR #​9270 by @​tiangolo.
  • 📝 Update order of examples, latest Python version first, and simplify version tab names. PR #​9269 by @​tiangolo.
  • 📝 Update all docs to use Annotated as the main recommendation, with new examples and tests. PR #​9268 by @​tiangolo.

v0.94.1

Compare Source

Fixes

v0.94.0

Compare Source

Upgrades
Docs
Translations
  • 🌐 Add Russian translation for docs/ru/docs/history-design-future.md. PR #​5986 by @​Xewus.
Internal

v0.93.0

Compare Source

Features
  • ✨ Add support for lifespan async context managers (superseding startup and shutdown 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
  • ✏ Fix formatting in docs/en/docs/tutorial/metadata.md for ReDoc. PR #​6005 by @​eykamp.
Translations
Internal

Configuration

📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR has been generated by Mend Renovate. View repository job log here.

@renovate renovate bot force-pushed the renovate/fastapi-0.x branch from 7ce4abf to 9dc02c6 Compare March 10, 2023 20:52
@renovate renovate bot changed the title fix(deps): update dependency fastapi to ^0.93.0 fix(deps): update dependency fastapi to ^0.94.0 Mar 10, 2023
@renovate renovate bot force-pushed the renovate/fastapi-0.x branch 2 times, most recently from 502f656 to 461af8d Compare March 15, 2023 18:30
@renovate renovate bot changed the title fix(deps): update dependency fastapi to ^0.94.0 fix(deps): update dependency fastapi to ^0.95.0 Mar 19, 2023
@renovate renovate bot force-pushed the renovate/fastapi-0.x branch from 461af8d to f6622d5 Compare March 19, 2023 00:10
@hay-kot hay-kot merged commit 6b63c75 into mealie-next Mar 21, 2023
@hay-kot hay-kot deleted the renovate/fastapi-0.x branch March 21, 2023 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant