---
title: Symbol links
description: Resolve and linkify backticked Python symbols across `nbdev` entry points
  and live package indexes.
order: 7
---
[`DocLookup`](doclinks.md#doclookup) maps qualified or stripped symbol names to documentation URLs and GitHub source URLs, and linkifies backticked symbols in Markdown text while skipping code blocks and existing links. Use [`mod_syms`](doclinks.md#mod_syms), [`write_modidx`](doclinks.md#write_modidx), and [`write_pkg_docs`](doclinks.md#write_pkg_docs) to generate and persist `pkg/_modidx.py`.

```python
lk = DocLookup(extra={'demo.core': {'demo.core.foo': ('api/core.html#foo', 'demo/core.py')}})
assert lk.doc('foo') == '/api/core.html#foo'
assert lk.linkify('Call `foo` now.') == 'Call [`foo`](/api/core.html#foo) now.'
```

## DocLookup

```python
def DocLookup(
    strip_libs:tuple=(), # Package names whose module prefixes are stripped for bare symbol lookups
    incl_libs=None, # Optional package names to restrict entry-point loading to
    skip_mods=None, # Module names excluded when stripping prefixes
    ns:dict=None, # Optional namespace dict to resolve module import aliases (e.g. `np.array`)
    extra:dict=None, # Optional live `{mod: {sym: (doc_path, py_path)}}` mapping overriding installed entry points
    local_libs:tuple=(), # Package names whose doc links emit root-relative `/...` URLs for Octavo's `Linker`
):
```

*Mapping from symbol names to documentation and source URLs.*

### DocLookup.doc

```python
def doc(
    sym:str
)->str | None:
```

*Documentation URL for `sym`, or `None` if unknown.*

### DocLookup.code

```python
def code(
    sym:str
)->str | None:
```

*GitHub source URL for `sym` (appending `#L<line>` when source line is found).*

### DocLookup.link\_line

```python
def link_line(
    l:str
)->str:
```

*Linkify backticked symbols in a single line of Markdown.*

### DocLookup.linkify

```python
def linkify(
    md:str
)->str:
```

*Linkify backticked symbols in Markdown `md`, skipping fenced/indented code blocks and existing links.*

## Building and writing `_modidx.py`

Index public module symbols into `d = {'settings': ..., 'syms': ...}` and persist non-module `docs = ...` metadata in `pkg/_modidx.py`.

### mod\_syms

```python
def mod_syms(
    mod_pages:dict, # `{mod_nm: (page_html_rel, py_rel)}` mapping modules to their HTML page and source path
)->dict: # `{mod_nm: {qual_sym: (page_html#anchor, py_rel)}}`
```

*Build the `syms` index mapping public modules, classes, callables, and class members to doc anchors and source paths.*

### write\_modidx

```python
def write_modidx(
    pkg_dir:str | pathlib._local.Path, # Package directory where `_modidx.py` is written
    syms:dict, # `{mod_nm: {qual_sym: (page_html#anchor, py_rel)}}` from `mod_syms`
    settings:dict, # Dict with `doc_host`, `doc_baseurl`, `lib_path`, `git_url`, `branch`
    header:str='# Autogenerated by octavo\n', # File header when creating `_modidx.py`
)->pathlib._local.Path | None:
```

*Write `d = {'settings': ..., 'syms': ...}` in `pkg/_modidx.py` via `set_py_var`.*

### write\_pkg\_docs

```python
def write_pkg_docs(
    pkg_dir:str | pathlib._local.Path, # Package directory where `_modidx.py` is written
    docs:dict, # `{section: items | {desc?, items?, Sub: ...}}`
)->pathlib._local.Path | None:
```

*Write `docs = ...` in `pkg/_modidx.py` when `docs` has link tuples; remove it otherwise.*
