---
sidebar:
  hidden: true
title: roboto.domain.secrets.secret
---
## Module Contents

### ParsedSecretName

```python
class roboto.domain.secrets.secret.ParsedSecretName
```

`from roboto.domain.secrets.secret import ParsedSecretName`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/secrets/secret.py#L31-L41)

Secret name and organization ID read from a secret URI.

`parse_secret_uri` returns it.

**Attributes**

- **ParsedSecretName.name** (`str`): Name of the secret.
- **ParsedSecretName.org_id** (`str | None`): ID of the organization that owns the secret, or `None` if the URI names none.

### SECRET_URI_REGEX

```python
roboto.domain.secrets.secret.SECRET_URI_REGEX
```

`from roboto.domain.secrets.secret import SECRET_URI_REGEX`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/secrets/secret.py#L26-L26)

Regular expression a secret URI must match: `roboto-secret://<name>`, optionally followed by `@<org_id>`.

### Secret

```python
class roboto.domain.secrets.secret.Secret(
    record: roboto.domain.secrets.record.SecretRecord,
    roboto_client: roboto.http.RobotoClient,
)
```

`from roboto.domain.secrets import Secret`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/secrets/secret.py#L75-L417)

A secret: sensitive information, such as an API key or password, that actions can use while they run.

A secret belongs to one organization and has a name unique within it. Its value is kept in a secret store and never passes through Roboto's APIs: `read_value` and `update_value` fetch short-lived credentials scoped to the secret and reach the store with them directly. An action parameter whose value is the secret's `uri` receives the secret's value when the action runs.

Get a `Secret` from `create`, `from_name`, `from_uri`, or `for_org`. To wrap a [`SecretRecord`](/docs/reference/python-sdk/roboto/domain/secrets/record#roboto.domain.secrets.record.SecretRecord) already fetched from Roboto, build a `Secret` from it directly.

**Parameters**

- **record** (`roboto.domain.secrets.record.SecretRecord`): Record of the secret.
- **roboto_client** (`roboto.http.RobotoClient`): Client to make requests to Roboto with.

**Properties**

- **Secret.name** (`str`): Name of the secret, unique within its organization.

- **Secret.org_id** (`str`): ID of the organization that owns the secret.

- **Secret.record** (`roboto.domain.secrets.record.SecretRecord`): Record of the secret that this instance holds.

  `refresh` replaces it with the current one.

- **Secret.store_type** (`roboto.domain.secrets.record.SecretStoreType`): Type of secret store that holds the secret's value.

- **Secret.uri** (`str`): URI that names the secret, as `roboto-secret://<name>@<org_id>`.

  Set it as an action parameter's value to pass the secret's value to the action, or load the secret from it with `from_uri`.

#### Secret.create()

```python
@classmethod
def create(
    name: str,
    caller_org_id: Optional[str] = None,
    initial_value: Optional[str] = None,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
) -> Secret
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/secrets/secret.py#L92-L142)

Create a secret, optionally with a value.

**Parameters**

- **name** (`str`): Name of the secret, unique within the organization it is created in.
- **caller_org_id** (`Optional[str]`): Organization to create the secret in. Required when the caller belongs to more than one organization; otherwise the caller's only organization.
- **initial_value** (`Optional[str]`): Value to store in the secret. It is set by `update_value` after the secret is created. `None` leaves the placeholder value `"INITIAL_VALUE_NOT_SET_BY_USER"` until a value is set.
- **roboto_client** (`Optional[roboto.http.RobotoClient]`): Client to make requests to Roboto with. Defaults to one configured from the environment, by [`from_env()`](/docs/reference/python-sdk/roboto/http/roboto_client#roboto.http.roboto_client.RobotoClient.from_env).

**Returns**

- `Secret`: The new secret.

**Raises**

- [`RobotoConflictException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoConflictException): The organization already has a secret with this name.

**Usage**

Create a secret without a value:

```python
secret = Secret.create(name="api_key", caller_org_id="og_12345")
print(secret.name)
# api_key
```

Create a secret with a value:

```python
secret = Secret.create(
    name="database_password", caller_org_id="og_12345", initial_value="super_secure_password"
)
```

#### Secret.delete()

```python
def delete() -> None
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/secrets/secret.py#L318-L333)

Delete the secret and its value.

Roboto removes the value from the secret store with no recovery window, so it cannot be restored.

**Raises**

- [`RobotoNotFoundException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoNotFoundException): The secret no longer exists.

**Returns**

- `None`

**Usage**

```python
secret = Secret.from_name("old_api_key")
secret.delete()
```

#### Secret.for_org()

```python
@classmethod
def for_org(
    org_id: str,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
) -> collections.abc.Generator[Secret, None, None]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/secrets/secret.py#L145-L187)

List the secrets in an organization.

Fetches the secrets a page at a time as the generator is consumed.

**Parameters**

- **org_id** (`str`): ID of the organization whose secrets to list.
- **roboto_client** (`Optional[roboto.http.RobotoClient]`): Client to make requests to Roboto with. Defaults to one configured from the environment, by [`from_env()`](/docs/reference/python-sdk/roboto/http/roboto_client#roboto.http.roboto_client.RobotoClient.from_env).

**Yields**

- Each secret the organization owns.

**Returns**

- `collections.abc.Generator[Secret, None, None]`

**Usage**

Print the name of every secret in an organization:

```python
for secret in Secret.for_org(org_id="og_12345"):
    print(secret.name)
```

#### Secret.from_name()

```python
@classmethod
def from_name(
    name: str,
    org_id: Optional[str] = None,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
) -> Secret
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/secrets/secret.py#L190-L227)

