Skip to main content

A streamlined, user-friendly JSON streaming preprocessor, crafted in Python.

Project description

streaming-json-py

codecov

import streamingjson

Welcome to streaming-json-py, a groundbreaking library designed to revolutionize the way we handle stream JSON parsing.

In an era dominated by LLMs (Large Language Models), the ability to efficiently parse JSON streams is more critical than ever. Traditionally, JSON parsing libraries have fallen short, requiring JSON data to be fully generated before any parsing can begin. streaming-json-py challenges this limitation head-on.

Key Features

  • Real-Time JSON Parsing: With streaming-json-py, you no longer need to wait for the entire JSON data to be generated. This library allows for the parsing of JSON as it is being streamed (this means JSON stream can stops at any position), significantly cutting down the time-to-first-token.
  • Seamless Integration: Designed to complement existing JSON parsing libraries, streaming-json-py preprocesses incomplete JSON strings, transforming them into valid, parseable JSON. This means you can continue using your preferred JSON library with our tool seamlessly.
  • Enhanced User Experience: By enabling real-time data processing, our library drastically reduces the wait time for end-users. Display JSON structures to users without the delay typically associated with complete JSON generation.

Example Usage

Basically, this library is used to complete fragmented JSON, making it into syntactically correct JSON. For example:

{"a": will complete to {"a":null}

and When the JSON stream continues to output as:

{"a":[tr will complete to {"a":[true]}

Do not worry about the JSON stream stopping anywhere, such as at a comma:

{"a":[true], will complete to {"a":[true]}

Escaped characters? No problem:

{"a":[true], "b": "this is unicode \u54" will complete to {"a":[true], "b": "this is unicode "}

(After the stream outputs the complete Unicode, it will then display.)

Here’s a quick example to get you started:

install from pypi:

pip install streamingjson

run example:

# init, @NOTE: We need to assign a new lexer for each JSON stream.
lexer = streamingjson.Lexer()

# append your JSON segment
lexer.append_string('{"a":')

# complete the JSON
print(lexer.complete_json()) # will print `{"a":null}`

# append more JSON segment
lexer.append_string('[tr')

# complete the JSON again
print(lexer.complete_json()) # will print `{"a":[true]}`

For more examples please see: examples

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

streamingjson-0.0.4.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

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

streamingjson-0.0.4-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: streamingjson-0.0.4.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.5

File hashes

Hashes for streamingjson-0.0.4.tar.gz
Algorithm Hash digest
SHA256 fc9fca42868f45329409ac5fa6ed3ae6fc2f4e78e4f55bb84b540ac58d555f42
MD5 450ffb0911ec028883a7f3f4e6d9fe99
BLAKE2b-256 60f88fbb79642f7dfb2029513cf07330345441369963b014a7e283a2f338a5ab

See more details on using hashes here.

File details

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

File metadata

  • Download URL: streamingjson-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.5

File hashes

Hashes for streamingjson-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 222fae47a0c2635291d3dea5500b9473c03e7650f4dfcb61d3a8c4da12dd693b
MD5 485b27e2568ffaf6f0bc65949915a847
BLAKE2b-256 29986cfa04d5366a786eb9d0038f7b4552fa17d88d4652659a69759c35a61d2a

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