Build faster with this simple AZD template for FastAPI on Azure App Service

Whether you’re building your first web app or your fiftieth, you want it to be simple to deploy so you can spend your time on building your new idea and not on configuration options to get your service running in the cloud. And when you’re just getting started you don’t need huge scale, you probably want to deploy it on a free plan! I’ve made this Simple FastAPI AZD template for Azure App Service to help you get to the fun part, and to cut out all the extra infrastructure that you don’t necessarily want or need. This FastAPI template for Azure App Service gives you all the infrastructure as code to deploy a basic “Hello World” FastAPI web app that you can spin up using AZD (Azure Developer SDK) with just three commands. How to do it To get started, you just need to install AZD, a command-line tool you can use right there in VS Code. Then you’re ready to grab the template and deploy. Run these commands and follow the prompts as you go.  Grab our new simple FastAPI template for Azure App Service: azd init --template Azure-Samples/azd-simple-fastapi-appservice It will ask you to give your environment a name. This will be used to name different resources that are deployed on Azure. Log in to your Azure account: azd auth login Now for the magic! Well, not magic… in one command we can package up your code, provision the Azure resources, and deploy your web app: azd up You’ll get to choose the location where your web app deploys and the subscription you want to put it on. If you loved how easy that was, you can check out more about AZD, how you can use it, and find more AZD learning resources on the Azure Developer SDK home page. Why choose FastAPI on Azure App Service FastAPI vs Other Python Frameworks FastAPI is a great choice if you need to build APIs quickly and efficiently. It’s designed to be fast, easy to use, and powerful. Here’s why you might choose FastAPI over other Python frameworks like Flask or Django: Speed and Native Asynchronous Support FastAPI is built for high performance as it is built on Starlette (a lightweight ASGI framework), ideal for high-concurrency apps with many simultaneous users or pushing live updates, WebSocket connections, or where background data collection and processing are frequent. Leveraging Python’s async and await keywords allows FastAPI to serve up your web app much faster than frameworks like Flask when handling many requests at once. Pydantic for Type Hints, Data Validation, and Clear Error Messages FastAPI uses Pydantic to enforce type hints and automatically validate request data. If the input is invalid, FastAPI returns clear, structured error messages without extra code. This makes APIs more reliable, user-friendly, and easier to debug. The automated error detection based on the Pydantic models you have specified also cuts down on test writing time as well as generating interactive API documentation automatically. Clean and Extendable Code with Dependency Injection FastAPI uses dependency injection to promote clean, maintainable, and modular code. Dependency injection is a design pattern where components (like functions or classes) are provided with their dependencies (e.g., database connections, external services) rather than creating them inside the function itself. This results in code that is easier to test, extend, and maintain – particularly when you consider the benefits of inheriting dependencies and the reduction of duplication of code this provides. Overall, if you’re looking for a framework that makes API development faster and smoother, FastAPI is a great choice! Why Azure App Service? There are a lot of deployment strategies out there, but when you’re just getting started you don’t need a lot of the complex features and configurations. To keep it as simple as possible, I’ve built this template to use Azure App Service – which can take you a long way on your web app journey as your idea and scale grows. Here’s a couple of points as to why using Azure App Service is a good way to get started with a new project, whether it’s a project you’re using for learning, a prototype, or for your global role out. Get started for free As the template comes, it is set to a basic plan (you can see the pricing per month here), but if you want to get started for free, you can easily update the template before you run azd up to leverage the free plan or the discounted developer plan! To change the plan go to the template file infra/resources.bicep and update line 58 where the SKU is set to “B1” (“Stock-Keeping Units” is how we refer to the different plans that offer different amounts of RAM and storage). Change this to “F1” to deploy up to 10 App Service apps for free on the free plan (or “D1”  for the discounted developer rate if you have more than 10 to deploy concurrently).   Scale far and wide When you’re just getting started, you’ll already get the benefit of Azure’s global reach by selecting from one of t

May 2, 2025 - 09:29
 0
Build faster with this simple AZD template for FastAPI on Azure App Service

Whether you’re building your first web app or your fiftieth, you want it to be simple to deploy so you can spend your time on building your new idea and not on configuration options to get your service running in the cloud. And when you’re just getting started you don’t need huge scale, you probably want to deploy it on a free plan!

I’ve made this Simple FastAPI AZD template for Azure App Service to help you get to the fun part, and to cut out all the extra infrastructure that you don’t necessarily want or need. This FastAPI template for Azure App Service gives you all the infrastructure as code to deploy a basic “Hello World” FastAPI web app that you can spin up using AZD (Azure Developer SDK) with just three commands.

How to do it

