Health Universe
  • Core Concepts
    • Overview of Health Universe
    • How Health Universe Works
  • Building Apps in Health Universe
    • Getting started with Health Universe
      • Create a Health Universe Account
      • Create a Github Account
      • Link your Github Account to your Health Universe Account
    • Creating a Workspace
    • Developing your Health Universe App
      • Streamlit vs FastAPI
      • Working in Streamlit
        • Typical Project Setup
        • Your First Health Universe App
        • Streamlit Best Practices
      • Working in FastAPI
        • Typical Project Setup
        • Your First Health Universe App
        • Navigator FastAPI best practices
    • Deploying your app to Health Universe
      • Deploying to Health Universe
      • Secret Management
      • Connecting to an LLM
      • Connecting to an external data source
  • Testing your app
  • Re-deploying your app
  • Document your app
  • Deleting your App on Health Universe
  • Additional resources
    • Data Formats, Standards & Privacy
    • External Tools and Libraries
Powered by GitBook
On this page
  • Step 1: Create a GitHub Repository
  • Step 2: Clone Your Repository or Use Our Template
  • Step 3: Set Up a Virtual Environment
  • Step 4: Install FastAPI, Uvicorn, etc.
  • Step 5: Edit App.py
  • Step 6: Run the FastAPI App
  • Step 7: Run pip freeze
  • Step 8: Commit Your Code and Push to GitHub
  • Step 9: Deploy Your App on Health Universe

Was this helpful?

  1. Building Apps in Health Universe
  2. Developing your Health Universe App
  3. Working in FastAPI

Typical Project Setup

PreviousWorking in FastAPINextYour First Health Universe App

Last updated 20 days ago

Was this helpful?

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 or Use Our Template

  1. Clone Your Repository

    • git clone https://github.com/<your_account>/<your_repo_name>.git

  2. Use Our Template

    • Start with our , designed to work seamlessly with the Health Universe Navigator interface. It’s highly recommended, as it’s easy to customize and already optimized for deployment.

    • Click the green “Use this template” button (top right).

    • Select “Create a new repository”.

    • Give your new repository a name (e.g., tool-bmi-calculator).

    • Click “Create repository from template”.

    • Once it's created, clone your new repo to your local machine OR modify the script within Github.

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:

  1. Open a terminal and navigate to your desired project directory.

  2. Create a new virtual environment with the following command:

    python -m venv .env
  3. Activate the virtual environment:

    • Windows:

      .env\Scripts\activate
    • macOS and Linux:

      source .env/bin/activate

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:

pip install fastapi uvicorn pydantic python-multipart httpx

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:

from fastapi import FastAPI
from pydantic import BaseModel

# Input schema using Pydantic
class GreetRequest(BaseModel):
    name: str

# Create the app
app = FastAPI()

@app.get("/")
def read_root():
    return {"message": "Welcome to Health Universe!"}

@app.post("/greet")
def greet_user(request: GreetRequest):
    return {"message": f"Hello, {request.name}!"}

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:

uvicorn main:app --reload

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:

pip freeze > requirements.txt

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

to view the root endpoint.

to test your API using Swagger UI.

FastAPI Template
http://127.0.0.1:8000
http://127.0.0.1:8000/docs