Compress JSON-like API responses before sending to LLMs.
Project description
Sqzy
Sqzy removes irrelevant fields from JSON-like API responses before you send them to LLMs. It drops nulls, blanks, and empty collections so the context window is used for meaningful data.
Install
pip install sqzy
Quick start
from sqzy import compress_json, compress_response
data = {
"id": 123,
"title": " ",
"summary": None,
"tags": ["python", "", None, "llm"],
"meta": {"page": 1, "next": None, "notes": ""},
}
print(compress_json(data))
# {'id': 123, 'tags': ['python', 'llm'], 'meta': {'page': 1}}
Decorator usage:
import requests
from sqzy import compress_response
@compress_response()
def fetch_user(user_id: str):
res = requests.get(f"https://api.example.com/users/{user_id}")
return res.json()
clean = fetch_user("42")
API
compress_json(data, **options) recursively removes:
Nonevalues- empty strings (including whitespace-only by default)
- empty lists and dicts
compress_response(**options) is a decorator that applies compress_json to
the return value of the wrapped function.
Options
drop_null(bool): removeNonevalues (defaultTrue)drop_empty_str(bool): remove empty strings (defaultTrue)drop_whitespace_only(bool): remove strings with only whitespace (defaultTrue)drop_empty_list(bool): remove empty lists (defaultTrue)drop_empty_dict(bool): remove empty dicts (defaultTrue)preserve_keys(set[str] or list[str]): keep values for specific keys
Contributing
Issues and pull requests are welcome. See CONTRIBUTING.md for local setup.
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 sqzy-0.1.0.tar.gz.
File metadata
- Download URL: sqzy-0.1.0.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0bd770d7395b575671fe49741ce72dde0d757681c16f09847604e4c7cfc9773
|
|
| MD5 |
549cabcff5e8dc8961d4d25ad6e497f2
|
|
| BLAKE2b-256 |
cd3336aaf65bc0594626b1009c05f2e8832f78c5c9f85fee0bac1591b45d05ef
|
File details
Details for the file sqzy-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sqzy-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29b3c97f1aab7c028c24a61633759eaadaf3fe4c73805853c12df8c7ee2d3c8b
|
|
| MD5 |
c0aac3899b6eeadfd0c4a2490386fdf6
|
|
| BLAKE2b-256 |
3c74f319a69c6eeba481112b94bf9fafb31fbcfd90a26c3c06f1630409fec8d3
|