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 fileCsvToPostgresOperator— 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
828d5c7878d65b1484abe6bf7003d8cefba5951cda461e3b01ecc4c862d4b424
|
|
| MD5 |
094be5c05cebfd659092829aeb942b17
|
|
| BLAKE2b-256 |
9ecedb06f5d79a5a070ad03d94450da07166474a9090856d02f53c1da5df01b8
|
Provenance
The following attestation bundles were made for airflow_postgres_csv-0.1.0.tar.gz:
Publisher:
publish.yml on Redevil10/airflow-postgres-csv
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
airflow_postgres_csv-0.1.0.tar.gz -
Subject digest:
828d5c7878d65b1484abe6bf7003d8cefba5951cda461e3b01ecc4c862d4b424 - Sigstore transparency entry: 926914748
- Sigstore integration time:
-
Permalink:
Redevil10/airflow-postgres-csv@1add557e318dbd08f1531e019632ea414e015236 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Redevil10
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1add557e318dbd08f1531e019632ea414e015236 -
Trigger Event:
release
-
Statement type:
File details
Details for the file airflow_postgres_csv-0.1.0-py3-none-any.whl.
File metadata
- Download URL: airflow_postgres_csv-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0ad6ba46f7e86ad770749a542d8b16eaa68904c5661a6437edf0922c8914bd0
|
|
| MD5 |
e0cd920607c94d69360eb573e013ed10
|
|
| BLAKE2b-256 |
a2824c590fbd4e8e0f8648e6d9d497118c6e4e8bbed554ba1fe767ae8dee31a6
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
airflow_postgres_csv-0.1.0-py3-none-any.whl -
Subject digest:
c0ad6ba46f7e86ad770749a542d8b16eaa68904c5661a6437edf0922c8914bd0 - Sigstore transparency entry: 926914749
- Sigstore integration time:
-
Permalink:
Redevil10/airflow-postgres-csv@1add557e318dbd08f1531e019632ea414e015236 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Redevil10
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1add557e318dbd08f1531e019632ea414e015236 -
Trigger Event:
release
-
Statement type: