Skip to main content

bq-airflow-dag-generator

Utility package to generate Airflow DAG from DOT language to execute BigQuery efficiently mainly for AlphaSQL.

Install

pip install bq-airflow-dag-generator

Usage

# You can set SQL_ROOT if your SQL file paths in dag.dot are not on current directory.
os.environ["SQL_ROOT"] = "/path/to/sql/root"
dagpath = "/path/to/dag.dot"
dag = generate_airflow_dag_by_dot_path(dagpath)

You can add tasks to existing DAG like

dagpath = "/path/to/dag.dot"
existing_airflow_dag
generate_airflow_dag_by_dot_path(dagpath, dag=existing_airflow_dag)

You can pass how to create Aiflow tasks like

def gen_task(sql_file_path, dag):
    sql_root = os.environ.get("SQL_ROOT")
    sql_file_path = os.path.join(sql_root, sql_file_path) if sql_root else sql_file_path
    with open(sql_file_path, "r") as f:
        query = f.read()
        task = PythonOperator(
            task_id=sql_file_path.replace("/", ""),
            python_callable=get_bigquery_callable(query),
            dag=dag,
        )
        task.doc = f"""\
# BigQuery Task Documentation: {sql_file_path}
This is automatically generated.
Query:
{query}
"""
    return task

dagpath = "/path/to/dag.dot"
dag = generate_airflow_dag_by_dot_path(dagpath, get_task_by_sql_path_and_dag=gen_task)

Test

python -m unittest tests.test_dags

Release files for bq-airflow-dag-generator 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bq-airflow-dag-generator 0.2.0
File Size Uploaded
bq-airflow-dag-generator-0.2.0.tar.gz 3.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bq-airflow-dag-generator 0.2.0
File Interpreter ABI Platform
bq_airflow_dag_generator-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 6.1 kB

Release files / bq-airflow-dag-generator-0.2.0.tar.gz

Download URL bq-airflow-dag-generator-0.2.0.tar.gz
Size 3.0 kB
Tags Source
SHA-256 checksum
How to use checksums
cafa8ae0e0d20cf1112ef001cdbb4bb2504060dd8f5fd4b198ef1b94b617324e
BLAKE2b-256 checksum
How to use checksums
90d4fba59fee0871c06455e0cdd1effdb045cb5669db78e6b2d1892e8417434f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.5 CPython/3.7.10 Darwin/20.3.0

Release files / bq_airflow_dag_generator-0.2.0-py3-none-any.whl

Download URL bq_airflow_dag_generator-0.2.0-py3-none-any.whl
Size 3.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f5e455e49724ba827df68aaaf7a44c3ab5eb30c3ca9c95f24a5d7e1622072de3
BLAKE2b-256 checksum
How to use checksums
e656bbaf886091680db1c05eadc04e0df50281c208f13df21602689b27ca7ca7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.5 CPython/3.7.10 Darwin/20.3.0

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page