graphcast.architecture.vertex
¶
Vertex configuration and management for graph databases.
This module provides classes and utilities for managing vertices in graph databases. It handles vertex configuration, field management, indexing, and filtering operations. The module supports both ArangoDB and Neo4j through the DBFlavor enum.
Key Components
- Vertex: Represents a vertex with its fields and indexes
- VertexConfig: Manages collections of vertices and their configurations
Example
vertex = Vertex(name="user", fields=["id", "name"]) config = VertexConfig(vertices=[vertex]) fields = config.fields("user", with_aux=True)
Vertex
dataclass
¶
Bases: BaseDataclass
Represents a vertex in the graph database.
A vertex is a fundamental unit in the graph that can have fields, indexes, and filters
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
Name of the vertex |
fields |
list[str]
|
List of field names |
fields_aux |
list[str]
|
List of auxiliary field names for weight passing |
indexes |
list[Index]
|
List of indexes for the vertex |
filters |
list[Expression]
|
List of filter expressions |
dbname |
Optional[str]
|
Optional database name (defaults to vertex name) |
Source code in graphcast/architecture/vertex.py
fields_all
property
¶
Get all fields including auxiliary fields.
Returns:
Type | Description |
---|---|
list[str]: Combined list of regular and auxiliary fields |
__post_init__()
¶
Initialize the vertex after dataclass initialization.
Sets the database name if not provided and updates fields based on indexes.
Source code in graphcast/architecture/vertex.py
update_aux_fields(fields_aux)
¶
Update auxiliary fields.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fields_aux
|
list
|
List of new auxiliary fields to add |
required |
Returns:
Name | Type | Description |
---|---|---|
Vertex |
Self for method chaining |
Source code in graphcast/architecture/vertex.py
VertexConfig
dataclass
¶
Bases: BaseDataclass
Configuration for managing collections of vertices.
This class manages a collection of vertices, providing methods for accessing and manipulating vertex configurations.
Attributes:
Name | Type | Description |
---|---|---|
vertices |
list[Vertex]
|
List of vertex configurations |
blank_vertices |
list[str]
|
List of blank vertex names |
force_types |
dict[str, list]
|
Dictionary mapping vertex names to type lists |
db_flavor |
DBFlavor
|
Database flavor (ARANGO or NEO4J) |
Source code in graphcast/architecture/vertex.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 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 |
|
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 |
__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 graphcast/architecture/vertex.py
__post_init__()
¶
Initialize the vertex configuration.
Creates internal mappings and validates blank vertices.
Raises:
Type | Description |
---|---|
ValueError
|
If blank vertices are not defined in the configuration |
Source code in graphcast/architecture/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 |
fields(vertex_name, with_aux=False)
¶
Get fields for a vertex.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vertex_name
|
str
|
Name of the vertex |
required |
with_aux
|
Whether to include auxiliary fields |
False
|
Returns:
Type | Description |
---|---|
list[str]: List of fields |
Source code in graphcast/architecture/vertex.py
filters(vertex_name)
¶
Get filter expressions for a vertex.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vertex_name
|
Name of the vertex |
required |
Returns:
Type | Description |
---|---|
list[Expression]
|
list[Expression]: List of filter expressions |
Source code in graphcast/architecture/vertex.py
index(vertex_name)
¶
Get primary index for a vertex.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vertex_name
|
Name of the vertex |
required |
Returns:
Name | Type | Description |
---|---|---|
Index |
Index
|
Primary index for the vertex |
indexes(vertex_name)
¶
Get all indexes for a vertex.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vertex_name
|
Name of the vertex |
required |
Returns:
Type | Description |
---|---|
list[Index]
|
list[Index]: List of indexes for the vertex |
Source code in graphcast/architecture/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 graphcast/architecture/vertex.py
update_vertex(v)
¶
Update vertex configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
v
|
Vertex
|
Vertex configuration to update |
required |
vertex_dbname(vertex_name)
¶
Get database name for a vertex.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vertex_name
|
Name of the vertex |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Database name for the vertex |
Raises:
Type | Description |
---|---|
KeyError
|
If vertex is not found |