Overview
The GLYPH Python SDK provides a token-efficient serialization format that is 30-50% more compact than JSON, specifically designed for AI agents and LLM applications.Installation
Install the GLYPH Python package:Quick Start
Convert JSON to GLYPH
Parse GLYPH Text
Build Values Programmatically
Module Structure
The GLYPH Python SDK is organized into several modules:Core Types (glyph.types)
- GValue: Universal value container for all GLYPH data types
- GType: Enumeration of supported types (null, bool, int, float, str, bytes, time, id, list, map, struct, sum)
- g: Shorthand constructor class for creating GValues
- field(): Helper function for creating struct fields
Parsing (glyph.parse)
- parse(): Parse GLYPH text into GValue objects
- parse_loose(): Alias for parse() with loose parsing rules
Serialization (glyph.loose)
- emit(): Convert GValue to canonical GLYPH text
- canonicalize_loose(): Full canonicalization with options
- fingerprint_loose(): Generate SHA-256 fingerprint of values
- equal_loose(): Compare values for equality
JSON Bridge (glyph.loose)
- json_to_glyph(): Convert JSON/Python data directly to GLYPH
- glyph_to_json(): Parse GLYPH text to Python/JSON
- from_json(): Convert Python values to GValue
- to_json(): Convert GValue to Python values
Common Patterns
Working with Maps
Working with Lists
Working with Structs
Handling Nulls
Error Handling
The SDK raisesTypeError when accessing values with the wrong type:
ValueError:
Type Safety
GLYPH provides runtime type checking:Performance Tips
- Reuse parsers: For bulk parsing, consider batching operations
- Use bare strings: Identifiers without special characters don’t need quotes
- Tabular mode: Lists of homogeneous maps automatically use compact tabular format
- Fingerprinting: Use
fingerprint_loose()for efficient deduplication
Next Steps
- Core Types - Detailed GValue and type system reference
- Parsing - Complete parsing API documentation
- JSON Bridge - JSON conversion and interop