Skip to main content

Python3.10+ utilities to translate iterators of bytes into file-like objects

Project description

Ever wanted to stream large JSON objects with FastAPI asynchrounously? Look no more, iteriotools is the solution you've been looking for!

It provides a RawIterIO class which can wrap an iterator of bytes into a read-only file-like object.

Example

cd example

To run the example project's application:

pipenv run uvicorn --reload project:app

To demonstrate the impact of RawIterIO on streaming large JSON objects, first emulate a "liveness probe" by running the following:

while time curl --silent http://127.0.0.1:8000/health > /dev/null; do :; done

Then, while still having the probe running, emulate a few clients GET-ing some large JSON object with:

(
    trap -- 'kill 0' EXIT
    for _ in {0..31}; do
        while curl --silent http://127.0.0.1:8000/users/batched > /dev/null; do :; done &
    done
    wait
)

You should notice a significant increase in response time on the "liveness probe" (e.g. 0.003 seconds --> 25 seconds).

Now, with the version that utilizes RawIterIO to stream JSON chunk by chunk:

(
    trap -- 'kill 0' EXIT
    for _ in {0..31}; do
        while curl --silent http://127.0.0.1:8000/users/streamed > /dev/null; do :; done &
    done
    wait
)

You should still notice a significant increase in response time, but way less extreme (e.g. 0.003 seconds -> 2 seconds), and that numbers scales better with the size of the JSON object being streamed instead of being batched.

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

iteriotools-0.0.4.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

iteriotools-0.0.4-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file iteriotools-0.0.4.tar.gz.

File metadata

  • Download URL: iteriotools-0.0.4.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.12.2 CPython/3.11.7

File hashes

Hashes for iteriotools-0.0.4.tar.gz
Algorithm Hash digest
SHA256 c9ade6cb5adffca82d8bc83c4da9f930b4c43395f657d5826f30aac1b7f6b852
MD5 b0ded5c34180a1f8a8b4a8c77de1b1c4
BLAKE2b-256 c3312991f0166bf5a01e4a0a95ad433dfd00c4486ea01ab188dffa4f5660156a

See more details on using hashes here.

File details

Details for the file iteriotools-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: iteriotools-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.12.2 CPython/3.11.7

File hashes

Hashes for iteriotools-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 766167e0e2ba8a20829fcbe159b381edc00bbfc0b857fe7e2b44f890a14b8b28
MD5 b874d0f5cfadf50859818138f8a25893
BLAKE2b-256 6bdda69173dbf87aff127c84d7fd3c41b58e06a89745bfe80ad57131c6ba0e31

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page