---
description: Generating a documentation index from a module
order: 5
output-file: doclinks.html
title: doclinks

---
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

## Create the module index

---

[source](https://github.com/AnswerDotAI/nbdev/blob/main/nbdev/doclinks.py#L31)

### 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])
s = "@patch\ndef _f(self:_T): ..."
test_eq('_T._f', _test_patch(s))
```

```python
s = "@patch_to(_T)\ndef _g(self): ..."
test_eq('_T._g', _test_patch(s))
```

```python
# Get all patched classes when patching with a union
s = "@patch\ndef _f(self:_T|_U|_V): ..."
test_eq(_test_patch(s), ['_T._f', '_U._f', '_V._f'])
```

```python
# _build_modidx()
```

## Export a notebook

---

[source](https://github.com/AnswerDotAI/nbdev/blob/main/nbdev/doclinks.py#L97)

### 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='nbs_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.*

---

[source](https://github.com/AnswerDotAI/nbdev/blob/main/nbdev/doclinks.py#L106)

### 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.*

---

[source](https://github.com/AnswerDotAI/nbdev/blob/main/nbdev/doclinks.py#L125)

### nbdev\_export

```python
def nbdev_export(
    path:str=None, # Path or filename
    procs:str='', # Space-separated `module:name` processors to use (or set `export_procs` in pyproject.toml)
    *, 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
):
```

*Export notebooks in `path` to Python modules*

## Construct Index

---

[source](https://github.com/AnswerDotAI/nbdev/blob/main/nbdev/doclinks.py#L149)

### create\_index

```python
def create_index(
    url, pre=None
):
```

*Create a documentation index from a sphinx inventory file at `url`, with optional prefix `pre`*

```python
url = 'https://docs.python.org/3'
syms = create_index(url)

for b in syms['builtins']:
    b = b.split('.')
    if len(b) != 2: continue
    b = b[1]
    assert b in bset

dict(list(syms['builtins'].items())[:10])
```

```output
<ipython-input-1-3feceb085160>:9: RemovedInSphinx10Warning: The tuple interface for _InventoryItem objects is deprecated. Please access the `project_name`, `project_version`, `uri`, and `displayname` attributes directly.
  _get = lambda o: {k:v[2] for k,v in idx[f'py:{o}'].items() if k[0]!='_'}
{'builtins.bool': 'https://docs.python.org/3/library/functions.html#bool',
 'builtins.bytearray': 'https://docs.python.org/3/library/stdtypes.html#bytearray',
 'builtins.bytes': 'https://docs.python.org/3/library/stdtypes.html#bytes',
 'builtins.complex': 'https://docs.python.org/3/library/functions.html#complex',
 'builtins.dict': 'https://docs.python.org/3/library/stdtypes.html#dict',
 'builtins.float': 'https://docs.python.org/3/library/functions.html#float',
 'builtins.frozenset': 'https://docs.python.org/3/library/stdtypes.html#frozenset',
 'builtins.int': 'https://docs.python.org/3/library/functions.html#int',
 'builtins.list': 'https://docs.python.org/3/library/stdtypes.html#list',
 'builtins.memoryview': 'https://docs.python.org/3/library/stdtypes.html#memoryview'}
```

## Query the module index

---

[source](https://github.com/AnswerDotAI/nbdev/blob/main/nbdev/doclinks.py#L167)

### NbdevLookup

```python
def NbdevLookup(
    strip_libs=None, # 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 docs and source URLs, defaulting `strip_libs` from nbdev config*

Indexing returns a link to the symbol's docs, along with the name of the source file the source URL if available.

```python
c = NbdevLookup()
c['nbdev.doclinks.NbdevLookup']
```

```output
('https://nbdev.fast.ai/api/doclinks.html#nbdevlookup',
 'nbdev/doclinks.py',
 'https://github.com/AnswerDotAI/nbdev/blob/main/nbdev/doclinks.py')
```

---

### DocLookup.doc

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

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

```python
c.doc('nbdev.doclinks.NbdevLookup')
```

```output
'https://nbdev.fast.ai/api/doclinks.html#nbdevlookup'
```

Symbol names are taken from libraries registered using the 'nbdev' entry point. By default, all libraries with this entry point are searched, but full symbol names (including module prefix) are required.

```python
assert c.doc('numpy.array').startswith('http')
assert not c.doc('numpy.Array')
assert c.doc('NbdevLookup').endswith('#nbdevlookup')
assert not c.doc('array')
```

Pass `strip_libs` to list libraries which should be available without requiring a module prefix.

```python
c = NbdevLookup(strip_libs=('nbdev', 'nbdev_numpy'))
assert c.doc('array').startswith('http')
```

---

### DocLookup.code

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

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

```python
NbdevLookup().code('fastcore.net.urlsend')
```

---

### DocLookup.linkify

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

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

````python
md = """This is a link to `numpy.array` and to `array()` and to `get_config()` but not a link to `foobar`.
And not a link to <code>dict2nb</code>.

    This is not a link to `get_config`

```
This isn't a link to `get_config` either
```"""
````

```python
print(NbdevLookup(('nbdev','numpy')).linkify(md))
```

````output
This is a link to [`numpy.array`](https://numpy.org/doc/stable/reference/generated/numpy.array.html#numpy.array) and to `array()` and to [`get_config()`](https://nbdev.fast.ai/api/config.html#get_config) but not a link to `foobar`.
And not a link to <code>dict2nb</code>.

    This is not a link to `get_config`

```
This isn't a link to `get_config` either
```
````

Explicit Markdown links keep their authored targets, including reference-style links. Only the unlinked symbol gets an automatic target:

```python
md = """An explicit [`NbdevLookup`](custom.html#details), [`NbdevLookup`][lookup], [`NbdevLookup`], and bare `NbdevLookup`.

[`NbdevLookup`]: shortcut.html
"""
lookup = NbdevLookup()
test_eq(lookup.linkify(md), md.replace('bare `NbdevLookup`', f'bare [`NbdevLookup`]({lookup.doc("NbdevLookup")})'))
```

`````python
# Test code blocks
md = """````markdown
```python
`NbdevLookup`
```
````
  ~~~python
`NbdevLookup`
  ~~~
    `NbdevLookup`
"""
assert NbdevLookup().linkify(md) == md
`````

```python
# Test builtins
md = "`builtins.str.split`"
NbdevLookup().linkify(md)
```

```output
'[`builtins.str.split`](https://docs.python.org/3/library/stdtypes.html#str.split)'
```

```python
# ... now with stripping
md = "`str.split` and `str`"
NbdevLookup('nbdev_stdlib').linkify(md)
```

```output
'[`str.split`](https://docs.python.org/3/library/stdtypes.html#str.split) and [`str`](https://docs.python.org/3/library/stdtypes.html#str)'
```

When there is a conflict, the linkification will apply in the order of the stripped libraries and then by alphabetical order. For example, `enumerate` is both a builtin and a function in the threading module. However, since builtins comes first alphabetically, it will take priority

```python
md = "`enumerate`, `builtins.enumerate` and `threading.enumerate`"
NbdevLookup(('nbdev_stdlib')).linkify(md)
```

```output
'[`enumerate`](https://docs.python.org/3/library/functions.html#enumerate), [`builtins.enumerate`](https://docs.python.org/3/library/functions.html#enumerate) and [`threading.enumerate`](https://docs.python.org/3/library/threading.html#threading.enumerate)'
```

We can also take the `find()` function as another instance, it exists as a standard library and in numpy. Therefore, depending on the order of stripped libraries we pass, `find()` will link to either numpy or standard library.

```python
md = "`find()`"
NbdevLookup(('nbdev_numpy','nbdev_stdlib')).linkify(md)
```

```output
'[`find()`](https://numpy.org/doc/stable/reference/generated/numpy.char.find.html#numpy.char.find)'
```

```python
md = "`find()`"
NbdevLookup(('nbdev_stdlib','nbdev_numpy')).linkify(md)
```

```output
'[`find()`](https://docs.python.org/3/library/gettext.html#gettext.find)'
```

You can also use NbdevLookup with import aliases like the following:

```python
import numpy as np
```

```python
NbdevLookup(ns=globals()).linkify('this is an aliased import link `np.array`')
```

```output
'this is an aliased import link [`np.array`](https://numpy.org/doc/stable/reference/generated/numpy.array.html#numpy.array)'
```
