### Install FlowerPower using uv Source: https://legout.github.io/flowerpower/quickstart Installs the FlowerPower library using the `uv` package manager. It first creates and activates a virtual environment, then proceeds with the installation. ```bash # Create and activate a virtual environment uv venv source .venv/bin/activate # Install FlowerPower uv pip install flowerpower ``` -------------------------------- ### Run FlowerPower Pipeline using CLI Source: https://legout.github.io/flowerpower/quickstart Executes a FlowerPower pipeline using the CLI. Examples demonstrate running with default parameters, overriding inputs and final variables, and using RunConfig objects from files or JSON strings. ```bash # Basic pipeline execution flowerpower pipeline run hello_world # Run with individual parameters (kwargs) flowerpower pipeline run hello_world --inputs '{"greeting_message": "Hi", "target_name": "FlowerPower"}' --final-vars '["full_greeting"]' --log-level DEBUG # Run using a RunConfig from a YAML file # Assuming you have a run_config.yaml like: # inputs: # greeting_message: "Hola" # target_name: "Amigo" # log_level: "INFO" flowerpower pipeline run hello_world --run-config ./run_config.yaml # Run using a RunConfig provided as a JSON string flowerpower pipeline run hello_world --run-config '{"inputs": {"greeting_message": "Bonjour", "target_name": "Monde"}, "log_level": "INFO"}' # Mixing RunConfig with individual parameters (kwargs overrides RunConfig) # This will run with log_level="DEBUG" and inputs={"greeting_message": "Howdy", "target_name": "Partner"} flowerpower pipeline run hello_world --run-config '{"inputs": {"greeting_message": "Original", "target_name": "Value"}, "log_level": "INFO"}' --inputs '{"greeting_message": "Howdy", "target_name": "Partner"}' --log-level DEBUG ``` -------------------------------- ### Install FlowerPower with All Extras Source: https://legout.github.io/flowerpower/installation Installs FlowerPower with all optional dependencies, including I/O plugins and Hamilton UI, using `uv pip`. This provides the full feature set. ```shell uv pip install 'flowerpower[all]' ``` -------------------------------- ### Execute Pipeline with RunConfigBuilder - Python Source: https://legout.github.io/flowerpower/quickstart This example shows how to build a pipeline execution configuration using the RunConfigBuilder, which offers a fluent interface. It configures inputs, final variables, log level, and retry attempts for the 'hello_world' pipeline. The builder pattern simplifies the creation of complex RunConfig objects. ```python from flowerpower import FlowerPowerProject from flowerpower.cfg.pipeline.builder import RunConfigBuilder project = FlowerPowerProject.load('.') # Build a configuration using the builder pattern config = ( RunConfigBuilder(pipeline_name='hello_world') .with_inputs({"greeting_message": "Hello", "target_name": "World"}) .with_final_vars(["full_greeting"]) .with_log_level("DEBUG") .with_retries(max_attempts=3, delay=1.0) .build() ) result = project.run('hello_world', run_config=config) print(result) ``` -------------------------------- ### Initialize FlowerPower Project using CLI Source: https://legout.github.io/flowerpower/quickstart Initializes a new FlowerPower project with a specified name using the Command Line Interface (CLI). It then navigates into the newly created project directory. ```bash flowerpower init --name hello-flowerpower cd hello-flowerpower ``` -------------------------------- ### Install Flowerpower with uv Source: https://legout.github.io/flowerpower/-io/installation Installs the flowerpower-io package using the uv package manager. Supports installing with all optional dependencies. ```bash uv pip install flowerpower-io ``` ```bash uv pip install flowerpower-io[all] ``` -------------------------------- ### Install Flowerpower with Pip Source: https://legout.github.io/flowerpower/-io/installation Installs the flowerpower-io package using pip. Supports installing with all optional dependencies or specific extras like parquet and duckdb. ```bash pip install flowerpower-io ``` ```bash pip install flowerpower-io[all] ``` ```bash pip install flowerpower-io[parquet,duckdb] ``` -------------------------------- ### Install FlowerPower with I/O Extras Source: https://legout.github.io/flowerpower/installation Installs FlowerPower with additional I/O plugins using `uv pip`. This enables extended input/output capabilities for the library. ```shell uv pip install 'flowerpower[io]' ``` -------------------------------- ### Initialize FlowerPower Project using Python API Source: https://legout.github.io/flowerpower/quickstart Initializes a new FlowerPower project programmatically using the Python API. This method creates a standard project structure with necessary configuration directories. ```python from flowerpower import FlowerPowerProject # Initialize a new project project = FlowerPowerProject.new( name='hello-flowerpower' ) ``` -------------------------------- ### Install FlowerPower with UI Extras Source: https://legout.github.io/flowerpower/installation Installs FlowerPower with the Hamilton UI extra using `uv pip`. This enables interactive dataflow visualization features. ```shell uv pip install 'flowerpower[ui]' ``` -------------------------------- ### Configure FlowerPower Pipeline Parameters Source: https://legout.github.io/flowerpower/quickstart Configures the parameters for a FlowerPower pipeline, specifically for the 'hello_world' pipeline. This YAML file defines the input values for the parameterized functions. ```yaml # conf/pipelines/hello_world.yml params: greeting_message: message: "Hello" target_name: name: "World" run: final_vars: - full_greeting ``` -------------------------------- ### Add Flowerpower with pixi Source: https://legout.github.io/flowerpower/-io/installation Adds the flowerpower-io package as a dependency to a project managed by pixi. ```bash pixi add flowerpower-io ``` -------------------------------- ### Create FlowerPower Pipeline using Python API Source: https://legout.github.io/flowerpower/quickstart Creates a new pipeline programmatically using the FlowerPower Python API. It loads the existing project and then utilizes the pipeline manager to create a new pipeline. ```python from flowerpower import FlowerPowerProject project = FlowerPowerProject.load('.') project.pipeline_manager.new(name='hello_world') ``` -------------------------------- ### Implement FlowerPower Pipeline with Hamilton Functions Source: https://legout.github.io/flowerpower/quickstart Implements a 'Hello World' pipeline using Hamilton functions within FlowerPower. It defines parameterized functions for greeting messages and target names, and a final function to combine them. ```python # pipelines/hello_world.py from pathlib import Path from hamilton.function_modifiers import parameterize from flowerpower.cfg.project import ProjectConfig from flowerpower.cfg.pipeline import PipelineConfig # Load project and pipeline configurations separately project_cfg = ProjectConfig.load(name="hello-flowerpower") pipeline_cfg = PipelineConfig.load(name="hello_world") PARAMS = pipeline_cfg.params # Access params from pipeline config @parameterize(**PARAMS.get("greeting_message", {})) def greeting_message(message: str) -> str: return f"{message}," @parameterize(**PARAMS.target_name) def target_name(name: str) -> str: return f"{name}!" def full_greeting(greeting_message: str, target_name: str) -> str: """Combines the greeting and target.""" print(f"Executing pipeline: {greeting_message} {target_name}") return f"{greeting_message} {target_name}" ``` -------------------------------- ### Usage Examples Source: https://legout.github.io/flowerpower/-io/api Examples demonstrating basic file, database, and metadata operations. ```APIDOC ## Usage Examples ### Basic File Operations ```python 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 ```python 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 ```python from flowerpower_io.metadata import get_dataframe_metadata # Get metadata from DataFrame metadata = get_dataframe_metadata(df) print(metadata) ``` ``` -------------------------------- ### Install FlowerPower with uv pip Source: https://legout.github.io/flowerpower/installation This command installs the core FlowerPower library using the `uv pip` package manager. This is the recommended method for installation. ```shell uv pip install flowerpower ``` -------------------------------- ### Create FlowerPower Pipeline using CLI Source: https://legout.github.io/flowerpower/quickstart Creates a new pipeline within a FlowerPower project using the CLI. This command generates the necessary files for the pipeline definition. ```bash flowerpower pipeline new hello_world ``` -------------------------------- ### Run FlowerPower Pipeline using Python API Source: https://legout.github.io/flowerpower/quickstart Executes a FlowerPower pipeline programmatically using the Python API. It loads the project and then calls the `run` method on the specified pipeline, printing the result. ```python from flowerpower import FlowerPowerProject project = FlowerPowerProject.load('.') result = project.run('hello_world') print(result) ``` -------------------------------- ### Install FlowerPower with pip Source: https://legout.github.io/flowerpower/installation This command installs the core FlowerPower library using the standard `pip` package manager. This serves as an alternative to `uv pip`. ```shell pip install flowerpower ``` -------------------------------- ### Execute Pipeline with Direct RunConfig - Python Source: https://legout.github.io/flowerpower/quickstart This snippet demonstrates how to execute a 'hello_world' pipeline using the RunConfig class directly. It allows specifying custom input variables, desired final variables, and the log level for the execution. The RunConfig object is passed to the project.run method for detailed control over the pipeline run. ```python from flowerpower import FlowerPowerProject from flowerpower.cfg.pipeline.run import RunConfig project = FlowerPowerProject.load('.') # Create a configuration with custom parameters config = RunConfig( inputs={"greeting_message": "Hi", "target_name": "FlowerPower"}, final_vars=["full_greeting"], log_level="DEBUG" ) result = project.run('hello_world', run_config=config) print(result) ``` -------------------------------- ### Common Patterns Source: https://legout.github.io/flowerpower/-io/api Examples illustrating common usage patterns like reading multiple files and partitioning data. ```APIDOC ## Common Patterns ### Reading Multiple Files ```python from flowerpower_io import ParquetLoader # Load multiple Parquet files loader = ParquetLoader("data/*.parquet") df = loader.to_polars() ``` ### Writing with Partitioning ```python from flowerpower_io import ParquetSaver # Save with partitioning saver = ParquetSaver( path="output/", partition_by="category", compression="zstd" ) saver.write(df) ``` ### Database Connection Management ```python 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() ``` ``` -------------------------------- ### Install Dependencies with uv Source: https://legout.github.io/flowerpower/-io/contributing Sets up a virtual environment and installs all project dependencies, including development and optional extras, using the 'uv' package manager. ```bash uv venv uv pip install -e ".[all]" ``` -------------------------------- ### Install Dependencies with pixi Source: https://legout.github.io/flowerpower/-io/contributing Installs all project dependencies using the 'pixi' package manager. This command should be run after cloning the repository. ```bash pixi install ``` -------------------------------- ### Execute Pipeline Mixing RunConfig and Individual Parameters - Python Source: https://legout.github.io/flowerpower/quickstart This snippet illustrates how to run a pipeline using a base RunConfig while overriding specific parameters with individual arguments. In this scenario, the inputs provided directly to the project.run method take precedence over those defined in the base configuration, offering flexibility in parameter management. ```python from flowerpower import FlowerPowerProject from flowerpower.cfg.pipeline.builder import RunConfigBuilder project = FlowerPowerProject.load('.') # Create a base configuration base_config = RunConfigBuilder().with_log_level("INFO").build() # Run with base config but override specific parameters result = project.run( 'hello_world', run_config=base_config, inputs={"greeting_message": "Greetings", "target_name": "Universe"} ) print(result) ``` -------------------------------- ### Create Virtual Environment with uv Source: https://legout.github.io/flowerpower/installation This command creates a virtual environment using `uv`. It is highly recommended to install FlowerPower within a virtual environment to avoid package conflicts. ```shell uv venv source .venv/bin/activate ``` -------------------------------- ### Complex Pipeline Configuration Example Source: https://legout.github.io/flowerpower/api/runconfig Illustrates building a highly customized pipeline configuration using `RunConfigBuilder`. This example includes setting inputs, final variables, configuration options, caching, executor and adapter settings, log level, retry policies, and both success and failure callbacks. ```python from flowerpower.cfg.pipeline.builder import RunConfigBuilder from flowerpower.pipeline import PipelineManager def success_handler(result): print(f"Pipeline succeeded: {result}") def failure_handler(error): print(f"Pipeline failed: {error}") # Build a complex configuration config = ( RunConfigBuilder() .with_inputs({"data_date": "2025-01-01", "batch_size": 32}) .with_final_vars(["model", "metrics", "predictions"]) .with_config({"model": "LogisticRegression", "params": {"C": 1.0}}) .with_cache({"recompute": ["preprocessing"]}) .with_executor_config({"type": "threadpool", "max_workers": 4}) .with_adapter_config({"opentelemetry": True}) .with_pipeline_adapter_config({"tracker": {"project_id": "123"}}) .with_project_adapter_config({"opentelemetry": {"host": "localhost:4317"}}) .with_log_level("DEBUG") .with_retry_config(max_retries=3, retry_delay=1.0) .with_success_callback(success_handler) .with_failure_callback(failure_handler) .build() ) manager = PipelineManager() result = manager.run("ml_pipeline", run_config=config) ``` -------------------------------- ### Basic Pipeline Usage Examples Source: https://legout.github.io/flowerpower/api/runconfig Demonstrates two ways to run a pipeline: directly using a `RunConfig` object, and using a `RunConfigBuilder` to construct the configuration before running. Both methods achieve the same outcome of executing a pipeline with specified parameters. ```python from flowerpower.cfg.pipeline.run import RunConfig from flowerpower.cfg.pipeline.builder import RunConfigBuilder from flowerpower.pipeline import PipelineManager # Using RunConfig directly config = RunConfig( inputs={"data_date": "2025-01-01"}, final_vars=["model", "metrics"], log_level="DEBUG" ) manager = PipelineManager() result = manager.run("my_pipeline", run_config=config) # Using RunConfigBuilder config = ( RunConfigBuilder() .with_inputs({"data_date": "2025-01-01"}) .with_final_vars(["model", "metrics"]) .with_log_level("DEBUG") .build() ) result = manager.run("my_pipeline", run_config=config) ``` -------------------------------- ### Initializing a New FlowerPower Project in Python Source: https://legout.github.io/flowerpower/api/flowerpowerproject Demonstrates how to initialize a new FlowerPower project using the `new` class method. Examples include creating a project in the current directory and initializing a project with a specific name. The `new` method returns a `FlowerPowerProject` instance and can optionally overwrite existing projects. ```python from flowerpower import FlowerPowerProject # Initialize a new project in the current directory project = FlowerPowerProject.new() # Initialize a new project with a specific name project = FlowerPowerProject.new(name="my-new-project") ``` -------------------------------- ### Loading an Existing FlowerPower Project in Python Source: https://legout.github.io/flowerpower/api/flowerpowerproject Provides examples for loading an existing FlowerPower project. It shows how to load a project from the current directory or a specified path. The `load` method returns a `FlowerPowerProject` instance if the project exists, otherwise it returns `None`. ```python from flowerpower import FlowerPowerProject # Load a project from the current directory project = FlowerPowerProject.load(".") # Load a project from a specific path project = FlowerPowerProject.load("/path/to/my/project") ``` -------------------------------- ### Load FlowerPower Project using create_project Source: https://legout.github.io/flowerpower/api/create_project Demonstrates how to load an existing FlowerPower project using the `create_project` function. It also shows an example of attempting to load a non-existent project, which results in a `FileNotFoundError`. This function relies on the `flowerpower` library. ```python from flowerpower import create_project # Load an existing project project = create_project(base_dir=".") # Attempt to load a non-existent project (will raise FileNotFoundError) try: project = create_project(base_dir="./non_existent_project") except FileNotFoundError as e: print(e) ``` -------------------------------- ### Install Dependencies with uv Source: https://legout.github.io/flowerpower/contributing Installs the project's base dependencies along with development and test dependencies using uv. The '-e' flag installs the package in editable mode. ```shell uv pip install -e ".[dev,test]" ``` -------------------------------- ### Install Optional Dependencies with uv Source: https://legout.github.io/flowerpower/contributing Installs optional dependencies for specific features like 'mqtt' or 'redis' in addition to the development and test dependencies. The '-e' flag installs the package in editable mode. ```shell uv pip install -e ".[dev,test,mqtt,redis]" ``` -------------------------------- ### GET /websites/legout_github_io_flowerpower/get_summary Source: https://legout.github.io/flowerpower/api/registry Retrieves a detailed summary of pipeline configurations and code. Supports filtering by specific pipeline names and inclusion of configuration, code, and project details. ```APIDOC ## GET /websites/legout_github_io_flowerpower/get_summary ### Description Get a detailed summary of pipeline(s) configuration and code. ### Method GET ### Endpoint /websites/legout_github_io_flowerpower/get_summary ### Parameters #### Query Parameters - **name** (str) - Optional - Specific pipeline to summarize. If None, summarizes all. - **cfg** (bool) - Optional - Include pipeline configuration details. Default True. - **code** (bool) - Optional - Include pipeline module code. Default True. - **project** (bool) - Optional - Include project configuration. Default True. ### Response #### Success Response (200) - **pipelines** (dict[str, dict | str]) - Nested dictionary containing requested summaries. #### Response Example ```json { "pipelines": { "data_pipeline": { "cfg": { "schedule": { "enabled": true } } } } } ``` ``` -------------------------------- ### Load JSON Data with Metadata Source: https://legout.github.io/flowerpower/-io/examples Shows how to load data from a JSON file into a Pandas DataFrame and retrieve associated metadata using flowerpower-io's JsonFileReader. Requires Pandas and flowerpower-io. ```python from flowerpower_io.loader import JsonFileReader import pandas as pd import os json_file = "user_profiles.json" profiles_content = ''' \ [ {"user_id": 1, "username": "alpha", "status": "active"}, {"user_id": 2, "username": "beta", "status": "inactive"} ] ''' with open(json_file, "w") as f: f.write(profiles_content) json_reader = JsonFileReader(path=json_file) df_profiles, metadata = json_reader.to_pandas(metadata=True) print("User Profiles Data:") print(df_profiles) print("\nMetadata retrieved:") print(metadata) # Clean up os.remove(json_file) ``` -------------------------------- ### Parquet Operations and Data Conversion with Polars and PyArrow Source: https://legout.github.io/flowerpower/-io/examples Illustrates reading a Parquet file into a Polars DataFrame, writing a Polars DataFrame to Parquet, and converting between Polars DataFrames and PyArrow Tables using flowerpower-io. Requires Polars, PyArrow, and flowerpower-io. ```python import polars as pl import pyarrow as pa from flowerpower_io.loader import ParquetFileReader from flowerpower_io.saver import ParquetFileWriter import os # Create a dummy Parquet file for demonstration data_to_parquet = pl.DataFrame({ "product": ["A", "B", "C"], "price": [1.99, 0.50, 2.75] }) temp_parquet_path = "temp_products.parquet" data_to_parquet.write_parquet(temp_parquet_path) # Read from Parquet into Polars DataFrame parquet_reader = ParquetFileReader(path=temp_parquet_path) df_polars = parquet_reader.to_polars() print("Data read from temp_products.parquet (Polars DataFrame):") print(df_polars) # Convert Polars DataFrame to PyArrow Table arrow_table = df_polars.to_arrow() print("\nConverted to PyArrow Table:") print(arrow_table) # Write PyArrow Table to a new Parquet file output_parquet_path = "new_products.parquet" parquet_writer = ParquetFileWriter(path=output_parquet_path) parquet_writer.write(data=arrow_table) print(f"\nPyArrow Table written to {output_parquet_path}") # Clean up os.remove(temp_parquet_path) os.remove(output_parquet_path) ``` -------------------------------- ### Create a new flowerpower pipeline Source: https://legout.github.io/flowerpower/api/cli_pipeline Initializes a new pipeline structure, including necessary directories, configuration files, and a skeleton module. This command streamlines the setup process for new pipelines. It requires a name for the pipeline and can optionally specify a base directory for creation and whether to overwrite existing files. Dependencies include the `flowerpower` CLI tool. ```bash # Create a pipeline with a default name $ pipeline new my_new_pipeline # Create a pipeline, overwriting if it exists $ pipeline new my_new_pipeline --overwrite # Create a pipeline in a specific directory $ pipeline new my_new_pipeline --base-dir /path/to/project ``` -------------------------------- ### Read and Write CSV Files with Pandas Source: https://legout.github.io/flowerpower/-io/examples Demonstrates reading data from a CSV file into a Pandas DataFrame and writing it back to another CSV file using flowerpower-io's CSVFileReader and CSVFileWriter. Requires Pandas and flowerpower-io. ```python import pandas as pd from flowerpower_io.loader import CSVFileReader from flowerpower_io.saver import CSVFileWriter import os # Create a dummy CSV file for demonstration sample_csv_content = """ id,name,value 1,apple,10 2,banana,20 3,orange,15 """ with open("sample.csv", "w") as f: f.write(sample_csv_content) # Read from CSV csv_reader = CSVFileReader(path="sample.csv") df_from_csv = csv_reader.to_pandas() print("Data read from sample.csv:") print(df_from_csv) # Write to CSV output_csv_path = "output.csv" csv_writer = CSVFileWriter(path=output_csv_path) csv_writer.write(data=df_from_csv) print(f"\nData written to {output_csv_path}") # Clean up os.remove("sample.csv") os.remove(output_csv_path) ``` -------------------------------- ### Get Pipeline Summary Source: https://legout.github.io/flowerpower/api/registry Retrieves a detailed summary of pipeline configurations and code. It can summarize all pipelines or a specific one, with options to include configuration, module code, and project configuration. Returns a nested dictionary. ```python get_summary(self, name: str | None = None, cfg: bool = True, code: bool = True, project: bool = True) -> dict[str, dict | str] ``` ```python summary = registry.get_summary("data_pipeline") print(summary["pipelines"]["data_pipeline"]["cfg"]["schedule"]["enabled"]) ``` -------------------------------- ### Initialize RunConfigBuilder (Python) Source: https://legout.github.io/flowerpower/api/runconfig Initializes a new RunConfigBuilder instance. This is the starting point for constructing a RunConfig object using a fluent interface. It sets up the builder with default values. ```python from flowerpower.cfg.pipeline.builder import RunConfigBuilder builder = RunConfigBuilder() ``` -------------------------------- ### SQLite Database Interaction with Pandas Source: https://legout.github.io/flowerpower/-io/examples Demonstrates writing a Pandas DataFrame to a SQLite database and reading data back using a custom SQL query with flowerpower-io's SQLiteWriter and SQLiteReader. Requires Pandas and flowerpower-io. ```python import pandas as pd from flowerpower_io.saver import SQLiteWriter from flowerpower_io.loader import SQLiteReader import os db_file = "my_database.db" table_name = "sales_data" # Create a Pandas DataFrame sales_data = pd.DataFrame({ "region": ["East", "West", "North", "South"], "sales": [1000, 1500, 1200, 900], "quarter": [1, 1, 2, 2] }) # Write to SQLite sqlite_writer = SQLiteWriter(path=db_file, table_name=table_name) sqlite_writer.write(data=sales_data, if_exists="replace") # Overwrite if table exists print(f"Data written to SQLite database '{db_file}' in table '{table_name}'.") # Read from SQLite with a custom query sqlite_reader = SQLiteReader(path=db_file) query = f"SELECT region, SUM(sales) as total_sales FROM {table_name} GROUP BY region ORDER BY total_sales DESC" df_query_result = sqlite_reader.to_pandas(query=query) print("\nTotal sales by region (from SQLite query):") print(df_query_result) # Clean up os.remove(db_file) ``` -------------------------------- ### Get Pipeline Instance Source: https://legout.github.io/flowerpower/api/registry Retrieves a fully-formed Pipeline object by loading its configuration and module, then injecting project context. It can optionally reload data from disk. Handles potential errors like missing files or import issues. ```python from flowerpower import FlowerPowerProject project = FlowerPowerProject.load(".") registry = project.pipeline_manager.registry pipeline = registry.get_pipeline("my_pipeline", project) ``` -------------------------------- ### Show Pipeline Summary Source: https://legout.github.io/flowerpower/api/cli_pipeline Provides a summary of one or all pipelines, including configuration, code details, and project context. The output can be directed to a file and can be generated in HTML or SVG formats. Users can specify a pipeline name to get a summary for a particular pipeline or omit it for an overview of all pipelines. ```bash $ pipeline show-summary # Show summary for a specific pipeline $ pipeline show-summary --name my_pipeline # Show only configuration information $ pipeline show-summary --name my_pipeline --cfg --no-code --no-project # Generate HTML report $ pipeline show-summary --to-html --output-file pipeline_report.html ``` -------------------------------- ### Show Available Pipelines Source: https://legout.github.io/flowerpower/api/cli_pipeline Lists all pipelines available within the project. The output format can be customized to 'table', 'json', or 'yaml'. This command helps in getting an overview of the project's pipelines and can optionally specify a base directory to scan for pipelines. ```bash $ pipeline show-pipelines # Output in JSON format $ pipeline show-pipelines --format json # List pipelines from a specific directory $ pipeline show-pipelines --base-dir /path/to/project ``` -------------------------------- ### Check Python Version Source: https://legout.github.io/flowerpower/installation This command checks the installed Python version. It is a prerequisite for installing FlowerPower, which requires Python 3.8 or higher. ```shell python --version ``` -------------------------------- ### Initialize New FlowerPower Project (FlowerPower CLI) Source: https://legout.github.io/flowerpower/cli Initializes a new FlowerPower project. Allows specifying the project name and the base directory for creation. Supports custom storage options and logging level. ```bash # Initialize project flowerpower init --name my_project ``` -------------------------------- ### Load, Access, and Save Configuration with Config Source: https://legout.github.io/flowerpower/api/configuration Shows how to initialize the main Config class, access project and pipeline settings, load configurations from a specified directory, and save the configuration. ```python from flowerpower.cfg import Config # Load default configuration config = Config() # Access project and pipeline settings print(config.project.name) print(config.pipeline.name) # Load configuration from directory config = Config.load(base_dir="my_project", name="project1", pipeline_name="data-pipeline") # Save configuration config.save(project=True, pipeline=True) ``` -------------------------------- ### Initialize Project API Source: https://legout.github.io/flowerpower/api/initialize_project Initializes a new FlowerPower project with specified configurations. ```APIDOC ## POST /initialize_project ### Description Initializes a new FlowerPower project. This function wraps `FlowerPowerProject.new()` for convenient top-level access. ### Method POST ### Endpoint /initialize_project ### Parameters #### Query Parameters - **name** (str) - Optional - The name of the project. Defaults to the current directory name. - **base_dir** (str) - Optional - The base directory where the project will be created. Defaults to the current working directory. - **storage_options** (dict | BaseStorageOptions) - Optional - Storage options for the filesystem. Defaults to an empty dictionary. - **fs** (AbstractFileSystem) - Optional - An instance of AbstractFileSystem to use for file operations. - **hooks_dir** (str) - Optional - The directory where the project hooks will be stored. Defaults to `settings.HOOKS_DIR`. - **log_level** (str) - Optional - The logging level to set for the project. If None, it uses the default log level. ### Request Example ```json { "name": "my-new-project", "base_dir": "/path/to/projects", "storage_options": {}, "log_level": "DEBUG" } ``` ### Response #### Success Response (200) - **FlowerPowerProject** (object) - A `FlowerPowerProject` instance initialized with the new project. #### Response Example ```json { "project_name": "my-new-project", "project_path": "/path/to/projects/my-new-project" } ``` ### Error Handling - **FileExistsError**: Raised if the project already exists at the specified base directory. ``` -------------------------------- ### FlowerPowerProject New API Source: https://legout.github.io/flowerpower/api/flowerpowerproject Initializes a new FlowerPower project. Can specify project name, base directory, and overwrite behavior. ```APIDOC ## FlowerPowerProject.new ### Description Initialize a new FlowerPower project. ### Method `classmethod` ### Endpoint N/A (Class Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters Table | Parameter | Type | Description | Default | |---|---|---|---| | `name` | `str | None` | The name of the project. If `None`, it defaults to the current directory name. | `None` | | `base_dir` | `str | None` | The base directory where the project will be created. If `None`, it defaults to the current working directory. | `None` | | `storage_options` | `dict | BaseStorageOptions | None` | Storage options for the filesystem. | `{}` | | `fs` | `AbstractFileSystem | None` | An instance of `AbstractFileSystem` to use for file operations. If None, uses the `get_filesystem` helper. | `None` | | `hooks_dir` | `str` | The directory where the project hooks will be stored. | `settings.HOOKS_DIR` | | `log_level` | `str | None` | The logging level to set for the project. If `None`, it uses the default log level. | `None` | | `overwrite` | `bool` | Whether to overwrite an existing project at the specified base directory. | `False` | ### Returns `FlowerPowerProject` - An instance of `FlowerPowerProject` initialized with the new project. ### Raises `FileExistsError`: If the project already exists at the specified base directory. ### Request Example ```python from flowerpower import FlowerPowerProject # Initialize a new project in the current directory project = FlowerPowerProject.new() # Initialize a new project with a specific name project = FlowerPowerProject.new(name="my-new-project") ``` ``` -------------------------------- ### FlowerPower CLI Usage Source: https://legout.github.io/flowerpower/cli General usage information for the FlowerPower CLI. Run `flowerpower --help` for a full list of commands. ```APIDOC ## FlowerPower CLI Usage ### Description The FlowerPower CLI provides command-line tools for managing projects and pipelines. It is built with Typer and accessible via the `flowerpower` command. ### Method CLI Command ### Endpoint `flowerpower [OPTIONS] COMMAND [ARGS]...` ### Parameters No specific parameters for the base command, use `--help` for options. ### Request Example ```bash flowerpower --help ``` ### Response #### Success Response Outputs help information or executes a specified command. #### Response Example ```bash Usage: flowerpower [OPTIONS] COMMAND [ARGS]... The FlowerPower CLI provides command-line tools for managing projects and pipelines. Options: --install-completion [default: False] Install completion for the specified shell. --show-completion [default: False] Show completion for the specified shell, to be copied into your .bashrc/.zshrc etc. --help Show this message and exit. Commands: pipeline Manage pipelines. ``` ``` -------------------------------- ### DuckDB Integration: Read and Write Data with flowerpower-io Source: https://legout.github.io/flowerpower/-io/advanced Demonstrates how `flowerpower-io` integrates with DuckDB for in-process analytical processing. Includes examples of reading from and writing to a DuckDB table using `DuckDBReader` and `DuckDBWriter`. ```python import duckdb import pandas as pd from flowerpower_io.loader import DuckDBReader from flowerpower_io.saver import DuckDBWriter import os # Create a dummy DuckDB file for demonstration db_path = "my_duckdb.db" conn = duckdb.connect(database=db_path, read_only=False) conn.execute("CREATE TABLE users (id INTEGER, name VARCHAR)") conn.execute("INSERT INTO users VALUES (1, 'Alice'), (2, 'Bob')") conn.close() # Read from DuckDB duckdb_reader = DuckDBReader(path=db_path, table_name="users") df_users = duckdb_reader.to_pandas() print("Users from DuckDB:") print(df_users) # Write to DuckDB new_users = pd.DataFrame({"id": [3, 4], "name": ["Charlie", "Diana"]}) duckdb_writer = DuckDBWriter(path=db_path, table_name="users") duckdb_writer.write(data=new_users, if_exists="append") # Append new users # Verify appended data conn = duckdb.connect(database=db_path, read_only=True) print("\nAll users after append:") print(conn.execute("SELECT * FROM users").fetchdf()) conn.close() # Clean up os.remove(db_path) ``` -------------------------------- ### Show Pipeline Summary (FlowerPower CLI) Source: https://legout.github.io/flowerpower/cli Displays a summary of pipelines, optionally including configuration, code, and project context. Can output to HTML or SVG, and save to a file. Accepts options for specific pipeline names, base directory, storage, and logging level. ```bash # Summary for all pipelines flowerpower pipeline show-summary # Summary for specific pipeline flowerpower pipeline show-summary --name my_pipeline --cfg --code --no-project ``` -------------------------------- ### Running ML Pipelines with Different Configurations in Python Source: https://legout.github.io/flowerpower/api/flowerpowerproject Demonstrates multiple ways to run an ML pipeline using the FlowerPowerProject class. It shows how to pass parameters individually (kwargs), use RunConfig objects, and leverage RunConfigBuilder for more complex configurations. It also illustrates how individual parameters can override settings in a RunConfig. ```python result = project.run( "ml_pipeline", inputs={"data_date": "2025-01-01"}, final_vars=["model", "metrics"] ) ``` ```python config = RunConfig( inputs={"data_date": "2025-01-01"}, final_vars=["model", "metrics"], log_level="DEBUG" ) result = project.run("ml_pipeline", run_config=config) ``` ```python config = ( RunConfigBuilder() .with_inputs({"data_date": "2025-01-01"}) .with_final_vars(["model", "metrics"]) .with_log_level("DEBUG") .with_retry_config(max_retries=3, retry_delay=1.0) .build() ) result = project.run("ml_pipeline", run_config=config) ``` ```python base_config = RunConfigBuilder().with_log_level("INFO").build() result = project.run( "ml_pipeline", run_config=base_config, inputs={"data_date": "2025-01-01"}, # Overrides inputs in base_config final_vars=["model"] # Overrides final_vars in base_config ) ``` -------------------------------- ### Read MQTT payloads using PayloadReader Source: https://legout.github.io/flowerpower/-io/api/loader Reads payloads from MQTT messages. This is a specialized loader for streaming data and requires a running MQTT broker and client setup. It takes an initialized MQTT client as input. ```python # This example is conceptual, as MQTT integration requires a running broker and client setup. # from flowerpower_io.loader import PayloadReader # from paho.mqtt.client import Client as MQTTClient # mqtt_client = MQTTClient() # # ... configure and connect mqtt_client ... # payload_reader = PayloadReader(mqtt_client=mqtt_client) # payload = payload_reader.read_payload() # print(payload) ``` -------------------------------- ### Read Parquet Data from S3 using flowerpower-io Source: https://legout.github.io/flowerpower/-io/advanced Shows how to read Parquet files directly from Amazon S3 using `ParquetFileReader` and `fsspec_utils`. Requires AWS credentials to be configured and `fsspec` with the S3 implementation installed. ```python # Example of reading from S3 (requires appropriate AWS credentials configured) # from flowerpower_io.loader import ParquetFileReader # s3_reader = ParquetFileReader( # path="s3://your-bucket/path/to/data.parquet", # storage_options={"key": "YOUR_ACCESS_KEY", "secret": "YOUR_SECRET_KEY"} # ) # df_s3 = s3_reader.to_pandas() # print("Data read from S3:") # print(df_s3.head()) ``` -------------------------------- ### Initialize FlowerPower Project (Python) Source: https://legout.github.io/flowerpower/api/initialize_project Initializes a new FlowerPower project with specified parameters. This function is a convenience wrapper for `FlowerPowerProject.new()`. It handles project naming, base directory, storage options, filesystem, hooks directory, and logging level. It raises `FileExistsError` if the project already exists. ```python from flowerpower import initialize_project # Initialize a new project project = initialize_project(name="my-new-project") # To overwrite an existing project, use `FlowerPowerProject.new(..., overwrite=True)` ``` -------------------------------- ### Create a New FlowerPower Pipeline Source: https://legout.github.io/flowerpower/cli Initializes a new pipeline project. Allows for overwriting existing pipelines. Key arguments include the pipeline name and optional base directory. ```bash # Create new pipeline flowerpower pipeline new my_pipeline # Overwrite if exists flowerpower pipeline new my_pipeline --overwrite ``` -------------------------------- ### Initialize PipelineRegistry from Filesystem Source: https://legout.github.io/flowerpower/api/registry Creates a PipelineRegistry instance by loading configuration from a base directory. It handles filesystem creation and project configuration loading. This method is suitable for initializing the registry with local or remote storage options. ```python registry = PipelineRegistry.from_filesystem("/path/to/project") registry = PipelineRegistry.from_filesystem( "s3://my-bucket/project", storage_options={"key": "ACCESS_KEY", "secret": "SECRET_KEY"} ) ``` -------------------------------- ### Direct PipelineManager Usage in Python Source: https://legout.github.io/flowerpower/advanced Shows how to directly use the PipelineManager to load, validate, and execute data pipelines. It includes initializing the manager, getting a specific pipeline from the registry, and running it with custom input data. ```python from flowerpower.pipeline import PipelineManager from flowerpower.cfg.pipeline.run import RunConfig # Initialize the manager pipeline_manager = PipelineManager() # Access the registry to load a specific pipeline pipeline = pipeline_manager.registry.get_pipeline("sales_etl") # Execute the pipeline with RunConfig result = pipeline.run(run_config=RunConfig(inputs={"input_data": "path/to/data.csv"})) print(result) ``` -------------------------------- ### Write Data to JSON Files using Python Source: https://legout.github.io/flowerpower/-io/api/saver The JsonFileWriter class handles writing data into JSON format. It takes a file path and can accept PyArrow Tables. Ensure PyArrow is installed to use this saver. ```python from flowerpower_io.saver import JsonFileWriter import pyarrow as pa table = pa.table({'col1': [1, 2], 'col2': ['A', 'B']}) json_writer = JsonFileWriter(path="output.json") json_writer.write(data=table) ``` -------------------------------- ### PipelineRegistry Initialization Source: https://legout.github.io/flowerpower/api/registry Methods for initializing a PipelineRegistry instance. ```APIDOC ## PipelineRegistry Initialization ### from_filesystem #### Description Create a PipelineRegistry from filesystem parameters. This factory method creates a complete PipelineRegistry instance by: 1. Creating the filesystem if not provided 2. Loading the ProjectConfig from the base directory 3. Initializing the registry with the loaded configuration ### Method `classmethod` ### Endpoint N/A (Class Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **base_dir** (str) - Required - The base directory path for the FlowerPower project - **fs** (AbstractFileSystem | None) - Optional - Filesystem instance. If None, will be created from base_dir - **storage_options** (dict | None) - Optional - Storage options for filesystem access ### Request Example ```python # Create registry from local directory registry = PipelineRegistry.from_filesystem("/path/to/project") # Create registry with S3 storage registry = PipelineRegistry.from_filesystem( "s3://my-bucket/project", storage_options={"key": "ACCESS_KEY", "secret": "SECRET_KEY"} ) ``` ### Response #### Success Response (200) - **PipelineRegistry** (PipelineRegistry) - A fully configured registry instance #### Response Example ```json { "registry_instance": "" } ``` ### Raises - **ValueError**: If `base_dir` is invalid or `ProjectConfig` cannot be loaded - **RuntimeError**: If filesystem creation fails ``` -------------------------------- ### Write Data to CSV Files using Python Source: https://legout.github.io/flowerpower/-io/api/saver The CSVFileWriter class is used to write data to CSV files. It requires a file path and accepts pandas DataFrames as input. Ensure pandas is installed for this functionality. ```python from flowerpower_io.saver import CSVFileWriter import pandas as pd df = pd.DataFrame({'col1': [1, 2], 'col2': ['A', 'B']}) csv_writer = CSVFileWriter(path="output.csv") csv_writer.write(data=df) ``` -------------------------------- ### Create and Load FlowerPower Project Source: https://legout.github.io/flowerpower/api/flowerpower The `FlowerPower` alias and `create_project` function are used to load existing FlowerPower projects from a specified directory. If the project does not exist, a FileNotFoundError is raised. Use `initialize_project` or `FlowerPowerProject.new()` to create new projects. ```python from flowerpower import FlowerPower, create_project # Load a project in the current directory using the alias project = FlowerPower() # Load a project in a specific directory project = create_project(base_dir="/path/to/existing/project") # Initialize a new project instead of loading from flowerpower import initialize_project project = initialize_project(name="my-data-project") ``` -------------------------------- ### Create or Load Project Source: https://legout.github.io/flowerpower/api/create_project This function loads an existing FlowerPower project or raises an error if the project does not exist. It can also be used to create a new project. ```APIDOC ## create_project ### Description Loads an existing FlowerPower project or creates a new one if it doesn't exist. ### Method POST (or GET, conceptually, as it loads existing data) ### Endpoint /websites/legout_github_io_flowerpower/create_project ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **name** (str) - Optional - The name of the project. Defaults to the current directory name. - **base_dir** (str) - Optional - The base directory where the project will be created or loaded from. Defaults to the current working directory. - **storage_options** (dict | BaseStorageOptions) - Optional - Storage options for the filesystem. - **fs** (AbstractFileSystem) - Optional - An instance of AbstractFileSystem to use for file operations. - **hooks_dir** (str) - Optional - The directory where the project hooks will be stored. ### Request Example ```json { "name": "my_project", "base_dir": ".", "storage_options": {}, "fs": null, "hooks_dir": "./hooks" } ``` ### Response #### Success Response (200) - **FlowerPowerProject** (object) - An instance of FlowerPowerProject representing the loaded or created project. #### Response Example ```json { "project_name": "my_project", "base_directory": "." } ``` ### Error Handling - **FileNotFoundError**: Raised if the project does not exist at the specified `base_dir`. ``` -------------------------------- ### Write Data to DuckDB Databases using Python Source: https://legout.github.io/flowerpower/-io/api/saver The DuckDBWriter facilitates writing data into DuckDB database files. It needs a database path and a table name, accepting Polars DataFrames. Polars must be installed for this operation. ```python from flowerpower_io.saver import DuckDBWriter import polars as pl df = pl.DataFrame({'id': [1, 2], 'product': ['Apple', 'Banana']}) duckdb_writer = DuckDBWriter(path="my_duckdb.db", table_name="products") duckdb_writer.write(data=df) ``` -------------------------------- ### FlowerPowerProject Load API Source: https://legout.github.io/flowerpower/api/flowerpowerproject Loads an existing FlowerPower project from a specified directory. Returns None if the project does not exist. ```APIDOC ## FlowerPowerProject.load ### Description Loads an existing FlowerPower project. If the project does not exist, it returns `None` and logs an error message. ### Method `classmethod` ### Endpoint N/A (Class Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters Table | Parameter | Type | Description | Default | |---|---|---|---| | `base_dir` | `str | None` | The base directory of the project. If `None`, it defaults to the current working directory. | `None` | | `storage_options` | `dict | BaseStorageOptions | None` | Storage options for the filesystem. | `{}` | | `fs` | `AbstractFileSystem | None` | An instance of `AbstractFileSystem` to use for file operations. | `None` | | `log_level` | `str | None` | The logging level to set for the project. If `None`, it uses the default log level. | `None` | ### Returns `FlowerPowerProject | None` - An instance if the project exists, otherwise `None`. ### Request Example ```python from flowerpower import FlowerPowerProject # Load a project from the current directory project = FlowerPowerProject.load(".") # Load a project from a specific path project = FlowerPowerProject.load("/path/to/my/project") ``` ```