Skip to content

API Reference

Welcome to the flowerpower-io API reference documentation. This section provides detailed information about all public classes, functions, and methods available in the library.

Overview

The flowerpower-io library provides a unified interface for reading and writing data from various sources and formats. The API is organized into several modules:

Quick Navigation

Base Classes

The base classes form the foundation of the library and provide common functionality for all I/O operations.

Metadata Functions

Metadata functions help you understand the structure and properties of your data before processing it.

Loader Classes

Loader classes provide specialized functionality for reading data from various sources.

File Loaders

Database Loaders

Saver Classes

Saver classes provide specialized functionality for writing data to various destinations.

File Savers

Database Savers

Usage Examples

Basic File Operations

from flowerpower_io import CSVLoader, ParquetSaver

# Load data from CSV
loader = CSVLoader("data.csv")
df = loader.to_polars()

# Save data to Parquet
saver = ParquetSaver("output/")
saver.write(df)

Database Operations

from flowerpower_io import PostgreSQLLoader, SQLiteSaver

# Load from PostgreSQL
loader = PostgreSQLLoader(
    host="localhost",
    username="user",
    password="password",
    database="mydb",
    table_name="users"
)
df = loader.to_polars()

# Save to SQLite
saver = SQLiteSaver(
    path="database.db",
    table_name="users"
)
saver.write(df)

Metadata Extraction

from flowerpower_io.metadata import get_dataframe_metadata

# Get metadata from DataFrame
metadata = get_dataframe_metadata(df)
print(metadata)

Common Patterns

Reading Multiple Files

from flowerpower_io import ParquetLoader

# Load multiple Parquet files
loader = ParquetLoader("data/*.parquet")
df = loader.to_polars()

Writing with Partitioning

from flowerpower_io import ParquetSaver

# Save with partitioning
saver = ParquetSaver(
    path="output/",
    partition_by="category",
    compression="zstd"
)
saver.write(df)

Database Connection Management

from flowerpower_io import PostgreSQLLoader

# Using context manager for connection
with PostgreSQLLoader(
    host="localhost",
    username="user",
    password="password",
    database="mydb"
) as loader:
    df = loader.to_polars()

Error Handling

The library provides comprehensive error handling for various scenarios:

from flowerpower_io import CSVLoader

try:
    loader = CSVLoader("nonexistent.csv")
    df = loader.to_polars()
except FileNotFoundError:
    print("File not found")
except Exception as e:
    print(f"Error: {e}")

Performance Tips

  1. Use opt_dtypes=True for better memory efficiency
  2. Use batch_size for large datasets
  3. Use concat=False when working with multiple files separately
  4. Use appropriate compression for your data format
  5. Use partitioning for large datasets

See Also