Quickstart
This guide will walk you through a simple example of using flowerpower-io to load data from a JSON file and save it to a CSV file.
1. Prepare your data
First, let’s create a sample JSON file named data.json:
[
{
"id": 1,
"name": "Alice",
"age": 30
},
{
"id": 2,
"name": "Bob",
"age": 24
},
{
"id": 3,
"name": "Charlie",
"age": 35
}
]Save this content to a file named data.json in the same directory where you’ll run your Python script.
2. Write the Python script
Now, create a Python script (e.g., quickstart_example.py) with the following content:
from fsspec_utils.utils.types import dict_to_dataframe
from flowerpower_io.loader import ParquetFileReader
from flowerpower_io.saver import CSVFileWriter, ParquetFileWriter
import json
import os
# Create dummy JSON data
json_data = """
[
{
"id": 1,
"name": "Alice",
"age": 30
},
{
"id": 2,
"name": "Bob",
"age": 24
},
{
"id": 3,
"name": "Charlie",
"age": 35
}
]
"""
# Create dataframe from json data
df = dict_to_dataframe(json.loads(json_data))
saver1 = ParquetFileWriter("data.parquet")
saver1.write(df)
# Load data from Parquet
loader = ParquetFileReader(path="data.parquet")
data_frame = loader.to_pandas()
print("Data loaded from Parquet:")
print(data_frame)
# Save data to CSV
saver = CSVFileWriter(path="output.csv")
saver.write(data_frame)
print("\nData saved to output.csv")
# Clean up generated files (optional)
os.remove("data.parquet")
os.remove("output.csv")3. Run the script
Execute the Python script. If you’ve installed flowerpower-io in a virtual environment, make sure it’s activated:
uv run python quickstart_example.pyYou should see output similar to this, indicating the data was loaded and saved successfully:
Data loaded from JSON:
shape: (3, 3)
┌─────┬─────────┬─────┐
│ id ┆ name ┆ age │
│ --- ┆ --- ┆ --- │
│ i64 ┆ str ┆ i64 │
╞═════╪═════════╪═════╡
│ 1 ┆ Alice ┆ 30 │
│ 2 ┆ Bob ┆ 24 │
│ 3 ┆ Charlie ┆ 35 │
└─────┴─────────┴─────┘
Data saved to output.csv
This example demonstrates the basic workflow of using flowerpower-io to move data between different formats. You can extend this to various other supported formats and sources.