MCPcopy Index your code
hub / github.com/ScrapeGraphAI/toonify / encode

Function encode

toon/encoder.py:50–81  ·  view source on GitHub ↗

Encode Python data structure to TOON format. Args: data: Python object to encode (dict or list) options: Encoding options - delimiter: ',' (default), '\t', or '|' - indent: int (default 2) - key_folding: 'off' (default) or 'safe'

(data: Any, options: Optional[Dict[str, Any]] = None)

Source from the content-addressed store, hash-verified

48
49
50def encode(data: Any, options: Optional[Dict[str, Any]] = None) -> str:
51 """
52 Encode Python data structure to TOON format.
53
54 Args:
55 data: Python object to encode (dict or list)
56 options: Encoding options
57 - delimiter: ',' (default), '\t', or '|'
58 - indent: int (default 2)
59 - key_folding: 'off' (default) or 'safe'
60 - flatten_depth: int or None
61
62 Returns:
63 TOON formatted string
64
65 Example:
66 >>> data = {'users': [{'id': 1, 'name': 'Alice'}]}
67 >>> print(encode(data))
68 users[1]{id,name}:
69 1,Alice
70 """
71 if options is None:
72 options = {}
73
74 opts = EncoderOptions(
75 delimiter=options.get('delimiter', DEFAULT_DELIMITER),
76 indent=options.get('indent', DEFAULT_INDENT),
77 key_folding=options.get('key_folding', KEY_FOLDING_OFF),
78 flatten_depth=options.get('flatten_depth')
79 )
80
81 return _encode_value(data, 0, opts)
82
83
84def _encode_value(value: Any, level: int, opts: EncoderOptions) -> str:

Callers 15

demo_basicFunction · 0.90
demo_tabularFunction · 0.90
demo_nestedFunction · 0.90
demo_delimitersFunction · 0.90
demo_key_foldingFunction · 0.90
mainFunction · 0.90
encode_pydanticFunction · 0.90
benchmark_datasetFunction · 0.90
benchmark_memoryFunction · 0.90

Calls 2

EncoderOptionsClass · 0.85
_encode_valueFunction · 0.85

Used in the wild real call sites across dependent graphs

searching dependent graphs…