Token-efficient serialization for AI agents
Project description
GLYPH Python
Python implementation of the GLYPH codec.
The primary surface is still codec-first:
- parse and emit values
- JSON bridge helpers
- canonicalization and fingerprinting
- streaming validation
Higher-level agent helpers exist, but they are optional layers on top of the codec.
Install
pip install glyph-py
Quick Start
import glyph
data = {"action": "search", "query": "weather", "max_results": 10}
text = glyph.json_to_glyph(data)
print(text)
restored = glyph.glyph_to_json(text)
assert restored == data
value = glyph.parse('{name=Alice age=30 active=t}')
print(value.get("name").as_str())
print(value.get("age").as_int())
fp = glyph.fingerprint_loose(glyph.from_json(data))
print(fp)
Core Functions
| Function | Description |
|---|---|
parse(text) |
Parse GLYPH text to GValue |
emit(value) |
Emit a GValue as canonical loose GLYPH |
json_to_glyph(data) |
Convert Python data directly to GLYPH text |
glyph_to_json(text) |
Parse GLYPH text to Python data |
from_json(data) |
Convert Python data to GValue |
to_json(value) |
Convert GValue to Python data |
fingerprint_loose(value) |
SHA-256 fingerprint of canonical loose form |
equal_loose(a, b) |
Equality by canonical loose form |
Building Values
from glyph import g, field
team = g.struct(
"Team",
field("name", g.str("Arsenal")),
field("rank", g.int(1)),
)
print(glyph.emit(team))
Streaming Validation
from glyph import StreamingValidator, ToolRegistry
registry = ToolRegistry()
registry.add_tool("search", {
"query": {"type": "str", "required": True},
"max_results": {"type": "int", "min": 1, "max": 100},
})
validator = StreamingValidator(registry)
for token in 'search{query="glyph" max_results=5}':
result = validator.push_token(token)
assert result.complete
assert result.valid
assert result.tool_name == "search"
Optional Higher-Level Layer
The Python package also contains an optional agent-oriented runtime in glyph.agent.
Treat that as an example consumer of the codec layer, not the definition of the format.
For repo-wide docs, start at ../README.md.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file glyph_py-1.0.1.tar.gz.
File metadata
- Download URL: glyph_py-1.0.1.tar.gz
- Upload date:
- Size: 63.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6c185367821dc52a05931f502d5fbe129ff236bb847ae1b2c9fde65f6f460f0
|
|
| MD5 |
8d95aa216c8f2a140146b54ba83fa3c9
|
|
| BLAKE2b-256 |
1b1761ec087fefdc27281af4b2c76b7d6592279a974bb6b86cd1493daeab32a1
|
File details
Details for the file glyph_py-1.0.1-py3-none-any.whl.
File metadata
- Download URL: glyph_py-1.0.1-py3-none-any.whl
- Upload date:
- Size: 43.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42a76fc626428c0fa372d648cda3f1e3fb38f11156437b8ebc03c3943dd2c7a4
|
|
| MD5 |
61c8891e48a4804fdc4fbaa81c9b6942
|
|
| BLAKE2b-256 |
1640b67c1a1f5beca75d62e24dc8dd120608e78aaca610dd346ecc0d17342ce1
|