A SQLAlchemy PostgreSQL dialect for ADBC (Arrow Database Connectivity)
Project description
pgarrow

A SQLAlchemy PostgreSQL dialect for ADBC (Arrow Database Connectivity)
Contents
Installation
pgarrow can be installed from PyPI using pip:
pip install pgarrow
Usage
pgarrow can be used using the postgresql+pgarrow dialect when creating a SQLAlchemy engine. For example, to create an engine for a PostgreSQL database at 127.0.0.1 (localhost) on port 5432 with user postgres and password password:
engine = sa.create_engine('postgresql+pgarrow://postgres:password@127.0.0.1:5432/')
Query returning built-in Python types
To run a query that returns built-in Python types, as is typical with SQLAlchemy:
import sqlalchemy as sa
engine = sa.create_engine('postgresql+pgarrow://postgres:password@127.0.0.1:5432/')
with engine.connect() as conn:
results = conn.execute(sa.text("SELECT 1")).fetchall()
Query returning an Arrow table
To run a query that returns an Arrow table, which should be the most performant for large datasets, you must use SQLAlchemy's driver_connection to access the ADBC-level connection, create a cursor from it to run the query and fetch the table using fetch_arrow_table:
import sqlalchemy as sa
engine = sa.create_engine('postgresql+pgarrow://postgres:password@127.0.0.1:5432/')
with \
engine.connect() as conn, \
conn.connection.driver_connection.cursor() as cursor:
cursor.execute("SELECT 1 AS a, 2.0::double precision AS b, 'Hello, world!' AS c")
table = cursor.fetch_arrow_table()
Replace PostgreSQL table with an Arrow table
To insert data into the database from an Arrow table, a similar pattern must be used to use adbc_ingest:
import sqlalchemy as sa
engine = sa.create_engine('postgresql+pgarrow://postgres:password@127.0.0.1:5432/')
table = pa.Table.from_arrays([[1,], [2,], ['Hello, world!',]], schema=pa.schema([
('a', pa.int32()),
('b', pa.float64()),
('c', pa.string()),
]))
with \
engine.connect() as conn, \
conn.connection.driver_connection.cursor() as cursor:
cursor.adbc_ingest("my_table", table, mode="create")
conn.commit()
Create a table with SQLAlchemy and append an Arrow table
To create a table using SQLAlchemy, and then append an Arrow table to it:
import sqlalchemy as sa
metadata = sa.MetaData()
sa.Table(
"my_table",
metadata,
sa.Column("a", sa.INTEGER),
sa.Column("b", sa.DOUBLE_PRECISION),
sa.Column("c", sa.TEXT),
schema="public",
)
table = pa.Table.from_arrays([[1,], [2,], ['Hello, world!',]], schema=pa.schema([
('a', pa.int32()),
('b', pa.float64()),
('c', pa.string()),
]))
with \
engine.connect() as conn, \
conn.connection.driver_connection.cursor() as cursor:
metadata.create_all(conn)
cursor.adbc_ingest("my_table", table, mode="append")
conn.commit()
Compatibility
- Python >= 3.9 (tested on 3.9.0, 3.10.0, 3.11.1, 3.12.0, and 3.13.0)
- PostgreSQL >= 13.0 (tested on 13.0, 14.0, 15.0, and 16.0)
- SQLAlchemy >= 1.4.24 other than between 2.0.0 and 2.0.6 on Python < 3.13.0; and >= 1.4.24 other than between 2.0.0 and 2.0.40 on Python >=3.13.0 (tested on 1.4.24 with all supported versions of Python; tested on 2.0.7 with Python before 3.13.0; and tested on 2.0.41 with Python 3.13.0)
- PyArrow >= 15.0.0 with Python < 3.13, and PyArrow >= 18.0.0 with Python >= 3.13.0 (tested on 15.0.0, 16.0.0, 17.0.0, 18.0.0, 19.0.0, 20.0.0 with Python before 3.13.0; and 18.0.0, 19.0.0, and 20.0.0 with Python 3.13.0)
- adbc-driver-postgresql >= 1.6.0 (tested on 1.6.0)
Project details
Release history Release notifications | RSS feed
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 pgarrow-0.0.7.tar.gz.
File metadata
- Download URL: pgarrow-0.0.7.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff8798ac84664edaa77e329c2eb7123ca25b81c6beeb4a92a0d6c35728864e36
|
|
| MD5 |
3c3c8ae5180cb12e39862a08fced1adb
|
|
| BLAKE2b-256 |
ca732300564be6d31c35bee45ba156a318c41f17ce18b63ec9d93a659fca4467
|
Provenance
The following attestation bundles were made for pgarrow-0.0.7.tar.gz:
Publisher:
deploy-package-to-pypi.yaml on michalc/pgarrow
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pgarrow-0.0.7.tar.gz -
Subject digest:
ff8798ac84664edaa77e329c2eb7123ca25b81c6beeb4a92a0d6c35728864e36 - Sigstore transparency entry: 226715090
- Sigstore integration time:
-
Permalink:
michalc/pgarrow@56ab394577be7a5d9590c68ab39fe4288bb9d1f6 -
Branch / Tag:
refs/tags/v0.0.7 - Owner: https://github.com/michalc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy-package-to-pypi.yaml@56ab394577be7a5d9590c68ab39fe4288bb9d1f6 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pgarrow-0.0.7-py3-none-any.whl.
File metadata
- Download URL: pgarrow-0.0.7-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2567656bad1001a90527895b2fff462254cb52c0640d351371eac5b4220a4ee
|
|
| MD5 |
d34c3dfcb4e6fe43d978e20a25c2c091
|
|
| BLAKE2b-256 |
dcf715c33332f14f012729438dfee5cb4da16fba7f3bc4931ea424b781a2bcde
|
Provenance
The following attestation bundles were made for pgarrow-0.0.7-py3-none-any.whl:
Publisher:
deploy-package-to-pypi.yaml on michalc/pgarrow
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pgarrow-0.0.7-py3-none-any.whl -
Subject digest:
f2567656bad1001a90527895b2fff462254cb52c0640d351371eac5b4220a4ee - Sigstore transparency entry: 226715093
- Sigstore integration time:
-
Permalink:
michalc/pgarrow@56ab394577be7a5d9590c68ab39fe4288bb9d1f6 -
Branch / Tag:
refs/tags/v0.0.7 - Owner: https://github.com/michalc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy-package-to-pypi.yaml@56ab394577be7a5d9590c68ab39fe4288bb9d1f6 -
Trigger Event:
release
-
Statement type: