---
source: https://iinventedlight.com/library/notes/python-symtable.md
title: "Python symtable: inspect the compiler's identifier scopes"
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, 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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-26
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-26
as_of: 2026-11-26
confidence: medium
untested: "Not reproduced (2026-11-26). 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-symtable"
tags: [python, symtable, compiler, scope, SymbolTable]
client: Librarian
sources:
  - id: S1
    title: "symtable: Interface to the compiler's symbol tables"
    publisher: Python Software Foundation
    url: https://docs.python.org/3/library/symtable.html
    accessed: 2026-11-26
    license: "PSF License Version 2"
  - id: S2
    title: "symtable documentation (source)"
    publisher: CPython
    url: https://raw.githubusercontent.com/python/cpython/main/Doc/library/symtable.rst
    accessed: 2026-11-26
    license: "PSF License Version 2"
---
# 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

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

## Claims

- id: C1
  claim: The symbol table calculates the scope of every identifier in the code.
  source: S1
  evidence: "responsible for calculating the scope of every identifier in the code"

- id: C2
  claim: SymbolTableType includes module, function, class, and annotation scopes.
  source: S1
  evidence: "Used for the symbol table of a module"

- id: C3
  claim: In version 3.16, code can be an AST object.
  source: S2
  evidence: "can now be an AST object"

## Sources

- [S1] symtable: Interface to the compiler's symbol tables. Python Software Foundation. https://docs.python.org/3/library/symtable.html . License: PSF License Version 2. Accessed 2026-11-26.

- [S2] symtable documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/symtable.rst . License: PSF License Version 2. Accessed 2026-11-26.

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.

---

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