Skip to main content

Import a Secret

Learn how to import a secret

Secrets allow users to store text blobs typically containing credentials and API keys for secure access in their code. To add a secret as a Pangea Vault Item, you must identify the secret information you want store and then import it as a Secret type Vault Item in Pangea Vault.


import os

import pangea.exceptions as pe
from pangea.config import PangeaConfig
from pangea.services import Vault

def import_secret(secret_name, secret_material):
token = os.getenv("PANGEA_VAULT_TOKEN")
domain = os.getenv("PANGEA_DOMAIN")
config = PangeaConfig(domain=domain)
vault = Vault(token, config=config)
secret_id = None

try:
# store a secret
create_response = vault.secret_store(name=secret_name, secret=secret_material)
secret_id = create_response.result.id

except pe.PangeaAPIException as e:
print(f"Vault Request Error: {e.response.summary}")
for err in e.errors:
print(f"\t{err.detail} \n")

return secret_id

Was this article helpful?

Contact us