Arrow, pydantic style
Project description
Welcome to arrowdantic
Arrowdantic is a small Python library backed by a mature Rust implementation of Apache Arrow that can interoperate with
- Parquet
- Apache Arrow and
- ODBC (databases).
For simple (but data-heavy) data engineering tasks, this package essentially replaces
pyarrow
: it supports reading from and writing to Parquet, Arrow at the same or
higher performance and higher safety (e.g. no segfaults).
Furthermore, it supports reading from and writing to ODBC compliant databases at
the same or higher performance than turbodbc
.
This package is particularly suitable for environments such as AWS Lambda - it takes 8M of disk space, compared to 82M taken by pyarrow.
Features
- declare and access Arrow-backed arrays (integers, floats, boolean, string, binary)
- read from and write to Apache Arrow IPC file
- read from and write to Apache Parquet
- read from and write to ODBC-compliant databases (e.g. postgres, mongoDB)
Examples
Use parquet
import io
import arrowdantic as ad
original_arrays = [ad.UInt32Array([1, None])]
schema = ad.Schema(
[ad.Field(f"c{i}", array.type, True) for i, array in enumerate(original_arrays)]
)
data = io.BytesIO()
with ad.ParquetFileWriter(data, schema) as writer:
writer.write(ad.Chunk(original_arrays))
data.seek(0)
reader = ad.ParquetFileReader(data)
chunk = next(reader)
assert chunk.arrays() == original_arrays
Use Arrow files
import arrowdantic as ad
original_arrays = [ad.UInt32Array([1, None])]
schema = ad.Schema(
[ad.Field(f"c{i}", array.type, True) for i, array in enumerate(original_arrays)]
)
import io
data = io.BytesIO()
with ad.ArrowFileWriter(data, schema) as writer:
writer.write(ad.Chunk(original_arrays))
data.seek(0)
reader = ad.ArrowFileReader(data)
chunk = next(reader)
assert chunk.arrays() == original_arrays
Use ODBC
import arrowdantic as ad
arrays = [ad.Int32Array([1, None]), ad.StringArray(["aa", None])]
with ad.ODBCConnector(r"Driver={SQLite3};Database=sqlite-test.db") as con:
# create an empty table with a schema
con.execute("DROP TABLE IF EXISTS example;")
con.execute("CREATE TABLE example (c1 INT, c2 TEXT);")
# insert the arrays
con.write("INSERT INTO example (c1, c2) VALUES (?, ?)", ad.Chunk(arrays))
# read the arrays
with con.execute("SELECT c1, c2 FROM example", 1024) as chunks:
assert chunks.fields() == [
ad.Field("c1", ad.DataType.int32(), True),
ad.Field("c2", ad.DataType.string(), True),
]
chunk = next(chunks)
assert chunk.arrays() == arrays
Use timezones
This package fully supports datetime and conversions between them and arrow:
import arrowdantic as ad
dt = datetime.datetime(
year=2021,
month=1,
day=1,
hour=1,
minute=1,
second=1,
microsecond=1,
tzinfo=datetime.timezone.utc,
)
a = ad.TimestampArray([dt, None])
assert (
str(a)
== 'Timestamp(Microsecond, Some("+00:00"))[2021-01-01 01:01:01.000001 +00:00, None]'
)
assert list(a) == [dt, None]
assert a.type == ad.DataType.timestamp(datetime.timezone.utc)
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 Distributions
Hashes for arrowdantic-0.2.2-pp37-pypy37_pp73-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 09ff09f25b9c4a6d9a2f8de07790ca00356a5b69176fcf1135a09c6ca774121e |
|
MD5 | 615ca41d701392d89fceab1114300e44 |
|
BLAKE2b-256 | fd82e8dcb1437a993f4b061f95769edcc46525b4eb8b7f9495e60b0e1c7e17c2 |
Hashes for arrowdantic-0.2.2-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a659aae442f8aef6d1472517b53bd8cd529ca18d8eff2a0b8ab16f77072aeb6f |
|
MD5 | 1a6117e7160b2051af42dd2d89f5d1b9 |
|
BLAKE2b-256 | a11e22fff01f8cc28cb9fc87a4076176fb274bf596492a72a70f73c27af6c526 |
Hashes for arrowdantic-0.2.2-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9336637205a88c52124a5eff74dbf1911b01e8cc7f6665b6f372ea0a4a6709e8 |
|
MD5 | 8f938f997bc70c1075eef574fc8b464e |
|
BLAKE2b-256 | 2b7895587654f65cec5c4c5853c4ed9ca06792d50f5b70be5b2451a380a797e5 |
Hashes for arrowdantic-0.2.2-cp310-cp310-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9520642ad017b9f20a5b1523d38d88dafcd1e8f04544a7eb07eea49262eda97f |
|
MD5 | 81401fde04ee1da074f78d90fd9ac132 |
|
BLAKE2b-256 | 8c9389916210c35da52f952ae1d2219e0ac5dfa9eafa934f890462d5afdcaa02 |
Hashes for arrowdantic-0.2.2-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfe25b0d66e336f54df38d3d56d5080b1729548b14d2293734ea1bf9b2317392 |
|
MD5 | e8bcaa654fc7c235703b89bafa8a8134 |
|
BLAKE2b-256 | 3741155249e8cb1a2743fc1991be51d44ef3cd277f88280d11a85a988cdcf6aa |
Hashes for arrowdantic-0.2.2-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3526fb39e1883284e81dcff9e2645fd2851c37598c78e5300b6e86618bfec015 |
|
MD5 | ebfc7ff578c01b47ea3bd5111d341ee9 |
|
BLAKE2b-256 | 778fb190891bdfbb3d9fc45d0afe9f840cfe4700560498126f5a4d548a4f0a37 |
Hashes for arrowdantic-0.2.2-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d79cdad729b8144b2347ce0c234e8acf7433abfd395501f3cd51a0b2ec782aa |
|
MD5 | dd779e8699a9f41cf6d8d3403cb5e076 |
|
BLAKE2b-256 | 54f81a023e2134e023c2128459b7ed662249caf1db895df1ba9676f2531f1f43 |
Hashes for arrowdantic-0.2.2-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dcc211b0a902d5d54ecf8237772339790bc67d048c932f372aebbf75d6878bb9 |
|
MD5 | 410de1e887d3c928a353f661f7c3451e |
|
BLAKE2b-256 | 1e5df16774eac4e0afd4c8e9cb040129d87602a76b69f59ddd3714e9b5e78f41 |
Hashes for arrowdantic-0.2.2-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bb269e197ad9c35d5d52a42c014733443abdca42778aca40e44e5e2ef7d86fc |
|
MD5 | 4c6b57faa581830da9f7623fd4c6a209 |
|
BLAKE2b-256 | 21a0b68c2423092384cc516971e39d947bd9949d8a21a2f18c8be90266d779c4 |
Hashes for arrowdantic-0.2.2-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0eb30c9cc1fa4545c48a7ae0b7ae5b53c216e3d07e5e998c2909cf1defdde31d |
|
MD5 | 8b0a589e5474359b5fec1152d0182ba4 |
|
BLAKE2b-256 | f3acf2a6a14e34bfa236fe86bb03f8a1927d08c4914789e3412d5cfa23d472e5 |
Hashes for arrowdantic-0.2.2-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be219bf8a3eb7d6f9a98e418d338da45596e65dee0ec79ef8d5c8b04cb193cd6 |
|
MD5 | c74acb3a96f7788c3a29b9e8e5974960 |
|
BLAKE2b-256 | 7567afd98ce040e8d5bfd5e7852d0fc6dc7c4c8e1d8f1f14c8701e77c8058489 |
Hashes for arrowdantic-0.2.2-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad4a8aa6e5e90fae781982b1ef269da22ab39cbadf55686e6ebe5f5ab41d8ae3 |
|
MD5 | 3a6b4c4c5aae8de9126ff6367c69299f |
|
BLAKE2b-256 | 0dbb2bf772d959d4bdbcbe6ffd6ad10c60a1bba8494d386488f04e7cf44e12eb |
Hashes for arrowdantic-0.2.2-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 693207ae5586bbac32949b18808f5fde7d7ca843646bea810c6726492b3e52e6 |
|
MD5 | 2ed0292a4c629f28d2c8c4e294d1b7a7 |
|
BLAKE2b-256 | b9a22c784b872d9413976f563c710af99992881148427daaa0e3fdb1426e36e0 |