API Reference8 min read•Updated July 2026
Python API Reference
Complete function signatures, ContextCompressor class, and return types.
compress() Function Signature
The primary entry point for quick prompt context reduction:
llmslim/core.py
def compress(
text: str,
target_ratio: float = 0.5,
mode: str = "auto",
detect_content: bool = True,
preserve_code: bool = True,
preserve_entities: bool = True,
) -> CompressionResult:
"""Surgically compress input prompt text while preserving key instruction fidelity.
Args:
text: Input string (prompt, RAG context, or code).
target_ratio: Target proportion of tokens to retain (e.g., 0.5 = 50% retained).
mode: Compression mode ("auto", "markdown", "json", "xml", "code", "chat").
detect_content: Auto-detect format type automatically.
preserve_code: Shield syntax, functions, and formatting in code blocks.
preserve_entities: Protect proper nouns, numbers, and technical terms.
Returns:
CompressionResult object with telemetry metrics and compressed text.
"""Frequently Asked Questions
What object is returned by compress()?
A CompressionResult instance containing compressed_text, original_tokens, compressed_tokens, savings_percent, and detailed execution metrics.