LeaseClient class

Definition

Creates a new LeaseClient.

This client provides lease operations on a BlobClient or ContainerClient.

LeaseClient(client, lease_id=None)
Inheritance
builtins.object
azure.storage.blob.lease.LeaseClient
LeaseClient

Parameters

client
BlobClient or ContainerClient

The client of the blob or container to lease.

lease_id
str

A string representing the lease ID of an existing lease. This value does not need to be specified in order to acquire a new lease, or break one.

Variables

id
str
The ID of the lease currently being maintained. This will be *None* if no lease has yet been acquired.
etag
str
The ETag of the lease currently being maintained. This will be *None* if no lease has yet been acquired or modified.
last_modified
datetime
The last modified timestamp of the lease currently being maintained. This will be *None* if no lease has yet been acquired or modified.

Methods

acquire(lease_duration=-1, **kwargs)

Requests a new lease.

If the container does not have an active lease, the Blob service creates a lease on the container and returns a new lease ID.

break_lease(lease_break_period=None, **kwargs)

Break the lease, if the container or blob has an active lease.

Once a lease is broken, it cannot be renewed. Any authorized request can break the lease; the request is not required to specify a matching lease ID. When a lease is broken, the lease break period is allowed to elapse, during which time no lease operation except break and release can be performed on the container or blob. When a lease is successfully broken, the response indicates the interval in seconds until a new lease can be acquired.

change(proposed_lease_id, **kwargs)

Change the lease ID of an active lease.

release(**kwargs)

Release the lease.

The lease may be released if the client lease id specified matches that associated with the container or blob. Releasing the lease allows another client to immediately acquire the lease for the container or blob as soon as the release is complete.

renew(**kwargs)

Renews the lease.

The lease can be renewed if the lease ID specified in the lease client matches that associated with the container or blob. Note that the lease may be renewed even if it has expired as long as the container or blob has not been leased again since the expiration of that lease. When you renew a lease, the lease duration clock resets.

acquire(lease_duration=-1, **kwargs)

Requests a new lease.

If the container does not have an active lease, the Blob service creates a lease on the container and returns a new lease ID.

acquire(lease_duration=-1, **kwargs)

Parameters

lease_duration
int

Specifies the duration of the lease, in seconds, or negative one (-1) for a lease that never expires. A non-infinite lease can be between 15 and 60 seconds. A lease duration cannot be changed using renew or change. Default is -1 (infinite lease).

if_modified_since
datetime

A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

if_unmodified_since
datetime

A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

if_match
str

An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the resource's ETag matches the value specified.

if_none_match
str

An ETag value, or the wildcard character (). Specify this header to perform the operation only if the resource's ETag does not match the value specified. Specify the wildcard character () to perform the operation only if the resource does not exist, and fail the operation if it does exist.

timeout
int

The timeout parameter is expressed in seconds.

Return type

break_lease(lease_break_period=None, **kwargs)

Break the lease, if the container or blob has an active lease.

Once a lease is broken, it cannot be renewed. Any authorized request can break the lease; the request is not required to specify a matching lease ID. When a lease is broken, the lease break period is allowed to elapse, during which time no lease operation except break and release can be performed on the container or blob. When a lease is successfully broken, the response indicates the interval in seconds until a new lease can be acquired.

break_lease(lease_break_period=None, **kwargs)

Parameters

lease_break_period
int

This is the proposed duration of seconds that the lease should continue before it is broken, between 0 and 60 seconds. This break period is only used if it is shorter than the time remaining on the lease. If longer, the time remaining on the lease is used. A new lease will not be available before the break period has expired, but the lease may be held for longer than the break period. If this header does not appear with a break operation, a fixed-duration lease breaks after the remaining lease period elapses, and an infinite lease breaks immediately.

if_modified_since
datetime

A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

if_unmodified_since
datetime

A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

timeout
int

The timeout parameter is expressed in seconds.

Returns

Approximate time remaining in the lease period, in seconds.

Return type

int

change(proposed_lease_id, **kwargs)

Change the lease ID of an active lease.

change(proposed_lease_id, **kwargs)

Parameters

proposed_lease_id
str

Proposed lease ID, in a GUID string format. The Blob service returns 400 (Invalid request) if the proposed lease ID is not in the correct format.

if_modified_since
datetime

A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

if_unmodified_since
datetime

A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

if_match
str

An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the resource's ETag matches the value specified.

if_none_match
str

An ETag value, or the wildcard character (). Specify this header to perform the operation only if the resource's ETag does not match the value specified. Specify the wildcard character () to perform the operation only if the resource does not exist, and fail the operation if it does exist.

timeout
int

The timeout parameter is expressed in seconds.

Returns

None

release(**kwargs)

Release the lease.

The lease may be released if the client lease id specified matches that associated with the container or blob. Releasing the lease allows another client to immediately acquire the lease for the container or blob as soon as the release is complete.

release(**kwargs)

Parameters

if_modified_since
datetime

A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

if_unmodified_since
datetime

A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

if_match
str

An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the resource's ETag matches the value specified.

if_none_match
str

An ETag value, or the wildcard character (). Specify this header to perform the operation only if the resource's ETag does not match the value specified. Specify the wildcard character () to perform the operation only if the resource does not exist, and fail the operation if it does exist.

timeout
int

The timeout parameter is expressed in seconds.

Returns

None

renew(**kwargs)

Renews the lease.

The lease can be renewed if the lease ID specified in the lease client matches that associated with the container or blob. Note that the lease may be renewed even if it has expired as long as the container or blob has not been leased again since the expiration of that lease. When you renew a lease, the lease duration clock resets.

renew(**kwargs)

Parameters

if_modified_since
datetime

A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

if_unmodified_since
datetime

A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

if_match
str

An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the resource's ETag matches the value specified.

if_none_match
str

An ETag value, or the wildcard character (). Specify this header to perform the operation only if the resource's ETag does not match the value specified. Specify the wildcard character () to perform the operation only if the resource does not exist, and fail the operation if it does exist.

timeout
int

The timeout parameter is expressed in seconds.

Returns

None