API Docs
Secrets Management

Secrets Management

Introduction

Sometimes you need to use credentials or api keys in your notebook. Best way to store them locally is creating .env file. But when you want to upload your notebook - using Secrets Management offered by Mercury Cloud is a good practice.

If you don't have your site yet, check this article and create it.

1. Creating Notebook

This is example notebook:

Example code

code to copy:

import os 
from dotenv import load_dotenv
import mercury as mr 
_ = load_dotenv()
name = os.environ.get("DB_USERNAME")
password = os.environ.get("DB_PASSWORD")
if name is not None and password is not None:
    print("credentials loaded successfully)
esle:
    print("credentials didn't loaded successfully)

2. Add secrets

First of all, you have to upload your notebook. Then you have to click Secrets which is placed on the headline.

Open Secrets widget

After that choose site where you uploaded your notebook and click + Add Secret button.

Add secrets

Type your secret's name in first window and the value of it in the second. When everything is ready click OK button to confirm.

Confirm your secret

Following this pattern you can add as many secrets as you need.

Secrets' list

3. Access secrets in the notebook

Secret variable are available in os.environ.

Code with variables

With secrets

Access secrets in notebook

4. Example use

Secrets are useful in many situations:

  • when you creating function to connect with database
Using secrets to connect with database.
  • installing packages from private repositories using requirements.txt

You can get more information about it in Install your packages doc.