Skip to main content

Node kinds

A node is a typed entity in the graph. Every node is a frozen dataclass:

from graphlens import Node, NodeKind

Node(
id="a1b2c3d4e5f6a7b8",
kind=NodeKind.FUNCTION,
qualified_name="app.services.process_order",
name="process_order",
file_path="src/app/services.py", # optional
span=Span(12, 1, 30, 2), # optional, 1-based
metadata={}, # free-form
)
FieldTypeDescription
idstrDeterministic 16-char id (see below)
kindNodeKindThe discriminator
qualified_namestrFully qualified name (module.Class.method)
namestrShort name (method)
file_pathstr | NoneSource file, when applicable
spanSpan | None1-based source range
metadatadict[str, object]Arbitrary extra data (e.g. origin)

The kinds

KindDescription
PROJECTRoot project node
MODULEA module (directory or file), language-dependent
FILEA source file
CLASSA class declaration
FUNCTIONA top-level function
METHODA method inside a class
PARAMETERA function/method parameter
VARIABLEA module-level or local variable
ATTRIBUTEA class attribute
TYPE_ALIASA type-alias declaration
IMPORTAn import statement
DEPENDENCYA declared package dependency
EXTERNAL_SYMBOLA symbol outside the project (stdlib, third-party, or unknown)
BOUNDARYA cross-language interface port (see Boundaries)

Deterministic IDs

IDs are a SHA-256 hash of project_name::kind::qualified_name, truncated to 16 hex characters:

from graphlens import make_node_id
make_node_id("my-project", "app.services.process_order", "FUNCTION")

Because the ID depends only on identity — not on file position — re-scanning a project yields the same IDs. That is what makes diff and incremental updates work.

The origin metadata

IMPORT and EXTERNAL_SYMBOL nodes always carry metadata["origin"]:

ValueMeaning
stdliblanguage standard library
internala module declared in the same project (a fallback when the MODULE node is not yet in the graph)
third_partya package listed in a dependency manifest
unknownnone of the above

This is the line between "our code" and "the ecosystem". See querying recipes.

Typical hierarchy

PROJECT
└─(CONTAINS)─ MODULE
└─(CONTAINS)─ FILE
└─(DECLARES)─ CLASS
└─(DECLARES)─ METHOD
└─(DECLARES)─ FUNCTION
└─(DECLARES)─ VARIABLE / ATTRIBUTE / TYPE_ALIAS
└─(DECLARES)─ IMPORT ─(RESOLVES_TO)─ MODULE (internal)
└─(RESOLVES_TO)─ EXTERNAL_SYMBOL (stdlib/third_party/unknown)

See Relation kinds for the edges.