Environment Variables
An environment variable is a value that affects the way the code runs and is dependent on the environment on which it is running.
For example, you have written a ML model API service that,
- Downloads the model from somewhere.
- Loads the model from disk.
- Serves a
/infer
route, which calls the model’s inference function.
Now, your service code may not change if you re-train and update the model. In this case, we can pass the model path via an environment variable.
main.py
You can then run this service and inject the environment variable value like below,
You can also use a .env
file on your local dev environment and use python-dotenv.
.env
How to inject environment variables in Truefoundry
In this guide we will learn how can we inject environment variables in our deployments in Truefoundry.
The variables MODEL_FQN
and S3_BUCKET_NAME
should be available in your environment on deployment.