Skip to main content

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. The following sections assume you store your secrets in the Seaplane secrets store, which you can learn more about in the section below.

General Authentication

Seaplane automatically checks for an environment variable with the name SEAPLANE_API_KEY to authenticate with the Seaplane SDK. For basic use cases adding SEAPLANE_API_KEY=<YOUR-API-KEY> to your project's .env is all you have to do to authenticate.

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.

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": os.getenv('SEAPLANE_KEY'),
"OPENAI_API_KEY": os.getenv('OPEN_AI_KEY')
}

config.set_api_keys(api_keys)

Seaplane currently supports the following external services.

  • OpenAI indicated by OPENAI_API_KEY in the API keys object.
  • More coming soon!

SQL Authentication

Seaplane handles the authentication with most built-in data sources automatically with one exception: SQL. To connect with SQL create a sql_access object inside the task where you want to use Seaplane Managed Global SQL. Add the sql_access object to your task decorator and pass the sql object as a parameter to the function definition as indicated below. You can learn more about SQL and SQL authentication here.

from seaplane import task
import os

# create a SQL access object
sql_access = {
"username": os.getenv('DB_USERNAME'),
"password": os.getenv('DB_PASSWORD'),
"database": os.getenv('DB_NAME')
}

@task(id='my-sql-task', sql=sql_access)
def my_sql_task(data, sql):
# run SQL queries
sql.execute("INSERT INTO my_table ....")

Seaplane Secrets

Seaplane automatically creates environment variables and stores them inside our secrets store for each secret defined inside your projects .env file.

For example, assume you have the following .env file.

.env
DB_USERNAME=<YOUR-DB-USERNAME>
DB_PASSWORD=<YOUR-DB-PASSWORD>
DB_NAME=<YOUR-DB-NAME>

During deployment, Seaplane automatically creates the required secrets as environment variables. You can load them inside a sql_access object as follows using os.getenv()

task.py
from seaplane import task
import os

# create a SQL access object
sql_access = {
"username": os.getenv('DB_USERNAME'),
"password": os.getenv('DB_PASSWORD'),
"database": os.getenv('DB_NAME')
}

@task(id='my-sql-task', sql=sql_access)
def my_sql_task(data, sql):
# run SQL queries
sql.execute("INSERT INTO my_table ....")