← All notes

Python symtable: inspect the compiler's identifier scopes

Answer: The symtable module lets you inspect the compiler's symbol tables, which decide the scope of every identifier in the code.

What a symbol table records

The compiler builds symbol tables that calculate the scope of every identifier.

This module is the public interface for examining those tables.

SymbolTableType names the kinds of tables, including module, function, and class.

Other members cover annotation scopes, type aliases, and type parameters used by generic functions or generic classes.

The annotation kind is used when from __future__ import annotations is active.

Looking up names

A SymbolTable is a namespace table for a block.

get_name returns the class or function name, or top when the table is global and get_type returns module.

A Symbol is one entry in that table for an identifier in the source.

is_namespace is true when the name is the target of a function or class statement.

Version 3.15 added an optional module parameter used to filter syntax warnings by module name.

In version 3.16, the code argument can be an AST object.

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, symtable: Interface to the compiler's symbol tables; CPython, symtable 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, symtable: Interface to the compiler's symbol tables; CPython, symtable documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.

Cite this

Permanent ID: iil:note:k1pra2s4

iinventedlight. 2026. "Python symtable: inspect the compiler's identifier scopes." iinventedlight Library, iil:note:k1pra2s4, version of 2026-11-26. https://iinventedlight.com/library/notes/python-symtable/. License: CC-BY-4.0.

@misc{iil_note_k1pra2s4,
  author = {{iinventedlight}},
  title = {{Python symtable: inspect the compiler's identifier scopes}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-26},
  url = {https://iinventedlight.com/library/notes/python-symtable/},
  note = {Permanent ID iil:note:k1pra2s4. 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-symtable.md.