Skip to content

Commit 8a17d10

Browse files
docs: add encode_generic to README
1 parent cbf0b90 commit 8a17d10

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,36 @@ output = encode_delta(delta)
114114

115115
81.2% savings on re-queries where the pack changed slightly.
116116

117+
## Generic Encoding
118+
119+
Encode any Python value (not just graph payloads) into GCF tabular format:
120+
121+
```python
122+
from gcf import encode_generic
123+
124+
output = encode_generic({
125+
"employees": [
126+
{"id": 1, "name": "Alice", "department": "Engineering", "salary": 95000},
127+
{"id": 2, "name": "Bob", "department": "Sales", "salary": 72000},
128+
],
129+
})
130+
```
131+
132+
Output:
133+
```
134+
## employees [2]{id,name,department,salary}
135+
1|Alice|Engineering|95000
136+
2|Bob|Sales|72000
137+
```
138+
139+
Works on dicts, lists, and primitives. Lists of uniform dicts get tabular rows. Nested dicts use `## key` section headers.
140+
117141
## API
118142

119143
| Function | Description |
120144
|----------|-------------|
121-
| `encode(p: Payload) -> str` | Encode a payload to GCF text |
145+
| `encode(p: Payload) -> str` | Encode a graph payload to GCF text |
146+
| `encode_generic(data: Any) -> str` | Encode any value to GCF tabular format |
122147
| `decode(input_text: str) -> Payload` | Parse GCF text back to a Payload |
123148
| `encode_with_session(p: Payload, s: Session) -> str` | Encode with session deduplication |
124149
| `encode_delta(d: DeltaPayload) -> str` | Encode a delta (added/removed only) |

0 commit comments

Comments
 (0)