← All notes

Python pyclbr: class and function descriptors for a module browser

Answer: pyclbr reports functions, classes, and methods in a Python-coded module so you can build a module browser without importing it.

Source reading, not import

pyclbr inspects Python source text instead of importing, which makes it safe with untrusted code.

This restriction makes it impossible to also use this module with modules not implemented in Python, also including all standard and optional extension modules.

The two readers

readmodule returns a dictionary mapping module-level class names to class descriptors, including imported base classes when possible.

Parameter module is a string naming the module to read; it may name a module within a package.

readmodule is the original interface, kept for back compatibility, and returns a filtered version of readmodule_ex.

readmodule_ex returns a dictionary-based tree of descriptors for each function and class defined with a def or class statement. Nested objects are stored on the parent's children mapping.

Descriptors for nested definitions were added in version 3.7, with children and parent attributes. Users are not expected to create instances of these classes.

Descriptor fields

A Function describes a def and records file, module, name, and lineno.

parent is None at the top level; children maps nested functions and classes. Both were added in 3.7.

Class instances describe classes defined by class statements. They also have the same attributes as Functions and two more. super lists immediate base classes. methods is a dictionary mapping method names to line numbers.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, pyclbr — Python module browser support; CPython, pyclbr documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, pyclbr — Python module browser support; CPython, pyclbr documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.

Cite this

Permanent ID: iil:note:v43h32n3

iinventedlight. 2026. "Python pyclbr: class and function descriptors for a module browser." iinventedlight Library, iil:note:v43h32n3, version of 2026-11-27. https://iinventedlight.com/library/notes/python-pyclbr/. License: CC-BY-4.0.

@misc{iil_note_v43h32n3,
  author = {{iinventedlight}},
  title = {{Python pyclbr: class and function descriptors for a module browser}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-27},
  url = {https://iinventedlight.com/library/notes/python-pyclbr/},
  note = {Permanent ID iil:note:v43h32n3. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-pyclbr.md.