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

# leasing

# `prefect.server.utilities.leasing`

## Classes

### `ResourceLease` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/utilities/leasing.py#L13](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/utilities/leasing.py#L13)</sup>

### `LeaseStorage` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/utilities/leasing.py#L21](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/utilities/leasing.py#L21)</sup>

**Methods:**

#### `create_lease` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/utilities/leasing.py#L22](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/utilities/leasing.py#L22)</sup>

```python theme={null}
create_lease(self, resource_ids: list[UUID], ttl: timedelta, metadata: T | None = None) -> ResourceLease[T]
```

Create a new resource lease.

**Args:**

* `resource_ids`: The IDs of the resources that the lease is associated with.
* `ttl`: How long the lease should initially be held for.
* `metadata`: Additional metadata associated with the lease.

**Returns:**

* A ResourceLease object representing the lease.

#### `read_expired_lease_ids` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/utilities/leasing.py#L74](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/utilities/leasing.py#L74)</sup>

```python theme={null}
read_expired_lease_ids(self, limit: int = 100) -> list[UUID]
```

Read the IDs of expired leases.

**Args:**

* `limit`: The maximum number of expired leases to read.

**Returns:**

* A list of UUIDs representing the expired leases.

#### `read_lease` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/utilities/leasing.py#L38](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/utilities/leasing.py#L38)</sup>

```python theme={null}
read_lease(self, lease_id: UUID) -> ResourceLease[T] | None
```

Read a resource lease.

**Args:**

* `lease_id`: The ID of the lease to read.

**Returns:**

* A ResourceLease object representing the lease, or None if not found.

#### `renew_lease` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/utilities/leasing.py#L50](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/utilities/leasing.py#L50)</sup>

```python theme={null}
renew_lease(self, lease_id: UUID, ttl: timedelta) -> bool | None
```

Renew a resource lease.

**Args:**

* `lease_id`: The ID of the lease to renew.
* `ttl`: The new amount of time the lease should be held for.

**Returns:**

* True if the lease was successfully renewed, False if the lease
* does not exist or has already expired. None may be returned by
* legacy implementations for backwards compatibility (treated as success).

#### `revoke_lease` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/utilities/leasing.py#L65](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/utilities/leasing.py#L65)</sup>

```python theme={null}
revoke_lease(self, lease_id: UUID) -> None
```

Release a resource lease by removing it from list of active leases.

**Args:**

* `lease_id`: The ID of the lease to release.
