# Introduction
FastAPI has grown far past being only a easy Python library for serving APIs. It has grow to be a broader ecosystem that many builders depend on to construct fashionable internet purposes, particularly for AI and machine studying initiatives. One of many causes FastAPI turned so in style is its pace, simplicity, and developer-friendly design.
Picture from FastAPI Cloud
Now, with FastAPI Cloud, the deployment expertise is turning into a lot simpler too. As a substitute of spending time configuring servers and deployment pipelines, you possibly can deploy an utility in seconds utilizing the FastAPI Cloud command-line interface (CLI). The setup feels simple, light-weight, and far nearer to the graceful expertise builders anticipate from fashionable managed platforms.
On the time of writing, entry continues to be rolling out by way of a waitlist. I utilized a few months in the past and not too long ago bought entry, so I wished to place collectively a easy information based mostly on my expertise. On this tutorial, I’ll stroll by way of the fundamental setup course of and present find out how to deploy a small FastAPI app in only a few steps.
# Creating the Mission
On this tutorial, you’ll construct a easy stay metals dashboard utilizing FastAPI. The app will fetch gold and silver costs from an API, return the info in JSON format, and show the values within the browser utilizing a small HTML interface.
Earlier than you start, be sure to have:
- uv put in for challenge scaffolding, or a latest supported Python model.
- A FastAPI Cloud account.
To get began, create a brand new FastAPI challenge with the official setup command:
uvx fastapi-new metals-live
cd metals-live
Inside just a few seconds, FastAPI will generate the challenge construction and set up the required dependencies for you.
Picture by Creator
Subsequent, activate the digital atmosphere contained in the challenge listing.
On Linux/macOS:
supply .venv/bin/activate
On Home windows PowerShell:
.venvScriptsActivate.ps1
# Including httpx
Subsequent, set up the packages the app will want. We are going to use httpx to fetch stay gold and silver costs from the API, and we can even ensure the usual FastAPI extras are put in so the app runs and deploys easily with out lacking dependencies.
uv add httpx “fastapi[standard]”
This command provides httpx for making outbound API requests and installs the usual FastAPI dependencies generally wanted for improvement and deployment.
# Changing the Default App
Now it’s time to substitute the default FastAPI app with the model you’ll really deploy.
That is what the default challenge construction seems to be like:
Picture by Creator
Open principal.py and substitute its contents with the customized code proven under. This model does two issues: it fetches stay gold and silver costs from the Gold API, and it serves a easy browser dashboard that refreshes robotically each 15 seconds.
Paste this into principal.py:
import httpx
from fastapi import FastAPI, HTTPException
from fastapi.responses import HTMLResponse
app = FastAPI(title=”Dwell Gold & Silver Costs”)
GOLD_API_BASE = “https://api.gold-api.com”
async def fetch_price(image: str):
url = f”{GOLD_API_BASE}/worth/{image}”
async with httpx.AsyncClient(timeout=10.0) as consumer:
response = await consumer.get(url)
if response.status_code != 200:
increase HTTPException(status_code=502, element=f”Didn’t fetch {image} worth”)
knowledge = response.json()
return {
“image”: knowledge.get(“image”, image),
“title”: knowledge.get(“title”, image),
“worth”: knowledge.get(“worth”),
“forex”: knowledge.get(“forex”, “USD”),
“updatedAt”: knowledge.get(“updatedAt”) or knowledge.get(“timestamp”),
}
@app.get(“/api/costs”)
async def get_prices():
gold = await fetch_price(“XAU”)
silver = await fetch_price(“XAG”)
return {
“gold”: gold,
“silver”: silver,
}
@app.get(“https://www.kdnuggets.com/”, response_class=HTMLResponse)
async def residence():
return “””
Dwell Gold & Silver Costs
Costs refresh robotically each 15 seconds.
“””
What this code does:
- Creates a FastAPI app.
- Fetches stay gold and silver costs from the API.
- Returns the info by way of /api/costs.
- Serves a easy HTML dashboard at /.
- Refreshes the displayed costs each 15 seconds.
# Testing Domestically
Earlier than deploying, it’s a good suggestion to run the app regionally and ensure all the things works as anticipated. FastAPI makes this simple with its built-in improvement server.
Begin the app with:
As soon as the server begins, FastAPI will generate a neighborhood URL in your app and a docs URL for testing the endpoints.
Picture by Creator
Open your browser and go to:
You need to see your stay dashboard exhibiting gold and silver costs. The values will refresh robotically each 15 seconds.
Picture by Creator
You may as well check the JSON endpoint instantly at:
http://127.0.0.1:8000/api/costs
That is particularly helpful if you wish to examine the uncooked response or later join the info to a different frontend or utility.
Picture by Creator
# Deploying to FastAPI Cloud
As soon as the app works regionally, you’re able to deploy it to FastAPI Cloud. The deployment circulate could be very easy and begins with a single command.
Run:
The CLI will information you thru connecting your FastAPI Cloud account and finishing the setup. Throughout onboarding, you might be requested just a few brief questions, corresponding to your workforce title, app title, and deployment settings.
Picture by Creator
As soon as that’s carried out, FastAPI Cloud will construct and deploy your app for you.
Picture by Creator
After the deployment finishes, you’ll get a stay public URL in your app — for instance:
Picture by Creator
https://metals-live.fastapicloud.dev/
FastAPI Cloud additionally provides you interactive API docs at:
https://metals-live.fastapicloud.dev/docs
Picture by Creator
That is helpful as a result of you possibly can check your API instantly from the browser, without having any further instruments.
Picture by Creator
# Monitoring the App
After deployment, you should use the FastAPI Cloud dashboard to watch your app and examine its logs.
To view the logs:
- Open the FastAPI Cloud dashboard.
- Go to Apps.
- Choose your app.
- Open Logs.
That is helpful for checking whether or not your app is working appropriately, recognizing API errors, and debugging points after deployment.
Picture by Creator
FastAPI Cloud additionally begins to really feel nearer to platforms like Supabase or Vercel, with managed internet hosting, fast CLI-based deployment, and additional integrations you possibly can connect with your app as you develop it.
Picture by Creator
# Wrapping Up
FastAPI Cloud makes it simple to take a small FastAPI app from native improvement to a stay deployment. On this information, we constructed a easy stay metals dashboard, examined it regionally, deployed it with one command, and checked logs after launch.
For a primary deployment, the workflow is easy and an excellent introduction to the FastAPI Cloud expertise.
Abid Ali Awan (@1abidaliawan) is an authorized knowledge scientist skilled who loves constructing machine studying fashions. Presently, he’s specializing in content material creation and writing technical blogs on machine studying and knowledge science applied sciences. Abid holds a Grasp’s diploma in expertise administration and a bachelor’s diploma in telecommunication engineering. His imaginative and prescient is to construct an AI product utilizing a graph neural community for college students battling psychological sickness.

