airflow-postgres-csv
| Category | Badges |
|---|---|
| License | |
| PyPI | |
| CI |
Airflow operators for bulk PostgreSQL <-> CSV transfers using COPY. Supports Airflow 2.9+ and Airflow 3, with both psycopg2 and psycopg (v3) drivers.
Listed on the Apache Airflow Ecosystem page.
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="SELECT * FROM users WHERE active = %(active)s",
parameters={"active": True},
csv_file_path="/tmp/users.csv",
)
# Load CSV into a table (with truncate)
import_task = CsvToPostgresOperator(
task_id="import_users",
conn_id="my_postgres",
table_name="staging.users",
csv_file_path="/tmp/users.csv",
truncate=True,
)
SQL from file
The sql parameter supports multiple formats:
# Inline SQL
PostgresToCsvOperator(sql="SELECT * FROM users", ...)
# Relative path (loaded by Airflow from DAG folder or template_searchpath)
PostgresToCsvOperator(sql="sql/export_users.sql", ...)
# Absolute path (loaded directly)
PostgresToCsvOperator(sql="/opt/airflow/sql/export_users.sql", ...)
Gzip compression
Both operators support gzip compression for large files:
# Export to gzip
PostgresToCsvOperator(
sql="SELECT * FROM large_table",
csv_file_path="/tmp/data.csv.gz",
compression="gzip",
...
)
# Import from gzip
CsvToPostgresOperator(
csv_file_path="/tmp/data.csv.gz",
compression="gzip",
...
)
Parameters
PostgresToCsvOperator
| Parameter | Description | Default |
|---|---|---|
conn_id |
Airflow Postgres connection ID | required |
csv_file_path |
Output file path (templated) | required |
sql |
SQL query string, or path to .sql file |
required |
parameters |
Dict of query parameters, bound client-side via mogrify |
{} |
has_header |
Include CSV header row | True |
compression |
Compression format ("gzip" or None) |
None |
timeout |
Query timeout in minutes | 60 |
count_lines |
Count and log the number of lines in the CSV after writing | True |
CsvToPostgresOperator
| Parameter | Description | Default |
|---|---|---|
conn_id |
Airflow Postgres connection ID | required |
table_name |
Target table (templated, supports schema.table) |
required |
csv_file_path |
Input file path (templated) | required |
columns |
Explicit column list | None |
has_header |
CSV has header row | True |
truncate |
Truncate table before loading | False |
compression |
Compression format ("gzip" or None) |
None |
delimiter |
CSV delimiter | "," |
quote_char |
CSV quote character | '"' |
null_string |
String representing NULL | "" |
timeout |
Query timeout in minutes | 60 |
count_lines |
Count and log the number of lines in the CSV before loading | True |
Development
Running tests
Tests can be run against both supported Airflow versions using tox:
pip install tox
tox -e airflow2 # test against Airflow 2.x
tox -e airflow3 # test against Airflow 3.x
tox # run both
Each environment installs the correct Airflow and provider versions automatically — no manual dependency management needed.
Requirements
| Airflow 2 | Airflow 3 | |
|---|---|---|
apache-airflow |
>=2.9, <3.0 |
>=3.0 |
apache-airflow-providers-postgres |
>=5.0, <6.0 |
>=6.0 |
| Python | 3.10 – 3.13 | 3.10 – 3.14 |
psycopg2 vs psycopg3
Recent versions of apache-airflow-providers-postgres make PostgresHook return a
psycopg (v3) connection when psycopg and SQLAlchemy 2 are installed, and a psycopg2
connection otherwise. Both operators detect the driver automatically and work with either.
License
Apache 2.0
Metadata
Release files for airflow-postgres-csv 0.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| airflow_postgres_csv-0.4.1.tar.gz | 304.3 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| airflow_postgres_csv-0.4.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 314.8 kB
Release files / airflow_postgres_csv-0.4.1.tar.gz
| Download URL | airflow_postgres_csv-0.4.1.tar.gz |
|---|---|
| Size | 304.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4ae5702622013912e8c6e66db6472fc65ad4fd999173799fd663b3d565b66fab
|
|
BLAKE2b-256 checksum How to use checksums |
5b0cc2f28c00f689c71f22b3033361a71256d4c56f3e44d33b1327438bd17744
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.
Transparency logRelease files / airflow_postgres_csv-0.4.1-py3-none-any.whl
| Download URL | airflow_postgres_csv-0.4.1-py3-none-any.whl |
|---|---|
| Size | 10.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ac4dd62ae3e65b430848d259b092a608e7b91c649d8a9da957d234704234ead4
|
|
BLAKE2b-256 checksum How to use checksums |
71ccc38ce980c75c6dffb4a95cbf37baff19963cda1e6b872b4206ae70a290c3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.
Transparency logSecurity for airflow-postgres-csv 0.4.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for airflow_postgres_csv-0.4.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.