Blasthttp streaming endpoint - #17
Merged
Merged
Conversation
TheTechromancer
marked this pull request as ready for review
April 30, 2026 18:39
liquidsec
approved these changes
May 1, 2026
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
request_batch_stream— an async-iterator variant ofrequest_batchthat yieldsBatchResults in completion order as each request finishes, instead of awaiting the entire batch and returning a list. A slow request no longer blocks faster peers behind it in the input list, and Python work can overlap with in-flight HTTP I/O.The existing
request_batchis unchanged.What changed
Rust
send_batch_streaminsrc/batch.rsreturningimpl Stream<Item = BatchResult>. Each request runs as its owntokio::spawn'd task and pipes results through anmpsc::unboundedchannel — so HTTP work keeps progressing while the consumer is busy iterating the previous batch (see "Throughput" below).PyBatchResultIteratorpyclass insrc/python.rswith__aiter__/__anext__.__anext__drains the underlying stream into aVec<PyBatchResult>capped at 1000 items or 200ms to amortize the Python↔Rust boundary cost. Pattern mirrorsblastdns::PyBatchIterator.merge_limitershelper extracted fromsend_batchand reused by both batch functions so the shared-vs-per-call rate-limit selection logic stays in one place.Python packaging
module-name = "blasthttp._native",python-source = "python".python/blasthttp/__init__.pyre-exports the native types and defines a thinBlastHTTPwrapper that:_native.BlastHTTPvia__getattr__(no per-method boilerplate),request_batch_streamas anasync defgenerator that unwraps each batch into individualBatchResultobjects.h2submodule is re-aliased soimport blasthttp.h2still works.Benchmark
blasthttp-python-streamandblasthttp-python-stream-200kengines toscripts/benchmark.pyfor direct comparison against the batched API.Behavior notes
request_batchis unchanged.BlastHTTP's public Python surface is otherwise the same — all native methods/getters are forwarded through__getattr__.concurrencyrequests are in-flight at any time. Rate-limit acquire happens before the semaphore, matchingsend_batch's dispatch pacing.send_batch.Test plan
cargo test --lib— 134 tests passcargo clippy --features python --all-targets -- -D warnings— cleanpytest tests/python/— 30 tests pass (existing suite unchanged)httpbin.org/delay/NforN ∈ {3,0,2,0,1}confirmed completion-order delivery (0s results land at 0.35s/1.47s while 3s is still in flight)