Skip to main content

No project description provided

Project description

This document explains the usage of the Python function files_in_bucket, which can be used to list files within a specific folder in a Google Cloud Storage bucket.

Parameters:

  1. bucket_name (str): The name of the Google Cloud Storage bucket.

  2. folder_name (str): The name of the folder within the bucket to list files from.

  3. filename_needed (bool, optional): Defaults to True. If True, returns a list of filenames.

  4. file_object_needed (bool, optional): Defaults to False. If True, returns a list of file objects.

  5. list_sub_folders (bool, optional): Defaults to False. If True, includes files from subfolders within the specified folder.

Return Value:

  1. A list of filenames (strings) if filename_needed is True.
  2. A list of file objects, which can further be used to extract different aspects of the contained file, if file_object_needed is True.
  3. None if both filename_needed and file_object_needed are False.
  4. Raises an exception if an error occurs.

Example Usage:

Python:

from google.cloud import storage

bucket_name = "my-bucket" folder_name = "data/"

Get filenames only

filenames = files_in_bucket(bucket_name, folder_name) print(filenames)

Get file objects only

file_objects = files_in_bucket(bucket_name, folder_name, file_object_needed=True) for blob in file_objects: print(blob.name)

Include files from subfolders

all_files = files_in_bucket(bucket_name, folder_name, list_sub_folders=True) print(all_files)

Additional Notes:

  1. This function requires the google-cloud-storage library to be installed.
  2. Ensure you have proper authentication set up to access the specified bucket.
  3. The function includes basic error handling, but you may want to implement more specific handling based on your needs.
  4. I hope this README provides a clear explanation of the files_in_bucket function and its usage. Feel free to ask if you have any further questions. Email - preyaa.atri91@gmail.com

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

GCS_bucket_files_or_filenames-0.4.tar.gz (2.6 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file GCS_bucket_files_or_filenames-0.4.tar.gz.

File metadata

File hashes

Hashes for GCS_bucket_files_or_filenames-0.4.tar.gz
Algorithm Hash digest
SHA256 7dc8c7517f6984e4a182c1f302d222e61321016c12581ad6fd1703133a28c079
MD5 1648c754e598e58603e17c1cdd33946f
BLAKE2b-256 f1a4dacf3043a8eed66cd81fa1ec498e9cb2268c2bf9b2bdfff5a46b66279bbd

See more details on using hashes here.

File details

Details for the file GCS_bucket_files_or_filenames-0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for GCS_bucket_files_or_filenames-0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 5d6578d51b3077eca85dabd65b14eba58601377f24687a3ffb62ea95463c04dd
MD5 648db7554a9c190ebc258e9e436d865b
BLAKE2b-256 367995291fb8d9ed103cea5906a0bc593c974fa5e03e772fa50bc629f03e4455

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page