Skip to main content

A metadata-driven ETL framework

Project description

MetaWorkflows

PyPI version Python Versions License: MIT

MetaWorkflows is a Python framework designed to declaratively build and execute Extract, Transform, Load (ETL) jobs using simple and intuitive YAML configurations. It abstracts away the boilerplate code typically associated with data pipelines, allowing data engineers and analysts to focus on the logic of their data transformations.

Currently, MetaWorkflows provides robust support for Apache Spark as an execution engine, with a flexible architecture designed for future expansion to other engines and connectors.

Table of Contents

Key Features & Benefits

  • Declarative ETL: Define complex data pipelines using human-readable YAML.
  • Reduced Boilerplate: Focus on what data operations to perform, not how to code them from scratch.
  • Engine Agnostic (Design): While currently focused on Spark, the framework is designed to be extensible to other processing engines (e.g., Pandas, Dask).
  • Connector Abstraction: Easily read from and write to various data sources (databases, file systems, object storage) by defining connections separately.
  • Reproducibility & Versioning: YAML configurations can be version-controlled alongside your code, ensuring reproducible ETL jobs.
  • Rapid Development: Quickly prototype and iterate on ETL workflows.
  • Spark Integration: Leverage the power of Apache Spark for distributed data processing.
  • SQL Transformations: Define complex transformations using familiar SQL syntax directly within your Spark jobs.
  • Others: No need to known python, spark :D

Prerequisites

  • Python 3.10+
  • pip for installing packages
  • Apache Spark: If using the spark engine, you need a working Spark installation (local mode or a cluster). Ensure SPARK_HOME is set and Spark binaries are in your PATH, or that your Python environment is configured to find PySpark.
  • Java Development Kit (JDK): Required by Spark.
  • Database Drivers: If connecting to databases (e.g., PostgreSQL, MySQL), ensure the necessary JDBC driver JARs are accessible to Spark. You can specify them in the spark.jars.packages configuration within your job YAML.

Installation

Install MetaWorkflows using pip:

pip install metaworkflows

Quick Start

Let's walk through setting up and running a simple ETL job.

1. Project Structure

Organize your project as follows:

my_etl_project/
├── connections/
│   └── connections.yaml      # Database, filesystem, etc. credentials and settings
├── jobs/
│   └── etl/
│       └── spark_job.yaml    # Your ETL job definition
└── main.py           # Your Python script to execute the job

2. Define Connections

Use connection file (DEPRECATED)

Create a connections/connections.yaml file. This file stores connection details for your data sources and sinks, keeping them separate from your job logic.

Example connections/connections.yaml:
connections:
  my_postgres_db:
    type: postgresql # or jdbc for generic
    host: "localhost"
    port: 5432
    database: "mydatabase"
    user: "user"
    password: "password" # Consider using environment variables or a secrets manager for production
    # driver: "org.postgresql.Driver" # Usually auto-detected for known types

  my_mysql_db:
    type: mysql # or jdbc
    host: "localhost"
    port: 3306
    database: "magedb"
    user: "user"
    password: "password"
    # driver: "com.mysql.cj.jdbc.Driver"

  local_filesystem:
    type: file_system # A conceptual type, actual path used in write step
    base_path: "/tmp/metaworkflows_output/" # Optional base path

Note: For production, always use a secure way to manage secrets (e.g., environment variables, HashiCorp Vault, AWS Secrets Manager).

Use Secret Manager

#TODO

3. Define Your Job

Create your job definition file, for example, jobs/etl/spark_job.yaml (using the example you provided):

# jobs/etl/spark_job.yaml
job_name: process_sales_data_spark
description: "ETL job to process sales data using Spark, transform with SQL, and write to object storage."
version: "1.0"

engine:
  type: spark
  config: # Spark specific configurations
    spark.app.name: "SalesDataProcessing"
    spark.master: "local[*]" # Or your cluster URL yarn, mesos, etc.
    spark.executor.memory: "1g"
    spark.driver.memory: "1g"
    # Ensure necessary JDBC drivers are available for Spark
    spark.jars.packages: "org.postgresql:postgresql:42.7.5,com.mysql:mysql-connector-j:8.3.0"

steps:
  - step_name: read_candidates_data
    type: read
    connector: database
    connection_ref: "my_postgres_db" # Reference to connections.yaml
    options:
      query: "SELECT id, name, phone, date, address, city, region FROM public.candidates WHERE city <> 'Hạ Long'"
    output_alias: "df_candidates"

  - step_name: read_emp_banks
    type: read
    connector: database
    connection_ref: "my_mysql_db"
    options:
      query: "SELECT id, id_emp, bank_acc, bank_name FROM mageai.emp_banks"
    output_alias: "df_emp_banks"

  - step_name: transform_candidates_full
    type: transform
    engine_specific:
      spark_sql:
        temp_views:
          - alias: candidates
            dataframe: "df_candidates"
          - alias: emp_banks
            dataframe: "df_emp_banks"
        query: |
          SELECT
            c.*,
            e.bank_acc,
            e.bank_name
          FROM candidates as c
          LEFT JOIN emp_banks as e
          on c.id = e.id_emp
    input_aliases: ["df_candidates", "df_emp_banks"]
    output_alias: "df_transformed_candidates_banks"

  - step_name: write_transformed_data
    type: write
    connector: file # Could also be 'object_storage' or 'database'
    connection_ref: "local_filesystem" # Refer to a connection if it provides base paths or credentials
    input_alias: "df_transformed_candidates_banks"
    options:
      path: "processed_candidates/" # Relative to local_filesystem.base_path or absolute
      format: "parquet"
      mode: "overwrite"

