[Cloudian # 5] Try to list the objects stored in the bucket with Python (boto3)

Introduction

Cloudian is fully compatible with S3, so it's convenient to use the AWS SDK! Last time tried to transfer files with Python (boto3).

This time, I would like to list the objects stored in the bucket of object storage with Python (boto3).

List the objects stored in the bucket / list_objects ()

Use list_objects () to check the existence of files (objects) uploaded to Cloudian. list_objects () returns a lot of information in Python's dict type. In the following example, only the key and size of the object and the date and time of the last modification are displayed from the returned values.

test.py


import boto3

client = boto3.client(
    's3',
    endpoint_url='https://xxx.yyy.com'
)


#Bucket name:List all pythonbucket1 objects
for obj in client.list_objects(Bucket='pythonbucket1')['Contents']: 
    print(obj['Key'], obj['Size'],
    obj['LastModified'].strftime("%Y/%m/%d %H:%M:%S"))
10mb.dat 10485760 2020/12/14 03:12:38

Summary

I tried to display a list of objects with Python (boto3).

Next time, I would like to operate object storage/Cloudian in various ways with Python.

Recommended Posts

[Cloudian # 5] Try to list the objects stored in the bucket with Python (boto3)
[Cloudian # 6] Try deleting the object stored in the bucket with Python (boto3)
[Cloudian # 7] Try deleting the bucket in Python (boto3)
[Cloudian # 2] Try to display the object storage bucket in Python (boto3)
[Cloudian # 8] Try setting the bucket versioning with Python (boto3)
[Cloudian # 9] Try to display the metadata of the object in Python (boto3)
[Cloudian # 3] Try to create a new object storage bucket with Python (boto3)
Try logging in to qiita with Python
Python amateurs try to summarize the list ①
Try to solve the man-machine chart with Python
[Cloudian # 1] Try to access object storage with AWS SDK for Python (boto3)
[Cloudian # 10] Try to generate a signed URL for object publishing in Python (boto3)
How to get a list of files in the same directory with python
Try to solve the programming challenge book with python3
Try to solve the internship assignment problem with Python
Convert the image in .zip to PDF with Python
Try to decipher the login data stored in Firefox
[Python] How to output the list values in order
How to identify the element with the smallest number of characters in a Python list?
How to count the number of occurrences of each element in the list in Python with weight
Try scraping the data of COVID-19 in Tokyo with Python
Try to get the function list of Python> os package
Try sorting your own objects with priority queue in Python
Try to automate the operation of network devices with Python
Try to decipher the garbled attachment file name with Python
I wanted to delete multiple objects in s3 with boto3
Try to operate Facebook with Python
In the python command python points to python3.8
Convert list to DataFrame with python
Try to calculate Trace in Python
Recursively get the Excel list in a specific folder with python and write it to Excel.
6 ways to string objects in Python
Examine the object's class in python
Cython to try in the shortest
Output the key list included in S3 Bucket to a file
To make sure that the specified key is in the specified bucket in Boto 3
Try to get a list of breaking news threads in Python.
Output the contents of ~ .xlsx in the folder to HTML with Python
Try to solve the shortest path with Python + NetworkX + social data
Try to reproduce color film with Python
Try using the Wunderlist API in Python
Try using the Kraken API in Python
Try working with binary data in Python
OR the List in Python (zip function)
Display Python 3 in the browser with MAMP
How to work with BigQuery in Python
To work with timestamp stations in Python
Try hitting the YouTube API in Python
Get the EDINET code list in Python
The road to compiling to Python 3 with Thrift
Memorandum (Add name only to people with the same surname in the list)
Put Cabocha 0.68 on Windows and try to analyze the dependency with Python
How to get the date and time difference in seconds with python
Try to image the elevation data of the Geographical Survey Institute with Python
[Introduction to Python] How to sort the contents of a list efficiently with list sort
Receive a list of the results of parallel processing in Python with starmap
Move the turtle to the place where you click the mouse with turtle in Python
Get the list in the S3 bucket with Python and search with a specific Key. Output the Key name, last update date, and count number to a file.
How to pass the execution result of a shell command in a list in Python
How to use the C library in Python
Log in to the remote server with SSH