Skip to main content

Airflow operators for PostgreSQL <-> CSV file transfers using COPY

Project description

airflow-postgres-csv

Airflow 3 operators for bulk PostgreSQL ↔ CSV transfers using COPY.

Operators

  • PostgresToCsvOperator — Run a SQL query and export results to a CSV file
  • CsvToPostgresOperator — Load a CSV file into a PostgreSQL table

Both use PostgreSQL's COPY command for maximum throughput.

Installation

pip install airflow-postgres-csv

Usage

from airflow_postgres_csv import PostgresToCsvOperator, CsvToPostgresOperator

# Export query results to CSV
export_task = PostgresToCsvOperator(
    task_id="export_users",
    conn_id="my_postgres",
    sql_query="SELECT * FROM users WHERE active = %(active)s",
    query_params={"active": True},
    csv_file_path="/tmp/users.csv",
)

# Load CSV into a table
import_task = CsvToPostgresOperator(
    task_id="import_users",
    conn_id="my_postgres",
    table_name="staging.users",
    csv_file_path="/tmp/users.csv",
)

Key parameters

PostgresToCsvOperator:

Parameter Description Default
conn_id Airflow Postgres connection ID required
csv_file_path Output file path (template-able) required
sql_query SQL to execute None
sql_file_path Path to .sql file None
query_params Dict passed to cursor.mogrify {}
has_header Include CSV header True
timeout Query timeout (minutes) 60

CsvToPostgresOperator:

Parameter Description Default
conn_id Airflow Postgres connection ID required
table_name Target table (template-able, supports schema.table) required
csv_file_path Input file path (template-able) required
columns Explicit column list None
has_header CSV has header row True
delimiter CSV delimiter ","
quote_char CSV quote character '"'
null_string String representing NULL ""
timeout Query timeout (minutes) 60

Requirements

  • Apache Airflow >= 3.0.0
  • apache-airflow-providers-postgres >= 6.0.0

License

MIT

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

airflow_postgres_csv-0.1.0.tar.gz (180.2 kB view details)

Uploaded Source

Built Distribution

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

airflow_postgres_csv-0.1.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file airflow_postgres_csv-0.1.0.tar.gz.

File metadata

  • Download URL: airflow_postgres_csv-0.1.0.tar.gz
  • Upload date:
  • Size: 180.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for airflow_postgres_csv-0.1.0.tar.gz
Algorithm Hash digest
SHA256 828d5c7878d65b1484abe6bf7003d8cefba5951cda461e3b01ecc4c862d4b424
MD5 094be5c05cebfd659092829aeb942b17
BLAKE2b-256 9ecedb06f5d79a5a070ad03d94450da07166474a9090856d02f53c1da5df01b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for airflow_postgres_csv-0.1.0.tar.gz:

Publisher: publish.yml on Redevil10/airflow-postgres-csv

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

File details

Details for the file airflow_postgres_csv-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for airflow_postgres_csv-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c0ad6ba46f7e86ad770749a542d8b16eaa68904c5661a6437edf0922c8914bd0
MD5 e0cd920607c94d69360eb573e013ed10
BLAKE2b-256 a2824c590fbd4e8e0f8648e6d9d497118c6e4e8bbed554ba1fe767ae8dee31a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for airflow_postgres_csv-0.1.0-py3-none-any.whl:

Publisher: publish.yml on Redevil10/airflow-postgres-csv

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