Navegador

navegador / docs / api / sdk.md
1
# Python SDK Reference
2
3
Full API reference for the navegador Python SDK.
4
5
```python
6
from navegador.graph import GraphStore
7
from navegador.context import ContextLoader, ContextBundle, ContextNode, ContextEdge
8
from navegador.ingest import RepoIngester, KnowledgeIngester, WikiIngester, PlanopticonIngester
9
```
10
11
---
12
13
## GraphStore
14
15
Database abstraction layer. Both SQLite and Redis backends implement this interface.
16
17
```python
18
class GraphStore:
19
@classmethod
20
def sqlite(cls, path: str | Path = "navegador.db") -> "GraphStore": ...
21
22
@classmethod
23
def redis(cls, url: str = "redis://localhost:6379") -> "GraphStore": ...
24
```
25
26
### Class methods
27
28
#### `GraphStore.sqlite`
29
30
```python
31
@classmethod
32
def sqlite(cls, path: str | Path = "navegador.db") -> "GraphStore"
33
```
34
35
Open a local SQLite-backed graph. The file is created if it does not exist. Uses `falkordblite` (embedded engine — no daemon required).
36
37
**Parameters:**
38
39
| Name | Type | Default | Description |
40
|---|---|---|---|
41
| `path` | `str \| Path` | `"navegador.db"` | Path to the `.db` file |
42
43
**Returns:** `GraphStore`
44
45
#### `GraphStore.redis`
46
47
```python
48
@classmethod
49
def redis(cls, url: str = "redis://localhost:6379") -> "GraphStore"
50
```
51
52
Connect to a Redis-backed FalkorDB instance.
53
54
**Parameters:**
55
56
| Name | Type | Default | Description |
57
|---|---|---|---|
58
| `url` | `str` | `"redis://localhost:6379"` | Redis connection URL |
59
60
**Returns:** `GraphStore`
61
62
---
63
64
### Instance methods
65
66
#### `query`
67
68
```python
69
def query(self, cypher: str, params: dict | None = None) -> list[dict]
70
```
71
72
Execute a Cypher query and return all result rows.
73
74
**Parameters:**
75
76
| Name | Type | Default | Description |
77
|---|---|---|---|
78
| `cypher` | `str` | — | Cypher query string |
79
| `params` | `dict \| None` | `None` | Optional query parameters |
80
81
**Returns:** `list[dict]` — one dict per result row, keyed by return variable name.
82
83
---
84
85
#### `create_node`
86
87
```python
88
def create_node(self, label: str, properties: dict) -> str
89
```
90
91
Create a new node and return its ID.
92
93
**Parameters:**
94
95
| Name | Type | Description |
96
|---|---|---|
97
| `label` | `str` | Node label (e.g., `"Function"`, `"Concept"`) |
98
| `properties` | `dict` | Node properties |
99
100
**Returns:** `str` — node ID
101
102
---
103
104
#### `merge_node`
105
106
```python
107
def merge_node(
108
self,
109
label: str,
110
match_properties: dict,
111
set_properties: dict | None = None,
112
) -> str
113
```
114
115
Upsert a node: create it if no node with `match_properties` exists; otherwise update `set_properties` on the existing node.
116
117
**Parameters:**
118
119
| Name | Type | Default | Description |
120
|---|---|---|---|
121
| `label` | `str` | — | Node label |
122
| `match_properties` | `dict` | — | Properties to match on (identity key) |
123
| `set_properties` | `dict \| None` | `None` | Properties to set on create or update |
124
125
**Returns:** `str` — node ID
126
127
---
128
129
#### `create_edge`
130
131
```python
132
def create_edge(
133
self,
134
from_id: str,
135
to_id: str,
136
edge_type: str,
137
properties: dict | None = None,
138
) -> None
139
```
140
141
Create a directed edge between two nodes.
142
143
**Parameters:**
144
145
| Name | Type | Default | Description |
146
|---|---|---|---|
147
| `from_id` | `str` | — | Source node ID |
148
| `to_id` | `str` | — | Target node ID |
149
| `edge_type` | `str` | — | Relationship type (e.g., `"CALLS"`, `"ANNOTATES"`) |
150
| `properties` | `dict \| None` | `None` | Optional edge properties |
151
152
---
153
154
#### `merge_edge`
155
156
```python
157
def merge_edge(
158
self,
159
from_label: str,
160
from_match: dict,
161
to_label: str,
162
to_match: dict,
163
edge_type: str,
164
properties: dict | None = None,
165
) -> None
166
```
167
168
Upsert an edge between two nodes matched by label and properties.
169
170
---
171
172
#### `clear`
173
174
```python
175
def clear(self) -> None
176
```
177
178
Delete all nodes and edges from the graph.
179
180
---
181
182
#### `close`
183
184
```python
185
def close(self) -> None
186
```
187
188
Release the database connection. Called automatically when used as a context manager.
189
190
---
191
192
#### Context manager
193
194
`GraphStore` implements `__enter__` / `__exit__`. Use with `with` to ensure the connection is closed:
195
196
```python
197
with GraphStore.sqlite(".navegador/navegador.db") as store:
198
results = store.query("MATCH (n) RETURN count(n) AS total")
199
```
200
201
---
202
203
## ContextLoader
204
205
Builds structured context bundles from graph queries.
206
207
```python
208
class ContextLoader:
209
def __init__(self, store: GraphStore) -> None: ...
210
```
211
212
### Methods
213
214
#### `load_file`
215
216
```python
217
def load_file(self, path: str) -> ContextBundle
218
```
219
220
Return the full context bundle for a source file: the file node, its modules, classes, functions, imports, and their relationships.
221
222
**Parameters:**
223
224
| Name | Type | Description |
225
|---|---|---|
226
| `path` | `str` | Relative or absolute path to the source file |
227
228
**Returns:** `ContextBundle`
229
230
---
231
232
#### `load_function`
233
234
```python
235
def load_function(
236
self,
237
name: str,
238
*,
239
file: str = "",
240
depth: int = 1,
241
) -> ContextBundle
242
```
243
244
Return a function node with its callers, callees, decorators, containing class, and source.
245
246
**Parameters:**
247
248
| Name | Type | Default | Description |
249
|---|---|---|---|
250
| `name` | `str` | — | Function name |
251
| `file` | `str` | `""` | Optional file path to disambiguate |
252
| `depth` | `int` | `1` | Call graph traversal depth (1 = direct callers/callees only) |
253
254
**Returns:** `ContextBundle`
255
256
---
257
258
#### `load_class`
259
260
```python
261
def load_class(
262
self,
263
name: str,
264
*,
265
file: str = "",
266
) -> ContextBundle
267
```
268
269
Return a class node with its methods, base classes, subclasses, and references from other files.
270
271
**Parameters:**
272
273
| Name | Type | Default | Description |
274
|---|---|---|---|
275
| `name` | `str` | — | Class name |
276
| `file` | `str` | `""` | Optional file path to disambiguate |
277
278
**Returns:** `ContextBundle`
279
280
---
281
282
#### `explain`
283
284
```python
285
def explain(
286
self,
287
name: str,
288
*,
289
file: str = "",
290
) -> ContextBundle
291
```
292
293
Universal lookup: explain any node (function, class, file, concept, rule, decision) by name.
294
295
**Parameters:**
296
297
| Name | Type | Default | Description |
298
|---|---|---|---|
299
| `name` | `str` | — | Node name or file path |
300
| `file` | `str` | `""` | Optional file path to disambiguate code nodes |
301
302
**Returns:** `ContextBundle`
303
304
---
305
306
#### `load_concept`
307
308
```python
309
def load_concept(self, name: str) -> ContextBundle
310
```
311
312
Return a concept node with its rules, linked wiki pages, and annotated code nodes.
313
314
---
315
316
#### `load_domain`
317
318
```python
319
def load_domain(self, name: str) -> ContextBundle
320
```
321
322
Return a domain and all nodes belonging to it: concepts, rules, decisions, people, and annotated code.
323
324
---
325
326
#### `search`
327
328
```python
329
def search(
330
self,
331
query: str,
332
*,
333
all_layers: bool = False,
334
docs_only: bool = False,
335
limit: int = 20,
336
) -> list[ContextNode]
337
```
338
339
Search the graph by text query.
340
341
**Parameters:**
342
343
| Name | Type | Default | Description |
344
|---|---|---|---|
345
| `query` | `str` | — | Search string |
346
| `all_layers` | `bool` | `False` | Search all layers including knowledge and docs |
347
| `docs_only` | `bool` | `False` | Search docstrings and wiki content only |
348
| `limit` | `int` | `20` | Maximum number of results |
349
350
**Returns:** `list[ContextNode]`
351
352
---
353
354
#### `search_by_docstring`
355
356
```python
357
def search_by_docstring(self, query: str, *, limit: int = 20) -> list[ContextNode]
358
```
359
360
Search docstrings and wiki page content. Equivalent to `search(query, docs_only=True)`.
361
362
---
363
364
#### `decorated_by`
365
366
```python
367
def decorated_by(self, decorator: str) -> list[ContextNode]
368
```
369
370
Find all functions and classes that use a specific decorator.
371
372
**Parameters:**
373
374
| Name | Type | Description |
375
|---|---|---|
376
| `decorator` | `str` | Decorator name (e.g., `"login_required"`, `"pytest.mark.parametrize"`) |
377
378
**Returns:** `list[ContextNode]`
379
380
---
381
382
## ContextBundle
383
384
Structured result returned by `ContextLoader` methods.
385
386
```python
387
@dataclass
388
class ContextBundle:
389
root: ContextNode
390
nodes: list[ContextNode]
391
edges: list[ContextEdge]
392
metadata: dict
393
```
394
395
### Fields
396
397
| Field | Type | Description |
398
|---|---|---|
399
| `root` | `ContextNode` | The primary node (function, class, file, etc.) |
400
| `nodes` | `list[ContextNode]` | All nodes in the bundle, including `root` |
401
| `edges` | `list[ContextEdge]` | All edges between nodes in the bundle |
402
| `metadata` | `dict` | Query metadata (depth, timing, node counts) |
403
404
### Methods
405
406
#### `to_json`
407
408
```python
409
def to_json(self) -> str
410
```
411
412
Serialize the bundle to a JSON string.
413
414
#### `to_markdown`
415
416
```python
417
def to_markdown(self) -> str
418
```
419
420
Render the bundle as a Markdown string. Suitable for pasting into agent context.
421
422
#### `to_dict`
423
424
```python
425
def to_dict(self) -> dict
426
```
427
428
Return the bundle as a plain Python dict.
429
430
---
431
432
## ContextNode
433
434
A single node in a context bundle.
435
436
```python
437
@dataclass
438
class ContextNode:
439
id: str
440
label: str # e.g. "Function", "Concept"
441
name: str
442
properties: dict # all node properties from the graph
443
layer: str # "code" or "knowledge"
444
score: float # relevance score (search results only)
445
```
446
447
---
448
449
## ContextEdge
450
451
A relationship between two nodes in a context bundle.
452
453
```python
454
@dataclass
455
class ContextEdge:
456
from_id: str
457
to_id: str
458
edge_type: str # e.g. "CALLS", "ANNOTATES", "INHERITS"
459
properties: dict
460
```
461
462
---
463
464
## IngestionResult
465
466
Returned by all ingest methods.
467
468
```python
469
@dataclass
470
class IngestionResult:
471
nodes_created: int
472
nodes_updated: int
473
edges_created: int
474
files_processed: int
475
errors: list[str]
476
duration_seconds: float
477
```
478
479
| Field | Type | Description |
480
|---|---|---|
481
| `nodes_created` | `int` | New nodes written to the graph |
482
| `nodes_updated` | `int` | Existing nodes updated |
483
| `edges_created` | `int` | New edges written |
484
| `files_processed` | `int` | Source files walked |
485
| `errors` | `list[str]` | Per-file parse errors (non-fatal) |
486
| `duration_seconds` | `float` | Wall time for the ingest operation |
487

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button