close

How can I run the fast-api server using Pycharm?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How can I run the fast-api server using Pycharm in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How can I run the fast-api server using Pycharm?

  1. How can I run the fast-api server using Pycharm?

    Try to call uvicorn inside your code. e.g:
    from fastapi import FastAPI import uvicorn app = FastAPI()

  2. I run the fast-api server using Pycharm

    Try to call uvicorn inside your code. e.g:
    from fastapi import FastAPI import uvicorn app = FastAPI()

Method 1

You can do it without adding code to main.py

  1. In target to run instead of Script path choose Module name
  2. In Module name type uvicorn
  3. In parameters app.main:app --reload --port 5000
enter image description here

Method 2

Try to call uvicorn inside your code. e.g:

from fastapi import FastAPI
import uvicorn

app = FastAPI()


@app.get("/")
async def read_root():
    return {"Hello": "World"}

if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=5000, log_level="info")

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read