Typical Project Setup
Now that you have installed the required software, it's time to create a basic FastAPI project. In this section, we'll guide you through creating a new project, configuring your development tools, and setting up a basic API structure.
Because FastAPI apps can be more complex (and Health Universe is primarily a deployment, not a development environment), it is best to have a local development environment that is linked to your GitHub repository.
Step 1: Create a GitHub Repository
Go to GitHub and create a new public repository. At this time, the repo must be public in order for Health Universe to be able to deploy your project.
Step 2: Clone Your Repository
Step 3: Set Up a Virtual Environment
Setting up a virtual environment for your Health Universe projects is required as it creates the requirements.txt file needed to specify your application's dependencies. To create a virtual environment, follow these steps:
Open a terminal and navigate to your desired project directory.
Create a new virtual environment with the following command:
Activate the virtual environment:
Windows:
macOS and Linux:
Once activated, your terminal should display the environment name, e.g., (venv)
.
Step 4: Install FastAPI, Uvicorn, etc.
FastAPI is a high-performance framework for building APIs. Uvicorn is the ASGI server used to run FastAPI apps.. To install them, run the following command in your terminal:
Wait for the installation to complete. FastAPI, Uvicorn, etc is now installed on your system and ready for use in your Health Universe projects.
Step 5: Edit App.py
Let's build a simple "Hello, World!" style API with input validation using Pydantic.
Open main.py
in your editor and add:
Save the main.py
file.
Step 6: Run the FastAPI App
To run your "Hello, World!" FastAPI app, open the terminal, navigate to your project directory, and run the following command:
Then open your browser and go to:
To stop the app, press
Ctrl+C
in the terminal.
Step 7: Run pip freeze
From your terminal, run:
This command will save all your project's dependencies into a requirements.txt file. This file is read by the Health Universe cloud to know what libraries your app will require.
Step 8: Commit Your Code and Push to GitHub
Step 9: Deploy Your App on Health Universe
Last updated
Was this helpful?