Last active
September 24, 2024 14:43
-
-
Save prmoore77/cc506ad976772a5fa850eca503006a62 to your computer and use it in GitHub Desktop.
Write out a CSV file with PyArrow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from dotenv import load_dotenv | |
import pyarrow as pa | |
from pyarrow.fs import S3FileSystem | |
from pyarrow import csv | |
# Load environment | |
load_dotenv(dotenv_path="env.txt") | |
# Create a dummy table | |
table = pa.table({"a": [1, 2, 3], "b": [4, 5, 6]}) | |
# Setup an S3 file system | |
s3 = S3FileSystem(access_key=os.environ['AWS_ACCESS_KEY_ID'], | |
secret_key=os.environ['AWS_SECRET_ACCESS_KEY'], | |
session_token=os.environ['AWS_SESSION_TOKEN'], | |
region=os.environ['AWS_REGION'] | |
) | |
s3_path = "voltrondata-demo-data-us-east-2/phil_test/joe.csv" | |
with s3.open_output_stream(path=s3_path) as s3_file: | |
csv.write_csv(data=table, output_file=s3_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment