Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Why not use an asynchronous approach to write the code? #1446

Unanswered
jyaymusk asked this question in Questions
Discussion options

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_
You must be logged in to vote

Replies: 1 comment

Comment options

Was wondering the same. And i believe the previous version of this template used the async approach.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested

AltStyle によって変換されたページ (->オリジナル) /