graflo.onto¶
Core ontology and base classes for graph database operations.
This module provides the fundamental data structures and base classes used throughout the graph database system. It includes base classes for enums, dataclasses, and database-specific configurations.
Key Components
- BaseEnum: Base class for string-based enumerations with flexible membership testing
- BaseDataclass: Base class for dataclasses with JSON/YAML serialization support
- DBFlavor: Enum for supported database types (ArangoDB, Neo4j)
- ExpressionFlavor: Enum for expression language types
- AggregationType: Enum for supported aggregation operations
Example
class MyEnum(BaseEnum): ... VALUE1 = "value1" ... VALUE2 = "value2" "value1" in MyEnum # True "invalid" in MyEnum # False
AggregationType
¶
Bases: BaseEnum
Supported aggregation operations.
This enum defines the supported aggregation operations for data analysis.
Attributes:
| Name | Type | Description |
|---|---|---|
COUNT |
Count operation |
|
MAX |
Maximum value |
|
MIN |
Minimum value |
|
AVERAGE |
Average value |
|
SORTED_UNIQUE |
Sorted unique values |
Source code in graflo/onto.py
BaseDataclass
dataclass
¶
Bases: JSONWizard, Meta, YAMLWizard
Base class for dataclasses with serialization support.
This class provides a foundation for dataclasses with JSON and YAML serialization capabilities. It includes methods for updating instances and accessing field members.
Attributes:
| Name | Type | Description |
|---|---|---|
marshal_date_time_as |
Format for datetime serialization |
|
key_transform_with_dump |
Key transformation style for serialization |
Source code in graflo/onto.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
_
¶
Bases: Meta
Meta configuration for serialization.
Set skip_defaults=True here to exclude fields with default values by default when serializing. Can still be overridden per-call.
Source code in graflo/onto.py
get_fields_members()
classmethod
¶
Get list of field members excluding private ones.
Returns:
| Type | Description |
|---|---|
|
list[str]: List of public field names |
to_dict(skip_defaults=None, **kwargs)
¶
Convert instance to dictionary with enums serialized as strings.
This method overrides the default to_dict to ensure that all BaseEnum instances are automatically converted to their string values during serialization, making YAML/JSON output cleaner and more portable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skip_defaults
|
bool | None
|
If True, fields with default values are excluded. If None, uses the Meta class skip_defaults setting. |
None
|
**kwargs
|
Additional arguments passed to parent to_dict method |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dictionary representation with enums as strings |
Source code in graflo/onto.py
to_yaml(skip_defaults=None, **kwargs)
¶
Convert instance to YAML string with enums serialized as strings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skip_defaults
|
bool | None
|
If True, fields with default values are excluded. If None, uses the Meta class skip_defaults setting. |
None
|
**kwargs
|
Additional arguments passed to yaml.safe_dump |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
YAML string representation with enums as strings |
Source code in graflo/onto.py
to_yaml_file(file_path, skip_defaults=None, **kwargs)
¶
Write instance to YAML file with enums serialized as strings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Path to the YAML file to write |
required |
skip_defaults
|
bool | None
|
If True, fields with default values are excluded. If None, uses the Meta class skip_defaults setting. |
None
|
**kwargs
|
Additional arguments passed to yaml.safe_dump |
{}
|
Source code in graflo/onto.py
update(other)
¶
Update this instance with values from another instance.
This method performs a deep update of the instance's attributes using values from another instance of the same type. It handles different types of attributes (sets, lists, dicts, dataclasses) appropriately.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Another instance of the same type to update from |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If other is not an instance of the same type |
Source code in graflo/onto.py
BaseEnum
¶
Bases: StrEnum
Base class for string-based enumerations.
This class provides a foundation for string-based enums with flexible membership testing through the MetaEnum metaclass.
Source code in graflo/onto.py
__repr__()
¶
DBFlavor
¶
Bases: BaseEnum
Supported database types.
This enum defines the supported graph database types in the system.
Attributes:
| Name | Type | Description |
|---|---|---|
ARANGO |
ArangoDB database |
|
NEO4J |
Neo4j database |
|
TIGERGRAPH |
TigerGraph database |
|
FALKORDB |
FalkorDB database (Redis-based graph database using Cypher) |
Source code in graflo/onto.py
ExpressionFlavor
¶
Bases: BaseEnum
Supported expression language types.
This enum defines the supported expression languages for querying and filtering data.
Attributes:
| Name | Type | Description |
|---|---|---|
ARANGO |
ArangoDB AQL expressions |
|
NEO4J |
Neo4j Cypher expressions |
|
TIGERGRAPH |
TigerGraph GSQL expressions |
|
FALKORDB |
FalkorDB Cypher expressions (OpenCypher compatible) |
|
PYTHON |
Python expressions |
Source code in graflo/onto.py
MetaEnum
¶
Bases: EnumMeta
Metaclass for flexible enumeration membership testing.
This metaclass allows checking if a value is a valid member of an enum
using the in operator, even if the value hasn't been instantiated as
an enum member.
Example
class MyEnum(BaseEnum): ... VALUE = "value" "value" in MyEnum # True "invalid" in MyEnum # False
Source code in graflo/onto.py
__contains__(item, **kwargs)
¶
Check if an item is a valid member of the enum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Value to check for membership |
required | |
**kwargs
|
Additional keyword arguments |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
True if the item is a valid enum member, False otherwise |