Python Library for Compressing Files in Google Cloud Storage
This Python library provides a function to convert a CSV file stored in a Google Cloud Storage (GCS) bucket to a Parquet file and upload it back to the same bucket.
Functionality
- Downloads a CSV file from a specified GCS bucket.
- Reads the CSV data into a pandas DataFrame.
- Converts the DataFrame to an Arrow Table for efficient Parquet storage.
- Uploads the Arrow Table as a Parquet file to the GCS bucket.
- Optionally allows specifying an output folder within the bucket to store the Parquet file.
Installation You'll need the following:
- Python 3.6 or later
- google-cloud-storage
- pandas
- pyarrow
Install them using pip:
pip install google-cloud-storage pandas pyarrow
Example Usage:
from gcs_convert_csv_to_parquet import gcs_convert_csv_to_parquet
# Define your parameters
bucket_name = 'your-bucket-name'
csv_file = 'your-csv-file.csv'
parquet_file = 'your-output-file.parquet'
output_folder = 'optional-output-folder' # Optional
# Convert CSV to Parquet and upload to GCS
gcs_convert_csv_to_parquet(bucket_name, csv_file, parquet_file, output_folder)
The gcs_convert_csv_to_parquet function takes the following arguments:
Parameters:
- bucket_name (str): The name of the bucket containing the CSV file.
- csv_file (str): The name of the CSV file to convert.
- parquet_file (str): The desired name for the output Parquet file.
- output_folder (str, optional): The folder within the bucket to store the Parquet file. If None, the file will be stored at the root level of the bucket.
Notes
- This library assumes you have proper authentication set up to access Google Cloud Storage.
- The CSV file must be valid and well-formatted.
- Error handling is included to catch potential exceptions during conversion or upload.
Example Usage This example converts a CSV file named data.csv to a Parquet file named data.parquet and stores it in the output_folder within the specified bucket:
gcs_convert_csv_to_parquet("my-bucket", "data.csv", "data.parque
This will print a success message upon successful conversion and upload.
Metadata
Release files for gcs-convert-csv-to-parquet 0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| gcs_convert_csv_to_parquet-0.0.tar.gz | 2.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gcs_convert_csv_to_parquet-0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.1 kB
Release files / gcs_convert_csv_to_parquet-0.0.tar.gz
| Download URL | gcs_convert_csv_to_parquet-0.0.tar.gz |
|---|---|
| Size | 2.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0aa2d41fdf416cd625307b21a704ec1e9c70f287a7fd8912b0a1197e2102181c
|
|
BLAKE2b-256 checksum How to use checksums |
fb0a4bed7dd56459348639f84b874bf94b588ed234d685ddb90d37c311f3eab3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Release files / gcs_convert_csv_to_parquet-0.0-py3-none-any.whl
| Download URL | gcs_convert_csv_to_parquet-0.0-py3-none-any.whl |
|---|---|
| Size | 3.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a61e19607d0f434e1bea25b54b36647e8aae6918c458aa4627c2c115fbc49347
|
|
BLAKE2b-256 checksum How to use checksums |
7de7353738bf97300afcdca185c3aaa1da404dcb071e5bcd670fa109056044d2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|