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:
-
bucket_name (str): The name of the Google Cloud Storage bucket.
-
folder_name (str): The name of the folder within the bucket to list files from.
-
filename_needed (bool, optional): Defaults to True. If True, returns a list of filenames.
-
file_object_needed (bool, optional): Defaults to False. If True, returns a list of file objects.
-
list_sub_folders (bool, optional): Defaults to False. If True, includes files from subfolders within the specified folder.
Return Value:
- A list of filenames (strings) if filename_needed is True.
- A list of file objects, which can further be used to extract different aspects of the contained file, if file_object_needed is True.
- None if both filename_needed and file_object_needed are False.
- 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:
- This function requires the google-cloud-storage library to be installed.
- Ensure you have proper authentication set up to access the specified bucket.
- The function includes basic error handling, but you may want to implement more specific handling based on your needs.
- 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
Metadata
Release files for GCS-bucket-files-or-filenames 0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| GCS_bucket_files_or_filenames-0.6.tar.gz | 2.6 kB | Without provenance | Details for GCS_bucket_files_or_filenames-0.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| GCS_bucket_files_or_filenames-0.6-py3-none-any.whl | Python 3 | none | any | Details for GCS_bucket_files_or_filenames-0.6-py3-none-any.whl |
Total release size: 5.9 kB
Release files / GCS_bucket_files_or_filenames-0.6.tar.gz
| Download URL | GCS_bucket_files_or_filenames-0.6.tar.gz |
|---|---|
| Size | 2.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8f58780bdfe4181177f9c2c2b6484fc94029702a70bd73e1aa8f141a7a0fe26f
|
|
BLAKE2b-256 checksum How to use checksums |
40d8f74a6def74f12f58503f3aed1ce0f99a7e9a84b6fc1276af36b7bd69b558
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Release files / GCS_bucket_files_or_filenames-0.6-py3-none-any.whl
| Download URL | GCS_bucket_files_or_filenames-0.6-py3-none-any.whl |
|---|---|
| Size | 3.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d807a17dd1e1406f8d132207eb6acf305ce683050db05fe67021a0fc7564b578
|
|
BLAKE2b-256 checksum How to use checksums |
2398b0ba464e998c2a8c9f39c013af6886614c09fec2e3eb0abd2e15ae3b631d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Security for GCS-bucket-files-or-filenames 0.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.