-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
-
First Check
- I added a very descriptive title here.
- I used the GitHub search to find a similar question and didn't find it.
- I searched in the documentation/README.
- I already searched in Google "How to do X" and didn't find any information.
- I already read and followed all the tutorial in the docs/README and didn't find an answer.
Commit to Help
- I commit to help with one of those options 👆
Example Code
async @router.post("/login/access-token")
def login_access_token(
session: SessionDep, form_data: Annotated[OAuth2PasswordRequestForm, Depends()]
) -> Token:
"""
OAuth2 compatible token login, get an access token for future requests
"""
user = crud.authenticate(
session=session, email=form_data.username, password=form_data.password
)
if not user:
raise HTTPException(status_code=400, detail="Incorrect email or password")
elif not user.is_active:
raise HTTPException(status_code=400, detail="Inactive user")
access_token_expires = timedelta(minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES)
return Token(
access_token=security.create_access_token(
user.id, expires_delta=access_token_expires
)
)
### Description
In the code of this project, I noticed that a synchronous approach is used, and all the APIs are non-asynchronous. I believe using asynchronous programming might be better, as it could better leverage FastAPI’s advantages. Of course, if the difference is not significant, using a synchronous approach could still work fine. I'm just not sure how big the difference really is, but I would recommend using the asynchronous approach.
### Operating System
macOS
### Operating System Details
MacOs
### Python Version
3.13
### Additional Context
_No response_
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
Was wondering the same. And i believe the previous version of this template used the async approach.
Beta Was this translation helpful? Give feedback.
All reactions
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment