GValue
The universal value container for GLYPH data. All GLYPH values are represented asGValue instances.
Type Property
The type of this value (null, bool, int, float, str, bytes, time, id, list, map, struct, sum)
Type Constructors
Static methods for creating GValue instances:null()
Create a null value.GValue - A null value
bool_(v: bool)
Create a boolean value.Boolean value (True or False)
GValue - A boolean value
int_(v: int)
Create an integer value.Integer value
GValue - An integer value
float_(v: float)
Create a floating-point value.Float value
GValue - A float value
str_(v: str)
Create a string value.String value
GValue - A string value
bytes_(v: bytes)
Create a bytes value.Bytes value
GValue - A bytes value
time(v: datetime)
Create a timestamp value.Python datetime object (with or without timezone)
GValue - A time value
id(prefix: str, value: str)
Create a reference ID value.ID prefix (can be empty string)
ID value
GValue - An ID reference value
list_(*values: GValue)
Create a list value.Variable number of GValue elements
GValue - A list value
map_(*entries: MapEntry)
Create a map value.Variable number of key-value pairs
GValue - A map value
struct(type_name: str, *fields: MapEntry)
Create a struct value with a type name.Name of the struct type
Variable number of field entries
GValue - A struct value
sum(tag: str, value: Optional[GValue])
Create a sum type (tagged union) value.Tag identifying the variant
Optional payload value
GValue - A sum type value
Value Accessors
Methods for extracting typed values. All accessors raiseTypeError if the value is not of the expected type.
is_null() → bool
Check if the value is null.bool - True if value is null
as_bool() → bool
Extract boolean value.bool - The boolean value
Raises: TypeError - If value is not a boolean
as_int() → int
Extract integer value.int - The integer value
Raises: TypeError - If value is not an integer
as_float() → float
Extract float value.float - The float value
Raises: TypeError - If value is not a float
as_str() → str
Extract string value.str - The string value
Raises: TypeError - If value is not a string
as_bytes() → bytes
Extract bytes value.bytes - The bytes value
Raises: TypeError - If value is not bytes
as_time() → datetime
Extract datetime value.datetime - The datetime value
Raises: TypeError - If value is not a time
as_id() → RefID
Extract reference ID value.RefID - The reference ID object
Raises: TypeError - If value is not an ID
as_list() → List[GValue]
Extract list value.List[GValue] - The list of values
Raises: TypeError - If value is not a list
as_map() → List[MapEntry]
Extract map entries.List[MapEntry] - The map entries
Raises: TypeError - If value is not a map
as_struct() → StructValue
Extract struct value.StructValue - The struct object with type_name and fields
Raises: TypeError - If value is not a struct
as_sum() → SumValue
Extract sum type value.SumValue - The sum object with tag and value
Raises: TypeError - If value is not a sum type
as_number() → int | float
Extract numeric value (works for both int and float).int | float - The numeric value
Raises: TypeError - If value is not numeric
Collection Methods
get(key: str) → Optional[GValue]
Get field from struct or map by key.Field or entry key
GValue | None - The value if found, None otherwise
index(i: int) → GValue
Get element from list by index.Zero-based index
GValue - The element at the index
Raises: IndexError - If index is out of bounds
len() → int
Get length of list, map, or struct fields.int - Number of elements/fields
Mutators
set(key: str, value: GValue)
Set field on struct or map.Field or entry key
Value to set
TypeError - If value is not a struct or map
append(value: GValue)
Append to list.Value to append
TypeError - If value is not a list
clone() → GValue
Create a deep copy of this value.GValue - A deep copy of the value
GType
Enumeration of GLYPH value types.Values
GType.NULL- Null valueGType.BOOL- Boolean (true/false)GType.INT- Integer numberGType.FLOAT- Floating-point numberGType.STR- StringGType.BYTES- Byte arrayGType.TIME- TimestampGType.ID- Reference IDGType.LIST- List of valuesGType.MAP- Key-value mapGType.STRUCT- Typed structGType.SUM- Tagged union
Helper Classes
MapEntry
Key-value pair for maps and structs.The entry key
The entry value
RefID
Reference ID with optional prefix.ID prefix (can be empty)
ID value
StructValue
Struct with type name and fields.Name of the struct type
List of field entries
SumValue
Tagged union (sum type).Tag identifying the variant
Optional payload value
Shorthand Constructor: g
Theg object provides shorthand constructors without the trailing underscore.
Available Methods
g.null()→ GValueg.bool(v: bool)→ GValueg.int(v: int)→ GValueg.float(v: float)→ GValueg.str(v: str)→ GValueg.bytes(v: bytes)→ GValueg.time(v: datetime)→ GValueg.id(prefix: str, value: str)→ GValueg.list(*values: GValue)→ GValueg.map(*entries: MapEntry)→ GValueg.struct(type_name: str, *fields: MapEntry)→ GValueg.sum(tag: str, value: Optional[GValue])→ GValue
field() Helper
Create a field entry for struct construction.Field name
Field value
MapEntry - A field entry