105800 Views
82496 Views
47243 Views
47066 Views
45458 Views
38527 Views
Pi-Apps
Intermediate MicroPython
Arduino Alvik
Raspberry Pi Time machine
Now Ad-Free
Guiding Light
Intermediate level MicroPython
Introduction to FreeCAD for Beginners
Building a Robot Arm with Raspberry Pi and PCA9685
Building User Authentication for Static Sites with FastAPI
Mastering Pydantic for Robust Data Validation
Mastering Markdown for Documentation with Jekyll
KevsRobots Learning Platform
22% Percent Complete
By Kevin McAleer, 2 Minutes
Before diving into coding, it’s essential to prepare a development environment that’s robust, isolated, and capable of handling our project’s needs. This setup ensures that you can develop and test your application with consistency and reliability.
FastAPI requires Python 3.7+. If you haven’t installed Python yet or are using an older version, download and install the latest Python version from the official Python website.
A virtual environment is a self-contained directory that contains a Python installation for a particular version of Python, plus a number of additional packages. Using a virtual environment allows you to manage dependencies for different projects, avoiding conflicts between package versions.
To create a virtual environment, run the following commands in your terminal:
python -m venv fastapi-env
To activate the virtual environment, use:
fastapi-env\Scripts\activate.bat
source fastapi-env/bin/activate
With your virtual environment activated, install FastAPI and Uvicorn (an ASGI server for running your application) using pip:
pip install fastapi uvicorn
Create a new directory for your project and navigate into it:
mkdir fastapi_auth_project cd fastapi_auth_project
Within this directory, create a new file named main.py. This file will serve as the entry point for our FastAPI application.
main.py
You’ve now set up your development environment, including Python, a virtual environment, and necessary packages like FastAPI and Uvicorn. In the next lesson, we’ll dive into the basics of FastAPI and start building our user authentication system.
Try installing another Python package within your virtual environment and see how it is isolated from the global Python installation. Reflect on how using virtual environments can benefit the development process, especially when working on multiple projects.
< Previous Next >