modal.Secret

Secrets provide a dictionary of environment variables for images.

Secrets are a secure way to add credentials and other sensitive information to the containers your functions run in. You can create and edit secrets on the dashboard, or programmatically from Python code.

See the secrets guide page for more information.

hydrate 

Synchronize the local object with its identity on the Modal server.

It is rarely necessary to call this method explicitly, as most operations will lazily hydrate when needed. The main use case is when you need to access object metadata, such as its ID.

Added in v0.72.39: This method replaces the deprecated .resolve() method.

objects 

Namespace with methods for managing named Secret objects.

create 

Create a new Secret object.

Examples:

Secrets will be created in the active environment, or another one can be specified:

By default, an error will be raised if the Secret already exists, but passing allow_existing=True will make the creation attempt a no-op in this case. If the env_dict data differs from the existing Secret, it will be ignored.

Note that this method does not return a local instance of the Secret. You can use modal.Secret.from_name to perform a lookup after creation.

Added in v1.1.2.

list 

Return a list of hydrated Secret objects.

Examples:

Secrets will be retreived from the active environment, or another one can be specified:

By default, all named Secrets are returned, newest to oldest. It’s also possible to limit the number of results and to filter by creation date:

Added in v1.1.2.

delete 

Delete a named Secret.

Warning: Deletion is irreversible and will affect any Apps currently using the Secret.

Examples:

Secrets will be deleted from the active environment, or another one can be specified:

Added in v1.1.2.

name 

from_dict 

Create a secret from a str-str dictionary. Values can also be None, which is ignored.

Usage:

from_local_environ 

Create secrets from local environment variables automatically.

from_dotenv 

Create secrets from a .env file automatically.

If no argument is provided, it will use the current working directory as the starting point for finding a .env file. Note that it does not use the location of the module calling Secret.from_dotenv.

If called with an argument, it will use that as a starting point for finding .env files. In particular, you can call it like this:

This will use the location of the script calling modal.Secret.from_dotenv as a starting point for finding the .env file.

A file named .env is expected by default, but this can be overridden with the filename keyword argument:

from_name 

Reference a Secret by its name.

In contrast to most other Modal objects, named Secrets must be provisioned from the Dashboard. See other methods for alternate ways of creating a new Secret from code.

info 

Return information about the Secret object.