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
- id: C1 claim: pyclbr reads source instead of importing, so untrusted code is safer. source: S1 evidence: "safe to use with untrusted code"
- id: C2 claim: readmodule maps top-level class names to descriptors. source: S1 evidence: "dictionary mapping module-level class names"
- id: C3 claim: readmodule is a compatibility wrapper around readmodule_ex. source: S1 evidence: "kept for back compatibility"
- id: C4 claim: Nested descriptors arrived in 3.7. source: S2 evidence: "Descriptors for nested definitions"
- id: C5 claim: is_async marks async functions and was added in 3.10. source: S1 evidence: "Added in version 3.10"
Sources
- [S1] pyclbr — Python module browser support. Python Software Foundation. https://docs.python.org/3/library/pyclbr.html . License: PSF License Version 2. Accessed 2026-11-27.
- [S2] pyclbr documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/pyclbr.rst . License: PSF License Version 2. Accessed 2026-11-27.
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
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.},
}
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.
- python-pyclbr.schema.json (schema; CC-BY-4.0)
- python-pyclbr.table.json (table; CC-BY-4.0)
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.