Fetch a secret by name.

Secret names are unique within an organization, so a name and an organization identify one secret.

**Parameters**

- **name** (`str`): Name of the secret.
- **org_id** (`Optional[str]`): Organization that owns the secret. Defaults to the organization the caller acts in.
- **roboto_client** (`Optional[roboto.http.RobotoClient]`): Client to make requests to Roboto with. Defaults to one configured from the environment, by [`from_env()`](/docs/reference/python-sdk/roboto/http/roboto_client#roboto.http.roboto_client.RobotoClient.from_env).

**Raises**

- [`RobotoNotFoundException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoNotFoundException): The organization has no secret with this name, or the caller cannot see it.

**Returns**

- `Secret`

**Usage**

Fetch a secret from the organization the caller acts in:

```python
secret = Secret.from_name(name="api_key")
```

Fetch a secret from a specific organization:

```python
secret = Secret.from_name(name="database_password", org_id="og_12345")
print(f"{secret.name} in {secret.org_id}")
# database_password in og_12345
```

#### Secret.from_uri()

```python
@classmethod
def from_uri(
    uri: str,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
    fallback_org_id: Optional[str] = None,
) -> Secret
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/secrets/secret.py#L230-L272)

Fetch the secret a secret URI names.

Reads the name and organization from `uri` and fetches the secret with `from_name`, whose failures also apply.

**Parameters**

- **uri** (`str`): Secret URI, as `roboto-secret://<name>` or `roboto-secret://<name>@<org_id>`.
- **roboto_client** (`Optional[roboto.http.RobotoClient]`): Client to make requests to Roboto with. Defaults to one configured from the environment, by [`from_env()`](/docs/reference/python-sdk/roboto/http/roboto_client#roboto.http.roboto_client.RobotoClient.from_env).
- **fallback_org_id** (`Optional[str]`): Organization that owns the secret when `uri` names none. `None` uses the organization the caller acts in.

**Raises**

- `ValueError`: `uri` does not begin with a secret URI.

**Returns**

- `Secret`

**Usage**

Fetch a secret from a URI that names its organization:

```python
secret = Secret.from_uri("roboto-secret://api_key@og_12345")
print(f"{secret.name} in {secret.org_id}")
# api_key in og_12345
```

Fetch a secret from a URI that names no organization:

```python
secret = Secret.from_uri("roboto-secret://api_key", fallback_org_id="og_12345")
print(f"{secret.name} in {secret.org_id}")
# api_key in og_12345
```

#### Secret.read_value()

```python
def read_value() -> pydantic.SecretStr
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/secrets/secret.py#L335-L354)

Fetch the secret's value from its secret store.

Roboto returns short-lived credentials that can read this one secret, and the SDK reads the value from the secret store with them, so the value never passes through Roboto.

**Returns**

- `pydantic.SecretStr`: The value, as a `pydantic.SecretStr`, which shows `**********` when printed or logged. `get_secret_value()` returns the value itself.

**Raises**

- [`RobotoNotFoundException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoNotFoundException): The secret no longer exists.

**Usage**

```python
secret = Secret.from_name("api_key")
api_key = secret.read_value().get_secret_value()
```

#### Secret.refresh()

```python
def refresh() -> Secret
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/secrets/secret.py#L356-L373)

Fetch the secret's current record from Roboto.

**Returns**

- `Secret`: This instance, with its record updated from Roboto's response.

**Raises**

- [`RobotoNotFoundException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoNotFoundException): The secret no longer exists.

**Usage**

```python
secret = Secret.from_name("api_key")
secret.refresh()
```

#### Secret.update_value()

```python
def update_value(new_value: str) -> Secret
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/secrets/secret.py#L375-L399)

Replace the secret's value in its secret store.

Roboto returns short-lived credentials scoped to this one secret, and the SDK writes the value to the secret store with them, so the value never passes through Roboto.

**Parameters**

- **new_value** (`str`): Value to store in the secret.

**Returns**

- `Secret`: This instance. Its record is unchanged until you fetch it again.

**Raises**

- [`RobotoNotFoundException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoNotFoundException): The secret no longer exists.
- `botocore.exceptions.ClientError`: The caller cannot update the secret, so the credentials Roboto returns can only read its value.

**Usage**

```python
secret = Secret.from_name("api_key")
secret.update_value("new_secret_api_key_value")
```

### is_secret_uri()

```python
def roboto.domain.secrets.secret.is_secret_uri(uri: str) -> bool
```

`from roboto.domain.secrets import is_secret_uri`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/secrets/secret.py#L44-L52)

Return whether a string begins with a secret URI, as `Secret.uri` formats one.

Roboto calls this when an action runs, to find the action parameter values that name a secret.

**Parameters**

- **uri** (`str`): String to check, such as an action parameter's value.

**Returns**

- `bool`

### parse_secret_uri()

```python
def roboto.domain.secrets.secret.parse_secret_uri(uri: str) -> ParsedSecretName
```

`from roboto.domain.secrets.secret import parse_secret_uri`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/secrets/secret.py#L55-L72)

Return the secret name and organization ID that a secret URI names.

Roboto calls this when an action runs, to find the secrets its parameters name. To load the secret a URI names, use `Secret.from_uri`.

**Parameters**

- **uri** (`str`): Secret URI, as `roboto-secret://<name>` or `roboto-secret://<name>@<org_id>`.

**Raises**

- `ValueError`: `uri` does not begin with a secret URI.

**Returns**

- `ParsedSecretName`
