Skip to main content
Version: 0.4.0

Authentication

This document describes how to authenticate with the Seaplane SDK and the built-in components such as data stores or models. In general, we recommend you store authentication secrets inside the seaplane secrets store. This allows your apps to read them from environment variables and avoids unnecessary security risks of hard-coding secrets inside your project.

General Authentication​

Seaplane automatically creates environment variables and stores them inside the Seaplane secrets store for each secret defined inside your projects .env file. For example, assume you have the following .env file.

.env
SEAPLANE_API_KEY=<YOUR-SEAPLANE-KEY>
OPEN_AI_API_KEY=<API-KEY-1>
MY_EXTERNAL_SERVICE=<API-KEY-2>

Seaplane automatically checks for an environment variable with the name SEAPLANE_API_KEY to authenticate with the Seaplane SDK.

During deployment, Seaplane creates the additional secrets as environment variables. You can load them inside your application as follows using os.getenv()

task.py
from seaplane import task
import os

@task(id='my-task')
def my_sql_task(context):

# load API keys from environment variables
open_ai_key = os.getenv('OPEN_AI_API_KEY')
external_key = os.getenv('MY_EXTERNAL_SERVICE')

Setting API Keys Manually​

Alternatively, you can set the API key manually. Import config from the Seaplane package and call the set_api_key method inside your main.py file as follows.

warning

For security reasons, setting API keys manually should be avoided. We always recommend using the .env file when possible.

from seaplane import config
import os

config.set_api_key("<YOUR-SEAPLANE-KEY>")

You can set multiple keys all at once by calling the config.set_api_keys() method with an API key object. By doing so you can set the Seaplane API key and any external service API keys at the same time.

from seaplane import config

api_keys = {
"SEAPLANE_API_KEY": "<SEAPLANE-KEY>",
"OPENAI_API_KEY": "<OPEN-AI-KEY>"
}

config.set_api_keys(api_keys)