> ## 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.

# Lease credentials

> Lease credentials from a dynamic secret with the Python SDK.

`client.dynamic_secrets.leases.create()` leases credentials from a [dynamic secret](https://infisical.com/docs/documentation/platform/dynamic-secrets/overview). Each lease gives your application its own credentials, which Infisical revokes when the lease expires or when you [revoke the lease](https://infisical.com/docs/sdks/languages/python/dynamic-secrets/revoke-lease.md).

To find the project slug, open the project, go to **Administration** > **Settings**, and copy the **Project slug**.

## Parameters

**dynamic\_secret\_name** `str` *required*

The name of the dynamic secret.

**project\_slug** `str` *required*

The slug of the project.

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

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

**path** `str` (default: /)

The path of the folder that the dynamic secret is in.

**ttl** `str`

How long the credentials stay valid, such as `30m` or `2h`. Defaults to the dynamic secret's default TTL, and can't be longer than its max TTL.

## Returns

**response** `CreateLeaseResponse`

**properties**

**data** `Any`

The credentials. The keys depend on the dynamic secret's provider, such as `DB_USERNAME` and `DB_PASSWORD` for a SQL database.

**lease** `DynamicSecretLease`

The lease, with its `id` and its expiry time in `expireAt`.

**dynamicSecret** `DynamicSecret`

The dynamic secret that the credentials come from.

```python Basic theme={"dark"}
response = client.dynamic_secrets.leases.create(
    dynamic_secret_name="postgres-readonly",
    project_slug="<project-slug>",
    environment_slug="dev",
)

username = response.data["DB_USERNAME"]
password = response.data["DB_PASSWORD"]
```

```python With a TTL theme={"dark"}
response = client.dynamic_secrets.leases.create(
    dynamic_secret_name="postgres-readonly",
    project_slug="<project-slug>",
    environment_slug="dev",
    path="/backend",
    ttl="30m",
)
```

```json Response theme={"dark"}
{
  "data": {
    "DB_USERNAME": "inf_a8f3k2",
    "DB_PASSWORD": "<password>"
  },
  "lease": {
    "id": "b2c3d4e5-f6a7-4b8c-9d0e-1f2a3b4c5d6e",
    "version": 1,
    "externalEntityId": "inf_a8f3k2",
    "expireAt": "2026-12-02T11:30:00.000Z",
    "status": null,
    "statusDetails": null,
    "dynamicSecretId": "4d5e6f7a-8b9c-4d0e-1f2a-3b4c5d6e7f8a",
    "createdAt": "2026-12-02T11:00:00.000Z",
    "updatedAt": "2026-12-02T11:00:00.000Z"
  },
  "dynamicSecret": {
    "id": "4d5e6f7a-8b9c-4d0e-1f2a-3b4c5d6e7f8a",
    "name": "postgres-readonly",
    "type": "sql-database",
    "defaultTTL": "1h",
    "maxTTL": "24h",
    "folderId": "3a1f6c2e-9b4d-4e7a-8c5f-2d1e0b9a8c7f",
    "version": 1,
    "createdAt": "2026-11-20T08:15:42.000Z",
    "updatedAt": "2026-11-20T08:15:42.000Z"
  }
}
```


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