Fast random access to JSONL via a byte-count lookup cache (.bcl)
Project description
fastjsonlreader
Disclaimer: README written by GPT-5
Fast random access to JSONL files via a cached byte-count lookup index (.bcl).
JSONL (JSON Lines) is a common format where each line is a valid JSON object.
Normally, accessing the nth line requires scanning from the beginning.
fastjsonlreader builds and reuses a lightweight cache of byte offsets so you can jump directly to any line in O(1) file seek time.
🚀 Features
- Fast random access to JSON objects in large
.jsonlfiles. - Cache file (
.bcl) stores line lengths or offsets for reuse. - Command-line interface (CLI) for building caches ahead of time.
- Python API for easy integration into data pipelines.
- Works on any size JSONL file (limited only by disk size).
- Simple, dependency-free implementation (only standard library).
📦 Installation
From PyPI:
pip install fastjsonlreader
From source:
git clone https://github.com/yourname/fastjsonlreader.git
cd fastjsonlreader
pip install .
For development:
pip install -e .
🔧 Usage
CLI
You can build the index (cache file) before using it in code:
# Build the index (preferred command name)
python -m fastjsonlreader index data.jsonl
# Or using the alias:
python -m fastjsonlreader create-bcl data.jsonl
# Limit to the first N lines:
python -m fastjsonlreader index data.jsonl --num-lines 1000000
# Force rebuild even if a cache exists:
python -m fastjsonlreader index data.jsonl --force
# Show where caches are stored by default:
python -m fastjsonlreader cache-dir
Python API
from fastjsonlreader import FastJSONLReader, build_cache
# Build cache manually (optional; normally auto-generated)
build_cache("data.jsonl")
# Load reader
reader = FastJSONLReader("data.jsonl")
print(len(reader)) # number of lines in the file
print(reader[0]) # first JSON object (parsed as dict)
print(reader[12345]) # 12,346th JSON object
The reader behaves like a list:
- len → number of lines
- getitem → parsed JSON object
⚡ Performance
- The first time you use a file, fastjsonlreader scans it and writes a .bcl file with the byte lengths of each line.
- Subsequent runs load the .bcl instead of rescanning the file, saving time.
- Lookups currently require summing the line lengths before the target line. For extremely large files, an offset-based cache (storing cumulative sums directly) is recommended — planned for a future release.
📂 Cache Files
- Cache files are stored in ~/.fastjsoncache/ by default (one .bcl per JSONL file).
- You can override this with --cache-dir or when initializing the reader:
reader = FastJSONLReader("data.jsonl", cache_dir="/tmp/mycache")
📄 License
MIT License © 2025 Rafael Rivera Soto
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastjsonlreader-0.1.0.tar.gz.
File metadata
- Download URL: fastjsonlreader-0.1.0.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
589a06d6914b9179c41d09d2df23938a7e581863d54a3aaef269a5bbc8dd2340
|
|
| MD5 |
05b36b521a8fe60140c211001d79e3d6
|
|
| BLAKE2b-256 |
813cfd2d0304a58d25e54b36cba5775a87add1a88e23aa34508571903a7a1a5f
|
File details
Details for the file fastjsonlreader-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fastjsonlreader-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d48705beb2cbcf894a3589480fd394ad455d7553b31199f805933b1c7f0e455
|
|
| MD5 |
d119290e33138a3b6373b0bf2c6e024e
|
|
| BLAKE2b-256 |
28d9a1198fd3a2beb2e05f1f0435bf6d1c1b2b99094bd5bb0d69c26e4fb8e2fc
|