5 Steps to Create API’s at Warp Speed 

Supercharge your dev skills and build your API in record time using Python and FastAPI

March 9, 2023

By: Michael Cardoza

Quit dawdling with slow and outdated approaches and say goodbye to the tedious process of building APIs from scratch!

Welcome lightning-fast development with the ultimate time-saving allies – Python and FastAPI! 

Zip ahead with this dynamic duo and experience the high speed and efficiency they can deliver following five simple steps! 

1. The first step is to create an environment for the application using Python3. 

1  $ mkdir app && cd app
2  $ python3 -m venv venv
3  $ source venv/bin/activate

2. Install the required packages to start building the app. 

1  $ pip install fastapi
2  $ pip install "uvicorn[standard]"

3. It’s time to start writing our first script using FastAPI. This will be the main file to start the application.

1  from typing import Union
3  from fastapi import FastAPI
5  app = FastAPI()
8  @app.get("/")
9  def read_root():
10    return {"say-hello": "Hello Bits Kingdom"}
13 @app.get("/items/{item_id}")
14 def read_item(item_id: int, q: Union[str, None] = None):
15 return {"item_id": item_id, "q": q}

4. Run uvicorn in your terminal

1  $ uvicorn main:app --reload
3  INFO:     Uvicorn running on (Press CTRL+C to quit)
4  INFO:     Started reloader process [28720]
5  INFO:     Started server process [28722]
6  INFO:     Waiting for application startup.
7  INFO:     Application startup complete.

5. Finally, it’s time to check it. Open your browser at or

1  {
2  "say-hello": "Hello Bits Kingdom"
3  }

Can’t get enough of our Bits Tips? Our dev experts are constantly chipping in with tips that help you improve your coding in a snap! Check out these Terminal, Shell, or Console secrets from a super coder! 

✍🏾 This article was written by our copywriter, Sofia, in collaboration with our DEV expert, Michael.