erdantic.erd¶
Edge
¶
Class for an edge in the entity relationship diagram graph. Represents the composition
relationship between a composite model (source
via source_field
) with a component model
(target
).
Attributes:
Name | Type | Description |
---|---|---|
source |
Model
|
Composite data model. |
source_field |
Field
|
Field on |
target |
Model
|
Component data model. |
Source code in erdantic/erd.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
|
dot_arrowhead()
¶
Arrow shape specification in Graphviz DOT language for this edge's head. See Graphviz docs as a reference. Shape returned is based on crow's foot notation for the relationship's cardinality and modality.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
DOT language specification for arrow shape of this edge's head |
Source code in erdantic/erd.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
EntityRelationshipDiagram
¶
Class for entity relationship diagram.
Attributes:
Name | Type | Description |
---|---|---|
models |
List[Model]
|
Data models (nodes) in diagram. |
attr2 |
List[Edge]
|
Edges in diagram, representing the composition relationship between models. |
Source code in erdantic/erd.py
81 82 83 84 85 86 87 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 |
|
draw(out, **kwargs)
¶
Render entity relationship diagram for given data model classes to file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
out |
Union[str, PathLike]
|
Output file path for rendered diagram. |
required |
**kwargs |
Additional keyword arguments to |
{}
|
Source code in erdantic/erd.py
97 98 99 100 101 102 103 104 |
|
graph()
¶
Return pygraphviz.AGraph
instance for diagram.
Returns:
Type | Description |
---|---|
AGraph
|
pygraphviz.AGraph: graph object for diagram |
Source code in erdantic/erd.py
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 |
|
to_dot()
¶
Generate Graphviz DOT language representation of entity relationship diagram for given data model classes.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
DOT language representation of diagram |
Source code in erdantic/erd.py
142 143 144 145 146 147 148 149 |
|
adapt_model(obj)
¶
Dispatch object to appropriate concrete Model
adapter subclass and
return instantiated adapter instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj |
Any
|
Data model class to adapt |
required |
Raises:
Type | Description |
---|---|
UnknownModelTypeError
|
If obj does not match registered Model adapter classes |
Returns:
Name | Type | Description |
---|---|---|
Model |
Model
|
Instantiated concrete |
Source code in erdantic/erd.py
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
|
create(*models_or_modules, termini=[], limit_search_models_to=None)
¶
Construct EntityRelationshipDiagram
from given
data model classes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*models_or_modules |
type
|
Data model classes to diagram or modules containing them. |
()
|
termini |
Sequence[type]
|
Data model classes to set as terminal nodes. erdantic will stop searching for component classes when it reaches these models |
[]
|
limit_search_models_to |
Optional[Iterable[sr]]
|
Iterable of identifiers of data model classes that erdantic supports. If any are specified, when searching a module, limit data model classes to those ones. Defaults to None which will find all data model classes supported by erdantic. |
None
|
Raises: UnknownModelTypeError: If model is not recognized as a supported model type.
Returns:
Name | Type | Description |
---|---|---|
EntityRelationshipDiagram |
EntityRelationshipDiagram
|
diagram object for given data model. |
Source code in erdantic/erd.py
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 |
|
draw(*models_or_modules, out, termini=[], limit_search_models_to=None, **kwargs)
¶
Render entity relationship diagram for given data model classes to file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*models_or_modules |
type
|
Data model classes to diagram, or modules containing them. |
()
|
out |
Union[str, PathLike]
|
Output file path for rendered diagram. |
required |
termini |
Sequence[type]
|
Data model classes to set as terminal nodes. erdantic will stop searching for component classes when it reaches these models |
[]
|
limit_search_models_to |
Optional[Iterable[sr]]
|
Iterable of identifiers of data model classes that erdantic supports. If any are specified, when searching a module, limit data model classes to those ones. Defaults to None which will find all data model classes supported by erdantic. |
None
|
**kwargs |
Additional keyword arguments to |
{}
|
Source code in erdantic/erd.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
|
find_models(module, limit_search_models_to=None)
¶
Searches a module and yields all data model classes found.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module |
ModuleType
|
Module to search for data model classes |
required |
limit_search_models_to |
Optional[Iterable[sr]]
|
Iterable of identifiers of data model classes that erdantic supports. If any are specified, when searching a module, limit data model classes to those ones. Defaults to None which will find all data model classes supported by erdantic. |
None
|
Yields:
Type | Description |
---|---|
type
|
Iterator[type]: Members of module that are data model classes. |
Source code in erdantic/erd.py
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 |
|
search_composition_graph(model, seen_models, seen_edges)
¶
Recursively search composition graph for a model, where nodes are models and edges are composition relationships between models. Nodes and edges that are discovered will be added to the two respective provided set instances.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
Model
|
Root node to begin search. |
required |
seen_models |
Set[Model]
|
Set instance that visited nodes will be added to. |
required |
seen_edges |
Set[Edge]
|
Set instance that traversed edges will be added to. |
required |
Source code in erdantic/erd.py
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 |
|
to_dot(*models_or_modules, termini=[], limit_search_models_to=None)
¶
Generate Graphviz DOT language representation of entity relationship diagram for given data model classes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*models_or_modules |
type
|
Data model classes to diagram, or modules containing them. |
()
|
termini |
Sequence[type]
|
Data model classes to set as terminal nodes. erdantic will stop searching for component classes when it reaches these models |
[]
|
limit_search_models_to |
Optional[Iterable[sr]]
|
Iterable of identifiers of data model classes that erdantic supports. If any are specified, when searching a module, limit data model classes to those ones. Defaults to None which will find all data model classes supported by erdantic. |
None
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
DOT language representation of diagram |
Source code in erdantic/erd.py
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
|