Package Exports¶
The package root re-exports the supported user-facing objects. Prefer these imports in application code.
http_to_arrow
¶
Public exports for the http_to_arrow package.
IPCStreamSink(schema, *, compression=None)
¶
Serialize RecordBatch objects into Arrow IPC stream byte chunks.
The schema is written into the stream header on construction; call
:meth:header_bytes to retrieve it, :meth:write_batch for each batch, and
:meth:close to emit the end-of-stream marker.
Example
sink = IPCStreamSink(schema, compression="zstd") chunks = [sink.header_bytes()] chunks.append(sink.write_batch(batch)) chunks.append(sink.close()) table = pa.ipc.open_stream(pa.BufferReader(b"".join(chunks))).read_all()
Source code in src/http_to_arrow/src/http_to_arrow/_ipc.py
closed
property
¶
Whether the stream writer has been closed.
header_bytes()
¶
Return the Arrow IPC stream header bytes captured at construction.
PyArrow may buffer the schema message until the first write_batch or
close, so this can be empty. The bytes are always emitted in stream
order, so concatenating header_bytes() with every write_batch
result and close produces a valid Arrow IPC stream.
Source code in src/http_to_arrow/src/http_to_arrow/_ipc.py
write_batch(batch)
¶
Serialize batch and return its Arrow IPC stream bytes.
Source code in src/http_to_arrow/src/http_to_arrow/_ipc.py
close()
¶
Close the writer and return the trailing end-of-stream bytes.
ArrowRecordContainer(schema=None, table=None, batch_size=128000, unknown_field_policy='drop', missing_field_policy='null', coercion_policy='coerce', case_insensitive_keys=True, eager_clear_accumulator=False, dictionary_encode=False, dictionary_cardinality_threshold=0.5, compact_on_materialize=False, batches=None)
dataclass
¶
Bases: BaseArrowRecordContainer, ArrowRecordContainerSettings
Batch incoming records into Arrow tables using an explicit or inferred schema.
Source code in src/http_to_arrow/src/http_to_arrow/main.py
batch_total_rows
property
¶
Total rows across pending batches plus the in-flight accumulator.
total_rows
property
¶
Total rows across the cached table, pending batches, and accumulator.
normalize_record(record)
¶
append(record)
¶
extend(records)
¶
flush()
¶
to_table()
¶
incremental_flush(threshold=0)
¶
Flush accumulated batches into the cached table when above threshold rows.
Unlike to_table() this is designed to be called periodically during
streaming ingestion to bound memory. When the pending batch row count
exceeds threshold, the batches are materialised into the cached table
and the batch list is cleared.
Returns True when batches were actually flushed, False otherwise.
Source code in src/http_to_arrow/src/http_to_arrow/main.py
drain_batches()
¶
Return completed pending batches and remove them from the container.
This releases ownership of every flushed RecordBatch without
touching the in-flight accumulator or the cached table. After draining,
:attr:batch_total_rows reflects only the rows still held in the
accumulator.
Returns an empty list when no batches are pending.
Source code in src/http_to_arrow/src/http_to_arrow/main.py
flush_partial()
¶
Flush the in-flight accumulator and return the resulting batch.
Unlike :meth:flush, this returns the newly created RecordBatch and
removes it from the pending batch list so a later :meth:to_table call
does not materialize it a second time. Returns None when the
accumulator holds no rows.
Source code in src/http_to_arrow/src/http_to_arrow/main.py
iter_batches()
¶
Yield completed batches one at a time, releasing each as it is yielded.
Batches are yielded in FIFO order and removed from the container as they
are produced, so memory is not retained for already-yielded batches. The
in-flight accumulator is left untouched; call :meth:flush_partial
first to emit a trailing short batch.
Source code in src/http_to_arrow/src/http_to_arrow/main.py
to_polars_frame()
¶
reset()
¶
to_arrow()
¶
to_polars()
¶
ArrowIPCStream(schema, *, batch_size=128000, queue_maxsize=4, compression=None, dictionary_encode=False, dictionary_cardinality_threshold=0.5, eager_clear_accumulator=True)
¶
Stream Arrow IPC bytes from an async row producer with backpressure.
Streaming requires an explicit schema because the Arrow IPC stream header is
written before any rows are available. Inferred-schema mode and
dictionary_encode=True are rejected because they can change batch types
after the header schema is fixed.
Example
stream = ArrowIPCStream(schema=schema, compression="zstd")
async def produce() -> None: async for page in fetch_pages(): await stream.extend(page)
async for chunk in stream.ipc_chunks(producer=produce): ... # forward chunk to the HTTP response
Source code in src/http_to_arrow/src/http_to_arrow/streaming.py
put(row)
async
¶
extend(rows)
async
¶
end()
async
¶
ipc_chunks(producer=None)
async
¶
Yield Arrow IPC stream byte chunks until the producer signals end.
When producer is provided it is run as a concurrent task and this
method signals :meth:end on its behalf, so the producer never needs to
call it. Otherwise rows must be fed from a separate task via
:meth:put/:meth:extend, and that task must call :meth:end when done.
If the producer raises, the partial stream is flushed and closed cleanly and the exception is re-raised after the trailing bytes are emitted.
Source code in src/http_to_arrow/src/http_to_arrow/streaming.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |