Better Programming

Advice for programmers.

Follow publication

Member-only story

5 Python Modules That Make Building APIs Easier

Tate Galbraith
Better Programming
Published in
6 min readNov 23, 2022
Photo by Fotis Fotopoulos on Unsplash

APIs run our digital world. Nearly every website on the planet will leverage an API at some point. Whether they’re grabbing data from a backend or performing complex calculations, the chances of API calls being present on a modern site are almost 100%.

Since these services sit at the core of many gigantic products, you’d think prototyping them would be simple and fast. This isn’t always the case. There are hidden complexities in building out a robust API. Thankfully, with Python, you have a ton of battle-tested tools at your disposal. Tools that let you develop, test, and ship APIs faster than ever before. The best part is you don’t have to waste time with a bunch of boilerplate code.

In this article, we will explore a few Python modules that are geared towards building and testing APIs. These modules showcase just how quickly you can bring your API ideas to life with minimal hassle.

1. FastAPI

Source.

FastAPI is fast. You can prototype an API faster than many other platforms. This is a full framework for building APIs and boasts an exceptionally clean syntax for defining your endpoints. Simply add a decorator, return some data and you’re off to the races.

Check out a super short example below. In this example we define a single route with a GET method at the root of the application:

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def get_root():
return {"response": "hello"}

This method will serve up a simple JSON response to whoever hits the endpoint. While this is a rudimentary example, it shows just how little code you need to build an endpoint.

You can run this example using the uvicorn module by executing:

python3 -m uvicorn main:app

FastAPI obfuscates away all of the messy request/response handling and leaves you with a slick, clean interface for building your API. It also allows you to build using type hints from Python and by…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Tate Galbraith
Tate Galbraith

Written by Tate Galbraith

Software Engineer @mixhalo & die-hard Rubyist. Amateur Radio operator with a love for old technology. Tweet at me: https://twitter.com/@Tate_Galbraith

Responses (1)

Write a response