---
title: Symbol links
description: Resolve and linkify backticked Python symbols across `fastship` and legacy
  `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=None, # Package names whose module prefixes are stripped for bare symbol lookups (defaults to current project)
    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 the site `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 resolved `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 fastship\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 | None, # `{section: items | {desc?, items?, Sub: ...}}`
)->pathlib._local.Path | None:
```

*Write `docs = ...` in `pkg/_modidx.py` when `docs` is non-empty; remove it otherwise.*

### nbglob

```python
def nbglob(
    path=None, # path to start searching
    skip_folder_re:str='^[_.]', # Skip folders matching regex,
    file_glob:str='*.ipynb', # Only include files matching glob
    skip_file_re:str='^[_.]', # Skip files matching regex
    key:str='ship_path', as_path:bool=False, *, recursive:bool=True, # search subfolders
    maxdepth:int=None, # max depth to descend (1=just immediate contents; None=unlimited)
    symlinks:bool=True, # follow symlinks?
    file_re:str=None, # Only include files matching regex
    path_glob:str=None, # Only include files whose full paths match glob (wildcards match separators)
    path_re:str=None, # Only include files whose full paths match regex
    folder_re:str=None, # Only enter folders matching regex
    skip_file_glob:str=None, # Skip files matching glob
    func:<built-in function callable>=walk_join, # function to apply to each matched file
    ret_folders:bool=False, # return folders, not just files
    sort:bool=True, # sort files by name within each folder
    types:str | list=None, # list or comma-separated str of ext types from: py, js, java, c, cpp, rb, r, ex, sh, web, doc, cfg
    exts:str | list=None, # list or comma-separated str of exts to include
): # Paths to matched files
```

*Find all files in a directory matching an extension given a config key.*

### nbglob\_cli

```python
def nbglob_cli(
    path:str=None, # Path to notebooks
    symlinks:bool=False, # Follow symlinks?
    file_glob:str='*.ipynb', # Only include files matching glob
    file_re:str=None, # Only include files matching regex
    path_glob:str=None, # Only include files whose full paths match glob (wildcards match separators)
    path_re:str=None, # Only include files whose full paths match regex
    folder_re:str=None, # Only enter folders matching regex
    skip_file_glob:str=None, # Skip files matching glob
    skip_file_re:str='^[_.]', # Skip files matching regex
    skip_folder_re:str='^[_.]', # Skip folders matching regex
):
```

*Find all files in a directory matching an extension given a config key.*

### patch\_name

```python
def patch_name(
    o
):
```

*If `o` is decorated with `patch` or `patch_to`, return its class-prefix name.*

````
```{python}
def _test_patch(code): return patch_name(parse_py(code).defs[0])
assert _test_patch("@patch
````

def \_f(self:\_T): ...") \=\= '\_T.\_f' assert \_test\_patch("@patch\_to(\_T) def \_g(self): ...") \=\= '\_T.\_g' assert \_test\_patch("@patch def \_f(self:\_T&#124;\_U&#124;\_V): ...") \=\= \['\_T.\_f', '\_U.\_f', '\_V.\_f'\] \`\`\`
