Introduction to FastAPI by Łukasz Piotrkowski | Software Profile

Posted by


FastAPI is a modern, fast (high-performance) web framework for building APIs with Python 3.6+ based on standard Python type hints. It is designed to be easy to use and quick to develop with, making it a popular choice for developers looking to build web applications and APIs.

In this tutorial, we will introduce you to FastAPI and cover the basics of how to get started with building APIs using this framework. Specifically, we will be following along with Łukasz Piotrkowski’s tutorial on FastAPI, which can be found on his Profile Software page.

Let’s get started by installing FastAPI. You can install FastAPI using pip, the Python package installer. Open up a terminal or command prompt and run the following command:

pip install fastapi

Next, you will also need to install an ASGI server, such as uvicorn, which will allow you to run your FastAPI application. You can install uvicorn using pip as well:

pip install uvicorn

Once you have FastAPI and uvicorn installed, you can start building your first FastAPI application. Create a new Python file and import the necessary modules:

from fastapi import FastAPI

Next, create an instance of the FastAPI class, which will be your application:

app = FastAPI()

Now, you can start defining your API endpoints using FastAPI’s decorators. Let’s create a simple endpoint that returns a greeting when you access it:

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

In this example, we defined a GET endpoint at the root URL ("/") that returns a JSON response with the message "Hello World". You can run your FastAPI application using the uvicorn server:

uvicorn app:app --reload

This command will start the uvicorn server and load your FastAPI application. You can access your API by visiting http://127.0.0.1:8000 in your web browser.

In Łukasz Piotrkowski’s tutorial on FastAPI, he covers more advanced topics, such as handling request parameters, defining schema models, handling errors, and deploying FastAPI applications. You can follow along with his tutorial to learn more about how to build powerful APIs with FastAPI.

Overall, FastAPI is a powerful and efficient web framework for building APIs with Python. It’s easy to use, fast, and has a great developer experience. If you’re looking to build APIs quickly and efficiently, FastAPI is a great choice. I hope this tutorial has helped you get started with FastAPI and that you continue to explore this powerful framework.

0 0 votes
Article Rating

Leave a Reply

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@patrykpiesiak9370
4 hours ago

mowisz w o wiele zbyt skomplikowany sposób. Laik kompletnie nie zrozumie

1
0
Would love your thoughts, please comment.x
()
x