Self-paced

Explore our extensive collection of courses designed to help you master various subjects and skills. Whether you're a beginner or an advanced learner, there's something here for everyone.

Bootcamp

Learn live

Join us for our free workshops, webinars, and other events to learn more about our programs and get started on your journey to becoming a developer.

Upcoming live events

Learning library

For all the self-taught geeks out there, here is our content library with most of the learning materials we have produced throughout the years.

It makes sense to start learning by reading and watching videos about fundamentals and how things work.

Search from all Lessons


LoginGet Started

Start interactive tutorial

← Back to Projects

Develop a Basic Inventory API with FastAPI

Difficulty

  • easy

Average duration

4 hrs

Technologies

Difficulty

  • easy

Average duration

4 hrs

Technologies

📝 Instructions

🌱 How to start this project?

Do not clone this repository because we will use a different template.

We recommend opening the project using Codespaces (recommended) or Gitpod. Alternatively, you can clone the repository to your local computer using git clone.

This is the base repository you need to use:

https://github.com/4GeeksAcademy/python-hello

⚠ You will need Python installed if working locally, but everything is preconfigured in Codespaces or Gitpod.

📝 Instructions

Step 1: Set Up Your Environment

1pip install fastapi uvicorn

Step 2: Define the Inventory Model

Example:

1from pydantic import BaseModel 2 3class Item(BaseModel): 4 id: int 5 name: str 6 quantity: int 7 price: float

Step 3: Create the API Routes

Basic example:

1from fastapi import FastAPI 2 3app = FastAPI() 4 5inventory = [] 6 7@app.get("/items") 8def get_items(): 9 return inventory 10 11@app.post("/items") 12def add_item(item: Item): 13 inventory.append(item) 14 return item

Step 4: Test Your API

Step 5: Add Optional Features

Bonus Section

Additional Features to Practice

  1. Authentication: Implement a basic authentication system to access the API.
  2. Export Data: Add the option to export inventory data to a CSV or JSON file.
  3. Deploy: Publish your API to a service like Heroku, Render, or Deta.
  4. Advanced Validation: Use Pydantic to add extra validations to your models.

Explore different enhancements to make your API more functional and useful!

Signup and get access to this project for free

We will use it to give you access to your account.
Already have an account? Login here.

By signing up, you agree to the Terms and conditions and Privacy policy.

Difficulty

  • easy

Average duration

4 hrs

Technologies

Difficulty

  • easy

Average duration

4 hrs

Technologies

Difficulty

  • easy

Average duration

4 hrs

Technologies

Difficulty

  • easy

Average duration

4 hrs

Technologies

Signup and get access to this project for free

We will use it to give you access to your account.
Already have an account? Login here.

By signing up, you agree to the Terms and conditions and Privacy policy.

Difficulty

  • easy

Average duration

4 hrs

Technologies

Difficulty

  • easy

Average duration

4 hrs

Technologies

Supplementary Material

In order to prepare better for completing this exercises, we suggest the following materials

How to

How to Code in Python?

Exercise

Learn Python Functions Interactively

Exercise

Learn how to build HTTP requests with Python