To get started, you just need to install AZD, a command-line tool you can use right there in VS Code. Then you’re ready to grab the template and deploy. Run these commands and follow the prompts as you go. 

  1. Grab our new simple FastAPI template for Azure App Service:
    azd init --template Azure-Samples/azd-simple-fastapi-appservice
    It will ask you to give your environment a name. This will be used to name different resources that are deployed on Azure.

  2. Log in to your Azure account:
    azd auth login

  3. Now for the magic! Well, not magic… in one command we can package up your code, provision the Azure resources, and deploy your web app:
    azd up
    You’ll get to choose the location where your web app deploys and the subscription you want to put it on.

If you loved how easy that was, you can check out more about AZD, how you can use it, and find more AZD learning resources on the Azure Developer SDK home page.

Why choose FastAPI on Azure App Service

FastAPI vs Other Python Frameworks

FastAPI is a great choice if you need to build APIs quickly and efficiently. It’s designed to be fast, easy to use, and powerful. Here’s why you might choose FastAPI over other Python frameworks like Flask or Django:

Speed and Native Asynchronous Support
FastAPI is built for high performance as it is built on Starlette (a lightweight ASGI framework), ideal for high-concurrency apps with many simultaneous users or pushing live updates, WebSocket connections, or where background data collection and processing are frequent.

Leveraging Python’s async and await keywords allows FastAPI to serve up your web app much faster than frameworks like Flask when handling many requests at once.

Pydantic for Type Hints, Data Validation, and Clear Error Messages

FastAPI uses Pydantic to enforce type hints and automatically validate request data. If the input is invalid, FastAPI returns clear, structured error messages without extra code. This makes APIs more reliable, user-friendly, and easier to debug. The automated error detection based on the Pydantic models you have specified also cuts down on test writing time as well as generating interactive API documentation automatically.

Clean and Extendable Code with Dependency Injection

FastAPI uses dependency injection to promote clean, maintainable, and modular code. Dependency injection is a design pattern where components (like functions or classes) are provided with their dependencies (e.g., database connections, external services) rather than creating them inside the function itself. This results in code that is easier to test, extend, and maintain – particularly when you consider the benefits of inheriting dependencies and the reduction of duplication of code this provides.

Overall, if you’re looking for a framework that makes API development faster and smoother, FastAPI is a great choice!

Why Azure App Service?

There are a lot of deployment strategies out there, but when you’re just getting started you don’t need a lot of the complex features and configurations. To keep it as simple as possible, I’ve built this template to use Azure App Service – which can take you a long way on your web app journey as your idea and scale grows.

Here’s a couple of points as to why using Azure App Service is a good way to get started with a new project, whether it’s a project you’re using for learning, a prototype, or for your global role out.

Get started for free
As the template comes, it is set to a basic plan (you can see the pricing per month here), but if you want to get started for free, you can easily update the template before you run azd up to leverage the free plan or the discounted developer plan!

To change the plan go to the template file infra/resources.bicep and update line 58 where the SKU is set to “B1” (“Stock-Keeping Units” is how we refer to the different plans that offer different amounts of RAM and storage). Change this to “F1” to deploy up to 10 App Service apps for free on the free plan (or “D1”  for the discounted developer rate if you have more than 10 to deploy concurrently).  

Scale far and wide
When you’re just getting started, you’ll already get the benefit of Azure’s global reach by selecting from one of the many server locations close to you, helping reduce lag for users in your region. Then, as your web app “grows up”, you’ll have a lot of options for how to scale to reach a growing and spreading user base.

Once you have a couple of people trying to use your site at the same time it’s probably time to move on up to a Basic plan (if you have changed the template to use the “F1” or “D1” plans), to give you a bit more RAM to serve your users quickly. Just change your SKU back to “B1” or look at the different plan options if you think you might need something a bit beefier! Even just upgrading to the Basic plan will start to get you access to automatic scaling features to help you scale globally by increasing the number of VM instances that run your app.

Easy to manage and deploy
If you are getting started with cloud, Azure App Service is a great place to start (and continue!). App Service allows you to manage your cloud-hosted web apps with less of a learning curve than you might experience with a container-based option and has clean-cut ways to be able to interact with your logs.

And, we’ve already discussed how easy it is to get this project up and running on the cloud with AZD, but Azure App Service also has built-in GitHub integrations and works with CI/CD pipelines that you can configure in GitHub to customise your deployment flow as you continue to build out your solution.

Summary

To wrap things up, I hope using my Simple FastAPI + Azure App Service template sounds good to you! You can easily use it for free, so why not see how much simpler it can make deploying a Python-backed web app to the cloud?

I hope you enjoy building on it and have a great time with all the benefits of the speedy and modular FastAPI framework, along with the simplicity, scalability, and integration options that Azure App Service provides