supabase-py icon indicating copy to clipboard operation
supabase-py copied to clipboard

increasing the storage list limit beyond 100

Open nyck33 opened this issue 1 year ago • 0 comments

Rather than doing something like this:

# Function to list all files with pagination
def list_all_files(storage, bucket_name):
    offset = 0
    limit = 100  # The maximum number of files to retrieve per request
    all_files = []

    while True:
        response = storage.from_(bucket_name).list(limit=limit, offset=offset)
        files = response.data
        if files:
            all_files.extend(files)
            offset += limit
        else:
            break

    return all_files

# List all files in the bucket
all_files = list_all_files(supabase.storage, bucket_name)
print(f"Total files: {len(all_files)}")

I prefer to get a list of all file names in a bucket like

url: str = os.getenv("SUPABASE_URL")
#key: str = os.getenv("SUPABASE_SERVICE_ROLE_KEY")
key: str = os.getenv("SUPABASE_ANON_KEY")

supabase: Client = create_client(url, key)

SUPABASE_EMAIL = os.environ.get("SUPABASE_EMAIL")
SUPABASE_PASSWORD = os.environ.get("SUPABASE_PASSWORD")

# print secrets
print(SUPABASE_EMAIL, SUPABASE_PASSWORD)
my_session = supabase.auth.sign_in_with_password({"email": SUPABASE_EMAIL, "password":SUPABASE_PASSWORD})
# 

# Your storage bucket name
bucket_name = "scratch-assignments"
#%%
# List files in the bucket
files = supabase.storage.from_("scratch-assignments").list()
#%%
print(len(files)) #prints 100 but there are 104 files in the storage
#%%

That's a list of dictionaries but the contents are not that large so I'm not sure why it's set to such a low limit. Can you parameterize it like

files = supabase.storage.from_("scratch-assignments", max_ret=1000)

nyck33 avatar Feb 22 '24 09:02 nyck33