Creating secrets
From a dictionary
Create a secret directly from a dictionary of key-value pairs:From local environment variables
Automatically pull values from your local environment:From a .env file
Load secrets from a.env file in your project:
.env. You can specify a different filename:
From the dashboard
Reference a named secret created on the Modal dashboard:Managing named secrets
Modal provides aSecret.objects manager for creating, listing, and deleting named secrets programmatically.
Create a named secret
allow_existing=True to make this a no-op:
Secret.objects.create() does not return a local instance. Use Secret.from_name() to perform a lookup after creation.List secrets
Retrieve all named secrets in the current environment:Delete a secret
allow_missing=True to avoid errors if the secret doesn’t exist:
Working with secret instances
Get secret information
Update a secret
Update or add key-value pairs to an existing secret:Like
dict.update(), this merges the new values into the existing secret. Keys not mentioned are left unchanged.API reference
Secret.from_dict()
Dictionary of entries to insert as environment variables. Values can be
None, which are ignored.Secret.from_local_environ()
List of local environment variables to include for remote execution.
Secret.from_dotenv()
Starting point for finding the
.env file. If not provided, uses the current working directory.Name of the environment file to load.
Secret.from_name()
Name of the secret to reference.
Environment containing the secret. Uses the active environment if not specified.
List of required environment variables that will be validated server-side.
Secret.objects.create()
Name to use for the new secret.
Key-value pairs to set in the secret.
If
True, no-op when the secret already exists.Environment to create the secret in. Uses the active environment if not specified.
Secret.objects.list()
Limit the number of results returned.
Only return secrets created before this date.
Environment to list secrets from. Uses the active environment if not specified.
Secret.objects.delete()
Name of the secret to delete.
If
True, don’t raise an error if the secret doesn’t exist.Environment containing the secret. Uses the active environment if not specified.