> ## Documentation Index
> Fetch the complete documentation index at: https://infisical.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Get a secret

> Fetch one secret by name with the Python SDK.

`client.secrets.get_secret_by_name()` fetches one secret from a folder in an environment of a project. The machine identity needs a [role](https://infisical.com/docs/documentation/platform/access-controls/role-based-access-controls.md#project-level-access-controls) in the project that can read secrets, such as **Viewer**.

## Parameters

**secret\_name** `str` *required*

The name of the secret.

**project\_id** `str`

The ID of the project. Pass `project_id` or `project_slug`. If you pass both, the SDK uses `project_id`.

**project\_slug** `str`

The slug of the project.

**environment\_slug** `str` *required*

The slug of the environment, such as `dev`.

**secret\_path** `str` *required*

The path of the folder, such as `/` or `/backend`.

**version** `str`

The version of the secret to fetch. Defaults to the latest version. The [cache](https://infisical.com/docs/sdks/languages/python/client.md#create-a-client) ignores the version, so turn the cache off to fetch an older version.

**include\_imports** `bool` (default: True)

Whether to also look for the secret in the folder's [secret imports](https://infisical.com/docs/documentation/platform/secret-reference.md#secret-imports).

**expand\_secret\_references** `bool` (default: True)

Whether to replace each [secret reference](https://infisical.com/docs/documentation/platform/secret-reference.md#secret-referencing) in the value with the value it points to.

**view\_secret\_value** `bool` (default: True)

Whether to return the secret's value.

## Returns

**secret** `BaseSecret`

The secret.

**properties**

**secretKey** `str`

The name of the secret.

**secretValue** `str`

The value of the secret.

**secretValueHidden** `bool`

`True` if Infisical hid the value, because of `view_secret_value=False` or because the machine identity can't read the value.

**secretComment** `str`

The secret's comment.

**secretPath** `str`

The path of the folder that the secret is in.

**environment** `str`

The slug of the secret's environment.

**type** `str`

`shared`, or `personal` for a [personal override](https://infisical.com/docs/documentation/platform/secrets-mgmt/project.md#personal-overrides).

**version** `int`

The version number of the secret.

**tags** `List[dict]`

The secret's tags, each a dictionary with the keys `id`, `slug`, `name`, and `color`.

**secretMetadata** `list`

The key-value pairs stored with the secret, each with its `key` and `value`.

**id** `str`

The ID of the secret.

**createdAt** `str`

When the secret was created.

**updatedAt** `str`

When the secret was last updated.

```python Basic theme={"dark"}
secret = client.secrets.get_secret_by_name(
    secret_name="DATABASE_URL",
    project_id="<project-id>",
    environment_slug="dev",
    secret_path="/",
)

print(secret.secretValue)
```

```python In a folder theme={"dark"}
secret = client.secrets.get_secret_by_name(
    secret_name="DATABASE_URL",
    project_id="<project-id>",
    environment_slug="dev",
    secret_path="/backend",
)
```

```python Older version theme={"dark"}
secret = client.secrets.get_secret_by_name(
    secret_name="DATABASE_URL",
    project_id="<project-id>",
    environment_slug="dev",
    secret_path="/",
    version="3",
)
```

```json Response theme={"dark"}
{
  "id": "0b7c4a7e-5f3e-4d8a-9a51-2f6c1c0b3e21",
  "_id": "0b7c4a7e-5f3e-4d8a-9a51-2f6c1c0b3e21",
  "workspace": "5e8d7c6b-4a3f-4e2d-9c1b-0a9f8e7d6c5b",
  "environment": "dev",
  "secretKey": "DATABASE_URL",
  "secretValue": "postgres://app:<password>@db.internal:5432/app",
  "secretValueHidden": false,
  "secretComment": "",
  "secretPath": "/",
  "type": "shared",
  "version": 4,
  "tags": [],
  "secretMetadata": [],
  "createdAt": "2026-11-02T09:14:27.512Z",
  "updatedAt": "2026-11-30T16:41:03.208Z"
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.