Meet Thomes Jewitt: Get to Know FastAPI in This Introductory Talk

Posted by


FastAPI is a modern web framework for building APIs with Python. It’s fast, easy to use, and highly efficient, making it a popular choice for developers looking to create robust APIs quickly. In this tutorial, we’ll be covering the basics of FastAPI, as well as introducing you to a handy tool called TALK created by Thomas Jewitt that makes working with FastAPI even easier.

Before we get started, make sure you have Python installed on your machine. You can download Python from the official website if you don’t already have it installed.

First, let’s start by creating a new virtual environment for our project. Open a terminal or command prompt and create a new folder for your project. Then, run the following command to create a virtual environment:

python -m venv env

Next, activate the virtual environment by running the following command:

source env/bin/activate (for Unix systems) or .envScriptsactivate (for Windows systems)

Now that we have our virtual environment set up, let’s install FastAPI and TALK. Run the following commands in your terminal:

pip install fastapi
pip install uvicorn
pip install talk

With FastAPI and TALK installed, let’s create a simple FastAPI app. Create a new Python file in your project folder and import the necessary modules:

from fastapi import FastAPI
from talk.core import TALK

Next, create a new FastAPI app instance:

app = FastAPI()

Now, let’s add a simple route to our FastAPI app that will return a greeting message. Add the following code to your Python file:

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

Now, let’s start our FastAPI app using the uvicorn server. Run the following command in your terminal:

uvicorn filename:app --reload

Replace filename with the name of your Python file. Once the server is running, open a web browser and navigate to http://localhost:8000/. You should see a JSON response with the greeting message.

Now that we have a basic FastAPI app up and running, let’s introduce TALK. TALK is a tool created by Thomas Jewitt that provides interactive documentation for FastAPI apps. To enable TALK in your FastAPI app, we need to import it and add it as a middleware.

Add the following code to your Python file:

app.add_middleware(TALK, path='/api/docs')

Now, when you restart your FastAPI app and navigate to http://localhost:8000/api/docs in your web browser, you should see the TALK interactive documentation page for your FastAPI app.

In this tutorial, we covered the basics of FastAPI and introduced you to TALK, a tool created by Thomas Jewitt that provides interactive documentation for FastAPI apps. By following these steps, you should now have a basic understanding of how to create APIs with FastAPI and use TALK to enhance their documentation. Experiment with different routes and functionalities to further explore the capabilities of FastAPI and TALK. Happy coding!

0 0 votes
Article Rating
3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@ddwax89
1 month ago

I wll start using fast api from now. Thanks

@brainscott
1 month ago

Thanks Thomas, Great content, learned a few things as I'm a few months in on FastAPI

@f1l4nn1m
1 month ago

Superb presentation! Simple, effective and spot on!