Deploy Service Using Python SDK
In this guide, we’ll deploy a FastAPI service for solving the Iris classification problem. This problem involves predicting the species of an iris flower based on its sepal length, sepal width, petal length, and petal width. There are three species: Iris setosa, Iris versicolor, and Iris virginica.
Project Setup
We’ve already created a FastAPI service for the Iris classification problem, and you can find the code in our GitHub repository: GitHub Repository.
Clone the GitHub repository with the following command:
Navigate to the project directory:
Please review the service code to become familiar with the code you’ll deploy.
Project Structure
The project files are organized as follows:
All these files are located in the same directory.
Prerequisties
Before you proceed with the guide, make sure you have the following:
- Truefoundry CLI:
Set up and configure the TrueFoundry CLI tool on your local machine by following the Setup for CLI guide. - Workspace:
To deploy your service, you’ll need a workspace. If you don’t have one, you can create it using this guide: Creating a Workspace or seek assistance from your cluster administrator. Also, copy the Workspace FQN as this will be required later.
Deploying the Service
Create a deploy.py
file in the same directory as your Service code (app.py
). This file will contain the necessary configuration for your Service.
Your directory structure will then appear as follows:
File Structure
deploy.py
Picking a value for host
Providing a host value depends on the base domain urls configured in the cluster settings, you can learn how to find the base domain urls available to you here
For e.g. If your base domain url is *.truefoundry.your-org.com
then a valid value can be fastapi-your-workspace-8000.truefoundry.your-org.com
.
Alternatively if you have a non wildcard based domain url e.g. truefoundry.your-org.com
, then a valid value can be truefoundry.your-org.com/fastapi-your-workspace-8000
To understand the code, you can click the following recipe:
To deploy using Python SDK use:
Run the above command from the same directory containing the app.py
and requirements.txt
files.
Exclude files when building and deploying your source code:
To exclude specific files from being built and deployed, create a .tfyignore file in the directory containing your deployment script (deploy.py
). The .tfyignore
file follows the same rules as the .gitignore
file.
If your repository already has a .gitignore
file, you don’t need to create a .tfyignore
file. Service Foundry will automatically detect the files to ignore.
Place the .tfyignore
file in the project’s root directory, alongside deploy.py.
After running the command mentioned above, wait for the deployment process to complete. Monitor the status until it shows DEPLOY_SUCCESS:
, indicating a successful deployment.
Once deployed, you’ll receive a dashboard access link in the output, typically mentioned as You can find the application on the dashboard:
. Click this link to access the deployment dashboard.
View your deployed service
Your deployment will be successful in a few seconds, and your service will be displayed as active (green), indicating that it’s up and running.
Congratulations! You’ve successfully deployed your FastAPI service.
To learn how to use your service-specific dashboard and send requests to your service, check out this guide:
Interacting with your Service