Arrow -> PostgreSQL encoder
Project description
pgpq
Convert PyArrow RecordBatches to Postgres' native binary format.
Usage
import psycopg
import pyarrow.dataset as ds
from pgpq import ArrowToPostgresBinaryEncoder
dataset = ds.dataset("tests/testdata/")
encoder = ArrowToPostgresBinaryEncoder(dataset.schema)
# get the expected postgres destination schema
# note that this is _not_ the same as the incoming arrow schema
# and not necessarily the schema of your permanent table
# instead it's the schema of the data that will be sent over the wire
# which for example does not have timezones on any timestamps
pg_schema = encoder.schema()
# assemble ddl for a temporary table
# it's often a good idea to bulk load into a temp table to:
# (1) Avoid indexes
# (2) Stay in-memory as long as possible
# (3) Be more flexible with types (you can't load a SMALLINT into a BIGINT column without casting)
cols = [f"\"{col['name']}\" {col['data_type']['ddl']}" for col in pg_schema["columns"]]
ddl = f"CREATE TEMP TABLE data ({','.join(cols)})"
with psycopg.connect("postgres://postgres:postgres@localhost:5432/postgres") as conn:
with conn.cursor() as cursor:
cursor.execute(ddl) # type: ignore
with cursor.copy("COPY data FROM STDIN WITH (FORMAT BINARY)") as copy:
copy.write(encoder.write_header())
for batch in dataset.to_batches():
copy.write(encoder.write_batch(batch))
copy.write(encoder.finish())
# load into your actual table, possibly doing type casts
# cursor.execute("INSERT INTO \"table\" SELECT * FROM data")
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
pgpq-0.7.1.tar.gz
(23.8 kB
view hashes)
Built Distributions
pgpq-0.7.1-cp37-abi3-win_amd64.whl
(502.0 kB
view hashes)
pgpq-0.7.1-cp37-abi3-win32.whl
(455.7 kB
view hashes)
Close
Hashes for pgpq-0.7.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b21a8fe875fe47d2f227d6bffb7b2b567e40e96930778db6e412161592b5c0b6 |
|
MD5 | 205653445ad09a6a84b21d8042859ca8 |
|
BLAKE2b-256 | 984e04dde1be1da3abf3eac9d8e29ad1fdefaa5141b92c70f5ee9d9f4a50f2e1 |
Close
Hashes for pgpq-0.7.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6ea9cc922fafea8d7fe47a0d732ac508d0c97a13126fdd9eafb3d189506f08f |
|
MD5 | a1994096a39a7f31ad0f45ddab6fcd13 |
|
BLAKE2b-256 | 9dbf3caaea5b5d53bdf7b96d7fa60ebcfa886b8abb320502540568296703a942 |
Close
Hashes for pgpq-0.7.1-pp39-pypy39_pp73-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4980905a76215070d2d930f6afbfa7af40eca2de54a7a694cab965ae30ea83b0 |
|
MD5 | cd06dfc4c54d23ce68063162a41158f9 |
|
BLAKE2b-256 | f68644d3e0979c4c663c3ac0effea3e12f63ddd11e122c7faf217a8a193f36d0 |
Close
Hashes for pgpq-0.7.1-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57988f1fc9cca48082374033b6c1e37f54db67af9c33543440503c6e4413c846 |
|
MD5 | 5dab26185305dce32f2d2a3298009e99 |
|
BLAKE2b-256 | 74bd0f0ae58f4a0c4db5bbcb4995c416897f52bdcfc50de2ac8ba5c4de600f77 |
Close
Hashes for pgpq-0.7.1-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51158f9aab7abd3ec3ca522eb66b7236566e3942b6034addd00d5bbdceb4bed5 |
|
MD5 | 64027612c7d42d2eb2f69bd4664965ff |
|
BLAKE2b-256 | fe1711c129447c4bbf8fc01ce9f6d32ed0c396b5c7e076c7c6724e8eeefb16e5 |
Close
Hashes for pgpq-0.7.1-pp38-pypy38_pp73-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4618c83f0bc8aea6d55ddc0dbefe9506e0b89430b9829876326b57bfb6e4f618 |
|
MD5 | 6eeb9942499b142edb554fcaf4220f3e |
|
BLAKE2b-256 | bb8c4a0a37eebc5bf7cd96cec28704e18c9c01ed48bd7456c7cca2d54346c9d5 |
Close
Hashes for pgpq-0.7.1-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e8fb9b61d6a894c473dd264ef462ac8f520a8e77fa8cdfbf1c8b7939566792c |
|
MD5 | 0d45c82c557775475809017f9e87ae9c |
|
BLAKE2b-256 | 91508e78e19daba0b0e6e5f29ee2163e52111903f9a7b2affb43ad11bae624df |
Close
Hashes for pgpq-0.7.1-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0df3ada044681432928d64e1a8f39e84243c6bb01b41b1d87a2883af7a6e67f9 |
|
MD5 | 5719a3842600f73910b8aa6cefa03c2e |
|
BLAKE2b-256 | c174cedaccfcd6cdee9f2e86add48278c76acab2ae7bba934a385be49c861a79 |
Close
Hashes for pgpq-0.7.1-pp37-pypy37_pp73-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd8a313b91d721e7273ed94559c2d6458015d95e0ac4fb230eec7170f6fe16e9 |
|
MD5 | 2fe95b6b6744d0f2f4fad078302fa207 |
|
BLAKE2b-256 | e98d8602c524e96822185185bc318c7c59f59402f3fc4ca018d142eefa4362f5 |
Close
Hashes for pgpq-0.7.1-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 765bd5e0854a7de2731ac58240de098f68206c4990498385d59170e59b318d73 |
|
MD5 | bc98e805f9c1c25b788f0e32fcf9d319 |
|
BLAKE2b-256 | 53fe6a02f226c3d5c12466ebb2bde7f451b171a4d79d7f3be9fb2f60e6c218ec |
Close
Hashes for pgpq-0.7.1-cp37-abi3-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db76a973604cbed4bc3767c5d45fe21c349d7a3f7d2705f165fd12405fcd604c |
|
MD5 | 0d9c0e1c93dcdfccb19467daddc87575 |
|
BLAKE2b-256 | f9744f70b82082a0a427a3b249f0dbab53ed5d149333ebee41e6e166ae18b0a2 |
Close
Hashes for pgpq-0.7.1-cp37-abi3-musllinux_1_2_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0523becb5008905b4264624433506ce2150536e1782588369c811ac03c3c841b |
|
MD5 | a75fbd9cf899e429b9e66082aa43ab6b |
|
BLAKE2b-256 | b9d32e8487e60c39a326d533c9d50297faa3c2c903c196cb27a700411eb72aeb |
Close
Hashes for pgpq-0.7.1-cp37-abi3-musllinux_1_2_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 863d3d972c68b60d843fde4fd007e080baefc50e6f64c00050037c1d5f472c9b |
|
MD5 | 6c4527add9b50ec9c16ca0c37bfbbffd |
|
BLAKE2b-256 | 8bc4df759db24e030653b6b71e1e14f29115f6018d2215ce03dd134bb95dbce9 |
Close
Hashes for pgpq-0.7.1-cp37-abi3-musllinux_1_2_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2871f192655d4231be2c317f8ae158b775d63ac7fa7a6c86d49e7d8aab710652 |
|
MD5 | 10559172d08cda22614a28323e635c20 |
|
BLAKE2b-256 | 1e6b955987684a8226de1201cb3201062c68b639fced8a8cdcf1960604a1fe1b |
Close
Hashes for pgpq-0.7.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9908a8506b6ae4c32d3ada71826f531ffb85fa192717d6f3cc0770997e36687 |
|
MD5 | 74a1f74c8c66e105ca682cf21ec5e321 |
|
BLAKE2b-256 | 61b7d0e5db06d772b1423f4905ad1f449c8afd8476109076f82ba9bb821dab3c |
Close
Hashes for pgpq-0.7.1-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb6d237e167d035a6c20ff5b68ccef164cc4285faaffd9576b94c2fe5c92335c |
|
MD5 | 041c4ae73b77fcb0e17a95ad4ff4fd6e |
|
BLAKE2b-256 | f1a077b89e2095915b05873ca5223559052f897498707634e00c8c18c296d1df |
Close
Hashes for pgpq-0.7.1-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6bc1cee7266f892dc4c781a77b244eb93e27f2c09e45de1dcb5984c0764b4fd3 |
|
MD5 | b3b619af0781eb16c2fa6a1f117dcd73 |
|
BLAKE2b-256 | 57785c94baa50b034b0c64cb705d382f1dc2d042652134756ec0546bc8eede9f |
Close
Hashes for pgpq-0.7.1-cp37-abi3-manylinux_2_17_ppc64.manylinux2014_ppc64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 318b33f3312505d77e90bdeca0f7ef1bc6ea1218b7c38adf49230829a2539e5d |
|
MD5 | ecc5035ad15d7b7b2154a578c20a72bf |
|
BLAKE2b-256 | 64a8dfacd7f7012f9d95621a319f0754b288fa57e664c185df4ca05624e6f907 |
Close
Hashes for pgpq-0.7.1-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 315763664a264d5b82aace8ce81bb4d0689c6546dd75e3cf65bebad608a3c93b |
|
MD5 | 2fac0c8979b5edd6d11877579c802e04 |
|
BLAKE2b-256 | 7d87979f6a9ed29714ff7b0614cf0bcfe1aac19e1c131b35743553728ee707dc |
Close
Hashes for pgpq-0.7.1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b6c7de05198bc0ee638930442056388657c9888ccf0b47d8a233cf9d04756bf |
|
MD5 | f6dc3b86663bc9afea914b2aa83b586d |
|
BLAKE2b-256 | e55e2eb5aaa14f6f31975644bec222d12a0d7468c8ebef262bac2722e2254224 |
Close
Hashes for pgpq-0.7.1-cp37-abi3-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77451d74079189e7f8c7425f5bfc1dc0c2310e3b17bf1c3aa343f91fc671e0ab |
|
MD5 | 1887ddbeb85ae3e870b0510ba3564db3 |
|
BLAKE2b-256 | d421bbc174dc53c1d775b2d8fc36cc7070286457b34b3cedd7962f54082b5115 |
Close
Hashes for pgpq-0.7.1-cp37-abi3-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae8ffba3735a4869179919b80207477c058988582337fc25048ab7035d465cd3 |
|
MD5 | e158ebef1680479b5deb36050605388b |
|
BLAKE2b-256 | f6f0996644fc3cc931965670808a62c32db1be82723d919edb842ba0945a9b58 |
Close
Hashes for pgpq-0.7.1-cp37-abi3-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b6dc20c830bf1c0d3743d776abba05fb9b0c56df9e9dcb2f125841aad126d93 |
|
MD5 | 223191b7cd3fbf87dcfc42e4919eaafa |
|
BLAKE2b-256 | 2d5ebe3de8c96defe03007dd0a366696fa90927132eaba94cfd5e4e26b2cc770 |