JSON Stream Rust Tokenizer

0.5.1 · active · verified Sat Apr 11

A faster tokenizer for the `json-stream` Python library, this package ports `json-stream`'s internal tokenizer to Rust using PyO3, offering a significant parsing speedup (4-10x on CPython). As of `json-stream` version 2.0+, it is automatically detected and used by default, making explicit installation or usage generally unnecessary. It targets Python versions <3.15,>=3.8 and is actively maintained.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to explicitly use the `RustTokenizer` with `json-stream`'s `load` function and how to use the convenience `load` wrapper provided by this package.

from io import StringIO
from json_stream import load as json_stream_load
from json_stream_rs_tokenizer import RustTokenizer

# Example JSON data
json_buf = StringIO('{ "a": [1,2,3,4], "b": [5,6,7] }')

# Explicitly use the Rust tokenizer with json_stream.load
d = json_stream_load(json_buf, tokenizer=RustTokenizer)

print(f"Keys: {list(d.keys())}") # Output: Keys: ['a', 'b']
for k, l in d.items():
    print(f"{k}: {' '.join(str(n) for n in l)}")
# Expected output for 'a': a: 1 2 3 4

# Alternatively, use the convenience wrapper from json_stream_rs_tokenizer
json_buf_alt = StringIO('{ "x": "hello", "y": "world" }')
from json_stream_rs_tokenizer import load as rs_load
data_alt = rs_load(json_buf_alt)
print(f"Value of x: {data_alt['x']}") # Output: Value of x: hello

view raw JSON →