Skip to main content

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:

  • None values
  • 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): remove None values (default True)
  • drop_empty_str (bool): remove empty strings (default True)
  • drop_whitespace_only (bool): remove strings with only whitespace (default True)
  • drop_empty_list (bool): remove empty lists (default True)
  • drop_empty_dict (bool): remove empty dicts (default True)
  • drop_empty_tuple (bool): remove empty tuples (default False)
  • drop_empty_set (bool): remove empty sets (default False)
  • preserve_keys (set[str] or list[str]): keep values for specific keys
  • preserve_paths (set[str] or list[str]): keep values for specific dotted paths

Contributing

Issues and pull requests are welcome. See CONTRIBUTING.md for local setup.

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

sqzy-0.2.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

sqzy-0.2.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file sqzy-0.2.0.tar.gz.

File metadata

  • Download URL: sqzy-0.2.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for sqzy-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b247d09e64b439c8ea66e3c8947e2a5c0d20f9a3ebcd83a1324b03a60afc85e8
MD5 1223ee9f92df8cf4aed5b60317aeb409
BLAKE2b-256 245d9544e86faf36cfb6d022ee9d802f0077205efeef59d12a8551fc4c756137

See more details on using hashes here.

File details

Details for the file sqzy-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: sqzy-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for sqzy-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2286565e54e08a0626fcebbc1979a92242e9b8c8e145dbd255531a373fc6e03d
MD5 0d7c5503c7be5450c90f9b42461020b1
BLAKE2b-256 56cf0563dfad41523e93be26c4acc8a5f1e9bee669589ee26bc9ac0d9dba9ced

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