> ## Documentation Index
> Fetch the complete documentation index at: https://kb.hosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Installing FastAPI on unmanaged servers

> Learn to install and run FastAPI on an unmanaged server using command line instructions. FastAPI is a Python framework for building APIs.

This article demonstrates how to install and run FastAPI on an unmanaged server. [FastAPI](https://fastapi.tiangolo.com/) is a Python-based web framework for building APIs (Application Programming Interfaces).

Because FastAPI is asynchronous, it requires the Asynchronous Server Gateway Interface ( [ASGI](https://en.wikipedia.org/wiki/Asynchronous_Server_Gateway_Interface) ) instead of the Web Server Gateway Interface ( [WSGI](https://en.wikipedia.org/wiki/Web_Server_Gateway_Interface) ). Because our managed hosting solutions use [Passenger](https://www.phusionpassenger.com/) and WSGI to manage Python applications, you can only install and run FastAPI on an unmanaged hosting account.

## Installing FastAPI

To install FastAPI, you first create a virtual environment for Python. After you activate the virtual environment, you can use the *pip* installer to install FastAPI.

To do this, follow these steps:

1. Log in to your server [using SSH](/docs/using-ssh-secure-shell).

2. If you are running Ubuntu on your server, as the root user, type the following command:

   ```bash theme={null}
   apt install curl python3.8-venv
   ```

   > 📘 Note
   >
   > If you are running another distribution that already has *curl* and Python 3 virtual environment support installed, you do not need to install any additional packages. If your distribution does not have these packages installed, consult its documentation on how to do so.

3. As a regular (non-root) user, type the following commands:

   ```bash theme={null}
   cd ~
   python3 -m venv fastapi-test
   cd fastapi-test
   source bin/activate
   ```

4. The virtual environment is now created and activated. To update *pip*, type the following command:

   ```bash theme={null}
   pip install --upgrade pip
   ```

5. To install FastAPI, type the following commands:

   ```bash theme={null}
   pip install fastapi
   pip install "uvicorn[standard]"
   ```

6. FastAPI is now installed. To determine which version is installed, type the following command:

   ```bash theme={null}
   pip show fastapi
   ```

## Running an example application

FastAPI is now installed, and you can create and configure FastAPI applications. The following example shows how to do this.

1. Use a text editor to create a file named *main.py*.

2. Copy and paste the following code into the *main.py* file:

   ```python theme={null}
   from typing import Union
   from fastapi import FastAPI

   app = FastAPI()

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

   @app.get("/items/{item_id}")
   def read_item(item_id: int, q: Union[str, None] = None):
       return {"item_id": item_id, "q": q}
   ```

3. To start the development web server, type the following command::

   ```bash theme={null}
   uvicorn main:app --reload
   ```

4. In another terminal window, type the following command:

   ```bash theme={null}
   curl localhost:8000/items/5?q=my_query
   ```

   You should see the following JSON response:

   ```
   {"item_id":5,"q":"my_query"}
   ```

   You now have a basic, functioning web API created using FastAPI.

## More information

For more information about FastAPI, please visit [https://fastapi.tiangolo.com](https://fastapi.tiangolo.com).

## Related articles

* [Do you support FastAPI?](/docs/do-you-support-fastapi)

* [Installing and configuring Flask on a Linux shared hosting account](/docs/installing-and-configuring-flask-on-linux-shared-hosting)

* [Installing and configuring Django on Linux shared hosting](/docs/installing-and-configuring-django-on-linux-shared-hosting)

* [Installing and configuring Django on unmanaged servers](/docs/installing-and-configuring-django-on-unmanaged-servers)
