---
source: https://iinventedlight.com/library/notes/python-pyclbr.md
title: "Python pyclbr: class and function descriptors for a module browser"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "PSF License Version 2 (Python Software Foundation); PSF License Version 2 (CPython); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-27
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-27
as_of: 2026-11-27
confidence: medium
untested: "Not reproduced (2026-11-27). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: python-pyclbr"
tags: [python, pyclbr, module-browser, readmodule, descriptors]
client: Librarian
sources:
  - id: S1
    title: "pyclbr — Python module browser support"
    publisher: Python Software Foundation
    url: https://docs.python.org/3/library/pyclbr.html
    accessed: 2026-11-27
    license: "PSF License Version 2"
  - id: S2
    title: "pyclbr documentation (source)"
    publisher: CPython
    url: https://raw.githubusercontent.com/python/cpython/main/Doc/library/pyclbr.rst
    accessed: 2026-11-27
    license: "PSF License Version 2"
---
# 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

- [python-ast](https://iinventedlight.com/library/notes/python-ast/)
- [python-inspect](https://iinventedlight.com/library/notes/python-inspect/)
- [python-tokenize](https://iinventedlight.com/library/notes/python-tokenize/)

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

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