4. Run the Pipeline

Test job configuration file:

from metaworkflows.utils import JobValidator

print(JobValidator.validate_yaml_file("jobs/etl/your_job.yaml"))

To run an ETL job via the command line:

python -m metaworkflows.main run_job --job-path jobs/etl/your_job.yaml

Or programmatically from main file:

from metaworkflows.core.pipeline import Pipeline
from metaworkflows.core.job import Job

# Ensure your current working directory is the project root
job_definition = Job.from_yaml("jobs/etl/spark_job.yaml")
pipeline = Pipeline(job_definition)
pipeline.run()

Submit job to Dataproc GCP:

#TODO

YAML Configuration Deep Dive

Job Definition (job.yaml)

The core of MetaWorkflows is the job YAML file. It has the following main sections:

  • job_name: (string) A unique identifier for your job.
  • description: (string) A brief description of what the job does.
  • version: (string) Version of the job definition.
  • engine: (object) Defines the execution engine.
    • type: (string) The type of engine (e.g., spark).
    • config: (object) Engine-specific configurations. For Spark, these are standard Spark configurations (e.g., spark.app.name, spark.master, spark.jars.packages).
  • steps: (list) A list of steps to be executed sequentially. Each step has:
    • step_name: (string) A unique name for the step.
    • type: (string) Type of operation: read, transform, write.
    • connector: (string, for read/write types) Specifies the connector type (e.g., database, file, object_storage).
    • connection_ref: (string, for read/write types) A reference to an entry in your connections.yaml file.
    • options: (object) Connector-specific options.
      • For read (database): query or dbtable.
      • For read (file): path, format, header, inferSchema, etc.
      • For write (file): path, format, mode (overwrite, append, ignore, error).
    • output_alias: (string) A name to register the output DataFrame of this step, making it available for subsequent steps.
    • input_aliases: (list of strings, for transform/write types) Specifies which previously aliased DataFrames are inputs to this step.
    • engine_specific: (object, for transform type) Contains transformation logic specific to the chosen engine.
      • For spark_sql:
        • temp_views: (list) Defines temporary views from input DataFrames. Each item has alias (view name) and dataframe (input alias).
        • query: (string) The SQL query to execute.

More detail instruction JOB DEFINATION

Connections

1. Use connections.yaml (DEPRECATED)

This file centralizes connection configurations.

connections:
  <connection_name_1>:
    type: <connector_type> # e.g., postgresql, mysql, jdbc, s3, gcs, local_file_system
    # ... type-specific parameters (host, port, user, password, bucket, etc.) ...
  <connection_name_2>:
    # ...

Using connection_ref in your job steps allows MetaWorkflows to look up these details.

2. Use Secret Manager:

#TODO

Supported Components

(As of current version - this section should be updated as the framework evolves)

  • Engines:
    • Apache Spark
  • Connectors (for Read/Write):
    • Database:
      • PostgreSQL (via JDBC)
      • MySQL (via JDBC)
      • Generic JDBC
    • File System:
      • Local files
      • Formats: Parquet, CSV (others can be added)
    • Object Storage: (Conceptual, to be implemented - e.g., S3, GCS, Azure Blob Storage)

License

This project is licensed under the MIT License. See the LICENSE file for details.

Roadmap (Potential Future Enhancements)

  • Support for other execution engines (e.g., Pandas for smaller datasets, Dask for distributed Python)
  • Wider range of built-in connectors (e.g., Kafka, S3, Google Cloud Storage, Azure Blob Storage, APIs)
  • Schema validation and evolution capabilities
  • Parameterization of jobs (passing runtime variables)
  • Integration with orchestration tools (e.g., Apache Airflow)
  • Support for more complex transformation types beyond SQL
  • Visualization

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

metaworkflows-0.1.9.tar.gz (34.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

metaworkflows-0.1.9-py3-none-any.whl (36.7 kB view details)

Uploaded Python 3

File details

Details for the file metaworkflows-0.1.9.tar.gz.

File metadata

  • Download URL: metaworkflows-0.1.9.tar.gz
  • Upload date:
  • Size: 34.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for metaworkflows-0.1.9.tar.gz
Algorithm Hash digest
SHA256 a6ff80ec0030ccf27ef5478448181a759b565182810d32cf353556ea52ee0757
MD5 d8f9077f6a2b612837a7041e71baa8aa
BLAKE2b-256 757b52a0d84495b5cad001013fc70e5ed404615709688b77827013cf4fb3d43d

See more details on using hashes here.

Provenance

The following attestation bundles were made for metaworkflows-0.1.9.tar.gz:

Publisher: python-publish.yml on anhtuanluu/meta_workflows

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file metaworkflows-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: metaworkflows-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 36.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for metaworkflows-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 754b62409c6ce3c3b50dac5948d24bd72c66cf417b59dd044a199790441e44b2
MD5 474668e4d30ae74843676df7abacc0f7
BLAKE2b-256 edbd9295215c7385671f8cfc25a2abe3d94fd244ced31e29614edd3e58149c67

See more details on using hashes here.

Provenance

The following attestation bundles were made for metaworkflows-0.1.9-py3-none-any.whl:

Publisher: python-publish.yml on anhtuanluu/meta_workflows

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page