Store project credentials in .env files

Published

March 6, 2024

Learn how to store project identifier credentials in a .env file instead of using inline credentials. This topic is relevant for model developers who want to follow best practices for security when running notebooks.

Prerequisites

Steps

  1. Create a new file in the same folder as your notebook and name it .env. This is a hidden file, so you may need to change your settings to view it.

  2. Locate the code snippet for your model. These credentials can be found on the Getting started page for models registered in the model inventory. Copy the values from this page and paste them into your .env file in the following format:

    VM_API_PROJECT=<Project Identifier>
    VM_API_HOST=<API Host URL>
    VM_API_KEY=<API Key>
    VM_API_SECRET=<API Secret>
  3. Insert this code snippet above your project identifier credentials:

    %load_ext dotenv
    %dotenv dev.env

The updated notebook should look like this:

%load_ext dotenv
%dotenv .env

import validmind as vm

vm.init(
  api_host = "http://localhost:3000/api/v1/tracking",
  project = "..."
)
  1. Run the cell. Instead of using inline credentials, this cell will now load your project credentials from a .env file.

What’s next