---
name: write_node_ids
kind: function
lang: py
domain: core
version: "1.0.0"
purity: pure
signature: "def write_node_ids(data: Any, node_id: int = 0) -> int"
description: "Asigna IDs secuenciales zero-padded (0001, 0002...) a todos los nodos de un arbol. Retorna siguiente contador."
tags: [tree, id, hierarchy, mutation, pendiente-usar]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: ""
imports: []
params:
  - name: data
    desc: "Estructura árbol a la que añadir IDs"
  - name: node_id
    desc: "Contador inicial para los IDs (default: 0)"
output: "Próximo contador a usar después de asignar IDs"
tested: false
tests: []
test_file_path: ""
file_path: "python/functions/core/core.py"
source_repo: "https://github.com/VectifyAI/PageIndex"
source_license: "MIT"
source_file: "pageindex/utils.py"
---

## Ejemplo

```python
tree = [{"title": "A", "nodes": [{"title": "B", "nodes": []}]}]
next_id = write_node_ids(tree)
# tree[0]["node_id"] == "0000", tree[0]["nodes"][0]["node_id"] == "0001"
# next_id == 2
```

## Notas

Funcion pura en el sentido de no tener I/O, pero muta el arbol de entrada in-place. IDs son strings de 4 digitos.
