graflo.architecture.schema.vertex¶
Vertex configuration and management for graph databases.
This module provides classes and utilities for managing vertices in graph databases. It handles vertex configuration, property management, identity, and filtering operations. The module supports both ArangoDB and Neo4j through the DBType enum.
Key Components
- Vertex: Represents a vertex with its properties and identity
- VertexConfig: Manages vertices and their configurations
Example
vertex = Vertex(name="user", properties=["id", "name"]) config = VertexConfig(vertices=[vertex]) props = config.properties("user") # Returns list[Field] prop_names = config.property_names("user") # Returns list[str]
Attributes¶
IdentityMode = Literal['natural', 'hash', 'blank', 'assigned']
module-attribute
¶
PropertiesInputType = list[str] | list['Field'] | list[dict[str, Any]]
module-attribute
¶
RELOCATED_VERTEX_KEYS = {'dbname': 'db_profile.vertex_storage_names', 'indexes': 'db_profile.vertex_indexes', 'transforms': 'the ingestion model, as resource pipeline steps'}
module-attribute
¶
SCALAR_FIELD_TYPES = frozenset({FieldType.INT, FieldType.UINT, FieldType.FLOAT, FieldType.DOUBLE, FieldType.BOOL, FieldType.STRING, FieldType.DATETIME, FieldType.UUID})
module-attribute
¶
SCALAR_FIELD_TYPE_VALUES = frozenset(ft.value for ft in SCALAR_FIELD_TYPES)
module-attribute
¶
VertexName = str
module-attribute
¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
Field
¶
Bases: ConfigBaseModel
Represents a typed field in a vertex.
Field objects behave like strings for backward compatibility. They can be used in sets, as dictionary keys, and in string comparisons. The type information is preserved for databases that need it (like TigerGraph).
Attributes:
| Name | Type | Description |
|---|---|---|
name |
VertexName
|
Name of the field |
type |
FieldType | None
|
Optional type of the field. Can be FieldType enum, str, or None at construction. Strings are converted to FieldType enum by the validator. None is allowed (most databases like ArangoDB don't require types). Defaults to None. |
item_type |
FieldType | None
|
Required when |
Source code in graflo/architecture/schema/vertex.py
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 | |
Attributes¶
description = PydanticField(default=None, description='Optional semantic description of the field for schema inference and downstream reasoning.')
class-attribute
instance-attribute
¶
item_type = PydanticField(default=None, description='Element type when ``type`` is LIST. Must be a scalar (INT, UINT, FLOAT, DOUBLE, BOOL, STRING, DATETIME, UUID).')
class-attribute
instance-attribute
¶
model_config = ConfigDict(extra='forbid')
class-attribute
instance-attribute
¶
name = PydanticField(..., description='Name of the field (e.g. column or attribute name).')
class-attribute
instance-attribute
¶
semantics = PydanticField(default=None, description='Optional external-vocabulary anchors and unit for this field.')
class-attribute
instance-attribute
¶
type = PydanticField(default=None, description='Optional field type for databases that require it (e.g. TigerGraph: INT, STRING). None for schema-agnostic backends.')
class-attribute
instance-attribute
¶
Methods:¶
__eq__(other)
¶
Compare equal to strings with same name, or other Field objects with same name.
Source code in graflo/architecture/schema/vertex.py
__hash__()
¶
__ne__(other)
¶
__repr__()
¶
Return representation including type information.
Source code in graflo/architecture/schema/vertex.py
__str__()
¶
normalize_item_type(v)
classmethod
¶
normalize_type(v)
classmethod
¶
validate_list_item_type()
¶
Source code in graflo/architecture/schema/vertex.py
FieldMergeConflict
¶
Bases: Refusal
One property that two declarations describe incompatibly.
The per-property clause and the remedy are kept apart from the rendered
message so :func:union_field_lists can report every conflicting property
under one owner heading instead of one error per run.
field and conflict are the same two facts in structured form: which
property, and whether the disagreement is about types or about units. A
caller classifying the refusal reads those rather than the prose.
Source code in graflo/architecture/schema/vertex.py
Attributes¶
conflict = _conflict_kind([reason])
instance-attribute
¶
field = field
instance-attribute
¶
owner = owner
instance-attribute
¶
reason = reason
instance-attribute
¶
remedy = remedy
instance-attribute
¶
Methods:¶
__init__(owner, reason, remedy, *, field)
¶
Source code in graflo/architecture/schema/vertex.py
FieldMergeError
¶
Bases: Refusal
Every property two declarations describe incompatibly, in one refusal.
:func:union_field_lists collects rather than raising on the first clash,
so an author fixing a large merge sees all of them at once. The
individual :class:FieldMergeConflict objects stay on conflicts and
their property names on fields, so a caller can point at what is
wrong without parsing the rendered message.
check follows :func:_conflict_kind over the whole set, which is what
the heading already says -- so a reader of the message and a caller keying
on check are told the same thing, and a mixed set reports as a type
conflict on both.
Source code in graflo/architecture/schema/vertex.py
Attributes¶
conflict = _conflict_kind([c.reason for c in conflicts])
instance-attribute
¶
conflicts = conflicts
instance-attribute
¶
fields = tuple(dict.fromkeys(c.field for c in conflicts))
instance-attribute
¶
owner = owner
instance-attribute
¶
Methods:¶
__init__(message, *, owner, conflicts)
¶
Source code in graflo/architecture/schema/vertex.py
FieldType
¶
Bases: BaseEnum
Supported field types for graph databases.
These types are primarily used for TigerGraph, which requires explicit field types. Other databases (ArangoDB, Neo4j) may use different type systems or not require types.
Attributes:
| Name | Type | Description |
|---|---|---|
INT |
Integer type |
|
UINT |
Unsigned integer type |
|
FLOAT |
Floating point type |
|
DOUBLE |
Double precision floating point type |
|
BOOL |
Boolean type |
|
STRING |
String type |
|
DATETIME |
DateTime type |
|
UUID |
Logical UUID scalar (backends store as STRING/TEXT) |
|
LIST |
Homogeneous list of scalars (requires |
Source code in graflo/architecture/schema/vertex.py
Attributes¶
BOOL = 'BOOL'
class-attribute
instance-attribute
¶
DATETIME = 'DATETIME'
class-attribute
instance-attribute
¶
DOUBLE = 'DOUBLE'
class-attribute
instance-attribute
¶
FLOAT = 'FLOAT'
class-attribute
instance-attribute
¶
INT = 'INT'
class-attribute
instance-attribute
¶
LIST = 'LIST'
class-attribute
instance-attribute
¶
STRING = 'STRING'
class-attribute
instance-attribute
¶
UINT = 'UINT'
class-attribute
instance-attribute
¶
UUID = 'UUID'
class-attribute
instance-attribute
¶
SecondaryIdentity
¶
Bases: ConfigBaseModel
An alternate field-set that identifies a vertex without upserting it.
Vertices upsert on their primary identity. Edge-only sources often
reference endpoints by another field-set — a business key, an ISIN, a
source-local code — which is what a secondary identity names.
Uniqueness is soft: it is not enforced by a database constraint, so a lookup may match several vertices and the ingestion-level ambiguity policy decides what happens.
Examples:
>>> SecondaryIdentity(name="by_isin", fields=["isin"])
>>> SecondaryIdentity.model_validate(["org", "local_code"]) # auto-named
Source code in graflo/architecture/schema/vertex.py
Attributes¶
field_set
property
¶
fields = PydanticField(..., min_length=1, description='Property names forming this alternate key.')
class-attribute
instance-attribute
¶
name = PydanticField(default=None, description='Optional handle used by an edge step to select this field-set (e.g. source_match: by_isin).')
class-attribute
instance-attribute
¶
Methods:¶
dedupe_fields(v)
classmethod
¶
normalize_authored_shape(data)
classmethod
¶
Accept a bare [field, ...] list alongside the mapping form.
Source code in graflo/architecture/schema/vertex.py
Vertex
¶
Bases: ConfigBaseModel
Represents a vertex in the graph database.
A vertex is a fundamental unit in the graph that can have properties, identity, and filters. Properties can be specified as strings, Field objects, or dicts. Internally, properties are stored as Field objects but behave like strings where a string-like Field is needed.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Name of the vertex |
properties |
list[Field]
|
List of field names (str), Field objects, or dicts. Will be normalized to Field objects by the validator. |
identity |
list[str]
|
List of property names forming logical primary identity |
filters |
list[FilterExpression]
|
List of filter expressions |
Examples:
>>> # Typed properties: list of Field objects
>>> v2 = Vertex(name="user", properties=[
... Field(name="id", type="INT"),
... Field(name="name", type="STRING")
... ])
>>> # From dicts (e.g., from YAML/JSON)
>>> v3 = Vertex(name="user", properties=[
... {"name": "id", "type": "INT"},
... {"name": "name"} # defaults to None type
... ])
Source code in graflo/architecture/schema/vertex.py
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 | |
Attributes¶
assigned = PydanticField(default=False, description='True when this vertex uses an intentional UUID primary key: empty identity is filled with uuid4 at assemble time; not a blank-node placeholder.')
class-attribute
instance-attribute
¶
blank = PydanticField(default=False, description='True when this vertex has no natural identity and gets an auto-generated ID.')
class-attribute
instance-attribute
¶
description = PydanticField(default=None, description='Optional semantic description of the vertex meaning, role, and intended interpretation.')
class-attribute
instance-attribute
¶
digest_source_fields
property
¶
Fields feeding the synthetic digest, flat or funnel; empty otherwise.
filters = PydanticField(default_factory=list, description='Filter expressions (logical formulae) applied when querying this vertex.')
class-attribute
instance-attribute
¶
has_identity_funnel
property
¶
True when identity is derived from ordered funnel branches.
hash_identity_properties = PydanticField(default_factory=list, description="Source field names whose combined values are SHA256-hashed to produce a deterministic synthetic 'id'. Non-empty only when no natural key is narrow enough to store directly. Distinct from blank (random UUID).")
class-attribute
instance-attribute
¶
identity = PydanticField(default_factory=list, description='Logical identity property names (primary key semantics for matching/upserts).')
class-attribute
instance-attribute
¶
identity_funnel = PydanticField(default=None, description="Ordered fallback branches deriving a deterministic synthetic 'id'. The first branch whose fields are all present wins. Generalizes hash_identity_properties (the single-branch case); the two are mutually exclusive.")
class-attribute
instance-attribute
¶
identity_mode
property
¶
Runtime identity mode: natural, hash, blank, or assigned UUID PK.
A funnel resolves to hash: both derive a deterministic synthetic key
from source fields and share one writer family. Use
:attr:has_identity_funnel to tell them apart.
model_config = ConfigDict(extra='forbid')
class-attribute
instance-attribute
¶
name = PydanticField(..., description='Name of the vertex type (e.g. user, post, company).')
class-attribute
instance-attribute
¶
properties = PydanticField(default_factory=list, description='List of fields (names, Field objects, or dicts). Normalized to Field objects.')
class-attribute
instance-attribute
¶
property_names
property
¶
Property names as strings (Field.name for each entry).
secondary_identities = PydanticField(default_factory=list, description='Alternate field-sets that identify this vertex for lookup only. Edge endpoints may be matched on one of these instead of the primary identity; upserts always use identity. Soft uniqueness.')
class-attribute
instance-attribute
¶
secondary_identity_names
property
¶
Names of declared secondary identities, in declaration order.
semantics = PydanticField(default=None, description='Optional external-vocabulary anchors for this vertex type.')
class-attribute
instance-attribute
¶
Methods:¶
convert_hash_identity_properties(v)
classmethod
¶
Source code in graflo/architecture/schema/vertex.py
convert_identity(v)
classmethod
¶
Source code in graflo/architecture/schema/vertex.py
convert_to_expressions(v)
classmethod
¶
Source code in graflo/architecture/schema/vertex.py
convert_to_properties(v)
classmethod
¶
Source code in graflo/architecture/schema/vertex.py
finish_init()
¶
get_properties()
¶
secondary_identity(selector)
¶
Resolve selector to a declared secondary identity.
Accepts a declared name, an explicit field list equal to a declared
field-set, or the literal "secondary" when exactly one is declared.
Source code in graflo/architecture/schema/vertex.py
set_identity()
¶
Source code in graflo/architecture/schema/vertex.py
725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 | |
VertexConfig
¶
Bases: ConfigBaseModel
Configuration for managing vertices.
This class manages vertices, providing methods for accessing and manipulating vertex configurations.
Attributes:
| Name | Type | Description |
|---|---|---|
vertices |
list[Vertex]
|
List of vertex configurations |
force_types |
dict[str, list]
|
Dictionary mapping vertex names to type lists |
Source code in graflo/architecture/schema/vertex.py
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 | |
Attributes¶
assigned_vertices
property
¶
Vertex names with intentional UUID primary keys (assigned: true).
blank_vertices
property
¶
Vertex names marked blank (no natural identity; auto-generated ID).
force_types = PydanticField(default_factory=dict, description='Override mapping: vertex name -> list of field type names for type inference.')
class-attribute
instance-attribute
¶
hash_identity_vertices
property
¶
Vertex names using digest-derived synthetic identity (flat or funnel).
identity_from_all_properties = PydanticField(default=True, description='When true, vertices without explicit identity fall back to all property names. When false, explicit identity is required except for blank or assigned vertices.')
class-attribute
instance-attribute
¶
identity_funnel_vertices
property
¶
Vertex names whose synthetic identity comes from a funnel.
model_config = ConfigDict(extra='forbid')
class-attribute
instance-attribute
¶
vertex_list
property
¶
Get list of vertex configurations.
Returns:
| Type | Description |
|---|---|
|
list[Vertex]: List of vertex configurations |
vertex_set
property
¶
Get set of vertex names.
Returns:
| Type | Description |
|---|---|
|
set[str]: Set of vertex names |
vertices = PydanticField(..., description='List of vertex type definitions (name, properties, identity, filters).')
class-attribute
instance-attribute
¶
Methods:¶
__getitem__(key)
¶
Get vertex configuration by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Vertex name |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Vertex |
Vertex configuration |
Raises:
| Type | Description |
|---|---|
KeyError
|
If vertex is not found |
Source code in graflo/architecture/schema/vertex.py
__setitem__(key, value)
¶
Set vertex configuration by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Vertex name |
required |
value
|
Vertex
|
Vertex configuration |
required |
build_vertices_map()
¶
Source code in graflo/architecture/schema/vertex.py
filters(vertex_name)
¶
Get filter clauses for a vertex.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertex_name
|
Name of the vertex |
required |
Returns:
| Type | Description |
|---|---|
list[FilterExpression]
|
list[FilterExpression]: List of filter expressions |
Source code in graflo/architecture/schema/vertex.py
finish_init()
¶
identity_fields(vertex_name)
¶
match_fields(vertex_name, selector)
¶
Fields an edge endpoint is matched on for selector.
None or "identity" selects the primary identity, which keeps
every existing edge step on exactly the path it uses today.
Raises:
| Type | Description |
|---|---|
ValueError
|
if selector names no declared secondary identity. |
Source code in graflo/architecture/schema/vertex.py
numeric_fields_list(vertex_name)
¶
Get list of numeric fields for a vertex.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertex_name
|
Name of the vertex |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
Tuple of numeric field names |
Raises:
| Type | Description |
|---|---|
ValueError
|
If vertex is not defined in config |
Source code in graflo/architecture/schema/vertex.py
properties(vertex_name)
¶
property_names(vertex_name)
¶
Vertex property names as strings.
remove_vertices(names)
¶
Remove vertices by name.
Removes vertices from the configuration. Mutates the instance in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
names
|
set[str]
|
Set of vertex names to remove |
required |
Source code in graflo/architecture/schema/vertex.py
secondary_identities(vertex_name)
¶
Declared secondary identities for a vertex.
secondary_identity_fields(vertex_name, selector)
¶
Resolve an edge-step selector to a secondary identity field-set.
Returns None when selector names no declared secondary identity,
letting callers raise with their own context.
Source code in graflo/architecture/schema/vertex.py
update_vertex(v)
¶
Update vertex configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v
|
Vertex
|
Vertex configuration to update |
required |
vertices_by_identity_mode(mode)
¶
Vertex names whose resolved identity mode matches mode.
Functions:¶
field_type_value(ft)
¶
Normalize a FieldType / string / None to an uppercase type string.
Source code in graflo/architecture/schema/vertex.py
format_field_type_label(field)
¶
Human-readable type label, e.g. LIST<STRING>, INT or untyped.
Source code in graflo/architecture/schema/vertex.py
is_list_field_type(ft)
¶
merge_fields(a, b, *, owner)
¶
Merge two same-named fields, refusing a genuine disagreement.
type and item_type are compared and carried as a unit: LIST
is only half a type, so electing a type without the item_type that
came with it yields a field that cannot be constructed. One untyped side
gives way to the other's pair whole; two typed sides that disagree raise,
because widening (INT + FLOAT -> DOUBLE) would elect a type
neither author wrote.
Descriptions from both sides survive and grounding folds through
:func:~graflo.architecture.schema.semantics.merge_field_semantics. Nothing
here is decided by which side was seen first.
owner is a rendered label -- vertex 'party', edge ('order',
'invoice', 'places') -- so a merge kernel keyed by into name and a
model validator keyed by self.name raise the same sentence.
Source code in graflo/architecture/schema/vertex.py
union_field_lists(fields, *, owner)
¶
Fold same-named fields into one, preserving first-declaration order.
Every conflicting property is reported together: merging two large schemas one error per run makes the author re-run the merge to discover the next disagreement, when the merge already knows all of them.