S3 / Client / list_object_versions
list_object_versions#
- S3.Client.list_object_versions(**kwargs)#
Note
This operation is not supported for directory buckets.
Returns metadata about all versions of the objects in a bucket. You can also use request parameters as selection criteria to return metadata about a subset of all the object versions.
Warning
To use this operation, you must have permission to perform the
s3:ListBucketVersions
action. Be aware of the name difference.Note
A
200 OK
response can contain valid or invalid XML. Make sure to design your application to parse the contents of the response and handle it appropriately.To use this operation, you must have READ access to the bucket.
The following operations are related to
ListObjectVersions
:See also: AWS API Documentation
Request Syntax
response = client.list_object_versions( Bucket='string', Delimiter='string', EncodingType='url', KeyMarker='string', MaxKeys=123, Prefix='string', VersionIdMarker='string', ExpectedBucketOwner='string', RequestPayer='requester', OptionalObjectAttributes=[ 'RestoreStatus', ] )
- Parameters:
Bucket (string) –
[REQUIRED]
The bucket name that contains the objects.
Delimiter (string) – A delimiter is a character that you specify to group keys. All keys that contain the same string between the
prefix
and the first occurrence of the delimiter are grouped under a single result element inCommonPrefixes
. These groups are counted as one result against themax-keys
limitation. These keys are not returned elsewhere in the response.EncodingType (string) –
Encoding type used by Amazon S3 to encode the object keys in the response. Responses are encoded only in UTF-8. An object key can contain any Unicode character. However, the XML 1.0 parser can’t parse certain characters, such as characters with an ASCII value from 0 to 10. For characters that aren’t supported in XML 1.0, you can add this parameter to request that Amazon S3 encode the keys in the response. For more information about characters to avoid in object key names, see Object key naming guidelines.
Note
When using the URL encoding type, non-ASCII characters that are used in an object’s key name will be percent-encoded according to UTF-8 code values. For example, the object
test_file(3).png
will appear astest_file%283%29.png
.KeyMarker (string) – Specifies the key to start with when listing objects in a bucket.
MaxKeys (integer) – Sets the maximum number of keys returned in the response. By default, the action returns up to 1,000 key names. The response might contain fewer keys but will never contain more. If additional keys satisfy the search criteria, but were not returned because
max-keys
was exceeded, the response contains<isTruncated>true</isTruncated>
. To return the additional keys, seekey-marker
andversion-id-marker
.Prefix (string) – Use this parameter to select only those keys that begin with the specified prefix. You can use prefixes to separate a bucket into different groupings of keys. (You can think of using
prefix
to make groups in the same way that you’d use a folder in a file system.) You can useprefix
withdelimiter
to roll up numerous objects into a single result underCommonPrefixes
.VersionIdMarker (string) – Specifies the object version you want to start listing from.
ExpectedBucketOwner (string) – The account ID of the expected bucket owner. If the account ID that you provide does not match the actual owner of the bucket, the request fails with the HTTP status code
403 Forbidden
(access denied).RequestPayer (string) –
Confirms that the requester knows that they will be charged for the request. Bucket owners need not specify this parameter in their requests. If either the source or destination S3 bucket has Requester Pays enabled, the requester will pay for corresponding charges to copy the object. For information about downloading objects from Requester Pays buckets, see Downloading Objects in Requester Pays Buckets in the Amazon S3 User Guide.
Note
This functionality is not supported for directory buckets.
OptionalObjectAttributes (list) –
Specifies the optional fields that you want returned in the response. Fields that you do not specify are not returned.
(string) –
- Return type:
dict
- Returns:
Response Syntax
{ 'IsTruncated': True|False, 'KeyMarker': 'string', 'VersionIdMarker': 'string', 'NextKeyMarker': 'string', 'NextVersionIdMarker': 'string', 'Versions': [ { 'ETag': 'string', 'ChecksumAlgorithm': [ 'CRC32'|'CRC32C'|'SHA1'|'SHA256', ], 'Size': 123, 'StorageClass': 'STANDARD', 'Key': 'string', 'VersionId': 'string', 'IsLatest': True|False, 'LastModified': datetime(2015, 1, 1), 'Owner': { 'DisplayName': 'string', 'ID': 'string' }, 'RestoreStatus': { 'IsRestoreInProgress': True|False, 'RestoreExpiryDate': datetime(2015, 1, 1) } }, ], 'DeleteMarkers': [ { 'Owner': { 'DisplayName': 'string', 'ID': 'string' }, 'Key': 'string', 'VersionId': 'string', 'IsLatest': True|False, 'LastModified': datetime(2015, 1, 1) }, ], 'Name': 'string', 'Prefix': 'string', 'Delimiter': 'string', 'MaxKeys': 123, 'CommonPrefixes': [ { 'Prefix': 'string' }, ], 'EncodingType': 'url', 'RequestCharged': 'requester' }
Response Structure
(dict) –
IsTruncated (boolean) –
A flag that indicates whether Amazon S3 returned all of the results that satisfied the search criteria. If your results were truncated, you can make a follow-up paginated request by using the
NextKeyMarker
andNextVersionIdMarker
response parameters as a starting place in another request to return the rest of the results.KeyMarker (string) –
Marks the last key returned in a truncated response.
VersionIdMarker (string) –
Marks the last version of the key returned in a truncated response.
NextKeyMarker (string) –
When the number of responses exceeds the value of
MaxKeys
,NextKeyMarker
specifies the first key not returned that satisfies the search criteria. Use this value for the key-marker request parameter in a subsequent request.NextVersionIdMarker (string) –
When the number of responses exceeds the value of
MaxKeys
,NextVersionIdMarker
specifies the first object version not returned that satisfies the search criteria. Use this value for theversion-id-marker
request parameter in a subsequent request.Versions (list) –
Container for version information.
(dict) –
The version of an object.
ETag (string) –
The entity tag is an MD5 hash of that version of the object.
ChecksumAlgorithm (list) –
The algorithm that was used to create a checksum of the object.
(string) –
Size (integer) –
Size in bytes of the object.
StorageClass (string) –
The class of storage used to store the object.
Key (string) –
The object key.
VersionId (string) –
Version ID of an object.
IsLatest (boolean) –
Specifies whether the object is (true) or is not (false) the latest version of an object.
LastModified (datetime) –
Date and time when the object was last modified.
Owner (dict) –
Specifies the owner of the object.
DisplayName (string) –
Container for the display name of the owner. This value is only supported in the following Amazon Web Services Regions:
US East (N. Virginia)
US West (N. California)
US West (Oregon)
Asia Pacific (Singapore)
Asia Pacific (Sydney)
Asia Pacific (Tokyo)
Europe (Ireland)
South America (São Paulo)
Note
This functionality is not supported for directory buckets.
ID (string) –
Container for the ID of the owner.
RestoreStatus (dict) –
Specifies the restoration status of an object. Objects in certain storage classes must be restored before they can be retrieved. For more information about these storage classes and how to work with archived objects, see Working with archived objects in the Amazon S3 User Guide.
IsRestoreInProgress (boolean) –
Specifies whether the object is currently being restored. If the object restoration is in progress, the header returns the value
TRUE
. For example:x-amz-optional-object-attributes: IsRestoreInProgress="true"
If the object restoration has completed, the header returns the value
FALSE
. For example:x-amz-optional-object-attributes: IsRestoreInProgress="false", RestoreExpiryDate="2012-12-21T00:00:00.000Z"
If the object hasn’t been restored, there is no header response.
RestoreExpiryDate (datetime) –
Indicates when the restored copy will expire. This value is populated only if the object has already been restored. For example:
x-amz-optional-object-attributes: IsRestoreInProgress="false", RestoreExpiryDate="2012-12-21T00:00:00.000Z"
DeleteMarkers (list) –
Container for an object that is a delete marker.
(dict) –
Information about the delete marker.
Owner (dict) –
The account that created the delete marker.>
DisplayName (string) –
Container for the display name of the owner. This value is only supported in the following Amazon Web Services Regions:
US East (N. Virginia)
US West (N. California)
US West (Oregon)
Asia Pacific (Singapore)
Asia Pacific (Sydney)
Asia Pacific (Tokyo)
Europe (Ireland)
South America (São Paulo)
Note
This functionality is not supported for directory buckets.
ID (string) –
Container for the ID of the owner.
Key (string) –
The object key.
VersionId (string) –
Version ID of an object.
IsLatest (boolean) –
Specifies whether the object is (true) or is not (false) the latest version of an object.
LastModified (datetime) –
Date and time when the object was last modified.
Name (string) –
The bucket name.
Prefix (string) –
Selects objects that start with the value supplied by this parameter.
Delimiter (string) –
The delimiter grouping the included keys. A delimiter is a character that you specify to group keys. All keys that contain the same string between the prefix and the first occurrence of the delimiter are grouped under a single result element in
CommonPrefixes
. These groups are counted as one result against themax-keys
limitation. These keys are not returned elsewhere in the response.MaxKeys (integer) –
Specifies the maximum number of objects to return.
CommonPrefixes (list) –
All of the keys rolled up into a common prefix count as a single return when calculating the number of returns.
(dict) –
Container for all (if there are any) keys between Prefix and the next occurrence of the string specified by a delimiter. CommonPrefixes lists keys that act like subdirectories in the directory specified by Prefix. For example, if the prefix is notes/ and the delimiter is a slash (/) as in notes/summer/july, the common prefix is notes/summer/.
Prefix (string) –
Container for the specified common prefix.
EncodingType (string) –
Encoding type used by Amazon S3 to encode object key names in the XML response.
If you specify the
encoding-type
request parameter, Amazon S3 includes this element in the response, and returns encoded key name values in the following response elements:KeyMarker, NextKeyMarker, Prefix, Key
, andDelimiter
.RequestCharged (string) –
If present, indicates that the requester was successfully charged for the request.
Note
This functionality is not supported for directory buckets.
Examples
The following example return versions of an object with specific key name prefix. The request limits the number of items returned to two. If there are are more than two object version, S3 returns NextToken in the response. You can specify this token value in your next request to fetch next set of object versions.
response = client.list_object_versions( Bucket='examplebucket', Prefix='HappyFace.jpg', ) print(response)
Expected Output:
{ 'Versions': [ { 'ETag': '"6805f2cfc46c0f04559748bb039d69ae"', 'IsLatest': True, 'Key': 'HappyFace.jpg', 'LastModified': datetime(2016, 12, 15, 1, 19, 41, 3, 350, 0), 'Owner': { 'DisplayName': 'owner-display-name', 'ID': 'examplee7a2f25102679df27bb0ae12b3f85be6f290b936c4393484be31bebcc', }, 'Size': 3191, 'StorageClass': 'STANDARD', 'VersionId': 'null', }, { 'ETag': '"6805f2cfc46c0f04559748bb039d69ae"', 'IsLatest': False, 'Key': 'HappyFace.jpg', 'LastModified': datetime(2016, 12, 13, 0, 58, 26, 1, 348, 0), 'Owner': { 'DisplayName': 'owner-display-name', 'ID': 'examplee7a2f25102679df27bb0ae12b3f85be6f290b936c4393484be31bebcc', }, 'Size': 3191, 'StorageClass': 'STANDARD', 'VersionId': 'PHtexPGjH2y.zBgT8LmB7wwLI2mpbz.k', }, ], 'ResponseMetadata': { '...': '...', }, }