Skip to main content

ast-explore

Tool for exploring the AST of given Python source code.

Installation

This package is available on PyPI. To use it, you can either install with pip:

pip install ast-explore

or use it with uv directly:

uvx ast-explore --help

Usage

At a minimum, you must provide a Python file to analyze:

# previously-installed with pip:
ast-explore source_code.py

# with uv:
uvx ast-explore source_code.py

This will extract all possible data points from every node in the AST generated from that source code and print it to the screen. You may wish to pipe the results to a file or less to process.

Here's a partial example of the output:

📖 Reading Python source code from /.../source_code.py...
🔍 Parsing into a Python 3.14 AST...
✅ Ready to explore the AST! Starting depth-first traversal...

********************************************************************************
**    1. Module (https://docs.python.org/3.14/library/ast.html#ast.Module)    **
********************************************************************************

🌲 Path to this node from the root node of the AST:
   Module

📍 This node type does not have any line number information.

📝 Docstring is missing.

✨ AST node-specific fields and their values:
   - body         : [FunctionDef(n...ype_params=[])]
   - type_ignores : []

********************************************************************************
 2. FunctionDef (https://docs.python.org/3.14/library/ast.html#ast.FunctionDef)
********************************************************************************

🌲 Path to this node from the root node of the AST:
   Module -> FunctionDef

🐍 Source code represented by the node:
   1 | def strip_password(x: dict[str, str]) -> None:
   2 |     try:
   3 |         del x['password']
   4 |     except KeyError:
   5 |         pass

📍 Location in the source code:
   - lineno         : 1
   - end_lineno     : 5
   - col_offset     : 0
   - end_col_offset : 12

📝 Docstring is missing.

✨ AST node-specific fields and their values:
   - name           : 'strip_password'
   - args           : arguments(pos..., defaults=[])
   - body           : [Try(body=[Del... finalbody=[])]
   - decorator_list : []
   - returns        : Constant(value...ne, kind=None)
   - type_comment   : None
   - type_params    : []

********************************************************************************
   3. arguments (https://docs.python.org/3.14/library/ast.html#ast.arguments)
********************************************************************************

🌲 Path to this node from the root node of the AST:
   Module -> FunctionDef -> arguments

📍 This node type does not have any line number information.

✨ AST node-specific fields and their values:
   - posonlyargs : []
   - args        : [arg(arg='x', ..._comment=None)]
   - vararg      : None
   - kwonlyargs  : []
   - kw_defaults : []
   - kwarg       : None
   - defaults    : []

********************************************************************************
**       4. arg (https://docs.python.org/3.14/library/ast.html#ast.arg)       **
********************************************************************************

🌲 Path to this node from the root node of the AST:
   Module -> FunctionDef -> arguments -> arg

🐍 Source code represented by the node:
   1 | def strip_password(x: dict[str, str]) -> None:
     |                    ^^^^^^^^^^^^^^^^^

📍 Location in the source code:
   - lineno         : 1
   - end_lineno     : 1
   - col_offset     : 19
   - end_col_offset : 36

✨ AST node-specific fields and their values:
   - arg          : 'x'
   - annotation   : Subscript(val...), ctx=Load())
   - type_comment : None

Specifying nodes of interest

Use the --types argument to list the nodes you want to explore and only information about those nodes will be shown. Here, we only care about function definition nodes:

# previously-installed with pip:
ast-explore source_code.py --types FunctionDef AsyncFunctionDef

# with uv:
uvx ast-explore source_code.py --types FunctionDef AsyncFunctionDef

Here's an example of the result (there are no async functions in the file analyzed):

📖 Reading Python source code from /.../source-code.py...
🔍 Parsing into a Python 3.14 AST...
✅ Ready to explore the AST! Starting depth-first traversal...

********************************************************************************
 1. FunctionDef (https://docs.python.org/3.14/library/ast.html#ast.FunctionDef)
********************************************************************************

🌲 Path to this node from the root node of the AST:
   Module -> FunctionDef

🐍 Source code represented by the node:
   1 | def strip_password(x: dict[str, str]) -> None:
   2 |     try:
   3 |         del x['password']
   4 |     except KeyError:
   5 |         pass

📍 Location in the source code:
   - lineno         : 1
   - end_lineno     : 5
   - col_offset     : 0
   - end_col_offset : 12

📝 Docstring is missing.

✨ AST node-specific fields and their values:
   - name           : 'strip_password'
   - args           : arguments(pos..., defaults=[])
   - body           : [Try(body=[Del... finalbody=[])]
   - decorator_list : []
   - returns        : Constant(value...ne, kind=None)
   - type_comment   : None
   - type_params    : []

********************************************************************************

🏆 Traversal completed!

Interactive mode

Use interactive mode to step through the AST one node at a time:

# previously-installed with pip:
ast-explore source_code.py --interactive

# with uv:
uvx ast-explore source_code.py --interactive

Here's what that looks like:

📖 Reading Python source code from /.../source_code.py...
🔍 Parsing into a Python 3.14 AST...
✅ Ready to explore the AST! Starting depth-first traversal...

********************************************************************************
**    1. Module (https://docs.python.org/3.14/library/ast.html#ast.Module)    **
********************************************************************************

🌲 Path to this node from the root node of the AST:
   Module

📍 This node type does not have any line number information.

❓ Do you want more information on this node? [y]es [n]o [q]uit:

Of course, you can combine --interactive with --types/--skip to customize your exploration. Here, we interactively visit all try blocks:

# previously-installed with pip:
ast-explore source_code.py --interactive --types Try

# with uv:
uvx ast-explore source_code.py --interactive --types Try

Note that the first node we encounter is now the ast.Try node and not the ast.Module node we saw without specifying --types:

📖 Reading Python source code from /.../source_code.py...
🔍 Parsing into a Python 3.14 AST...
✅ Ready to explore the AST! Starting depth-first traversal...

********************************************************************************
**       1. Try (https://docs.python.org/3.14/library/ast.html#ast.Try)       **
********************************************************************************

🌲 Path to this node from the root node of the AST:
   Module -> FunctionDef -> Try

🐍 Source code represented by the node:
   2 |     try:
   3 |         del x['password']
   4 |     except KeyError:
   5 |         pass

❓ Show location fields? [y]es [n]o [q]uit: y

📍 Location in the source code:
   - lineno         : 2
   - end_lineno     : 5
   - col_offset     : 4
   - end_col_offset : 12

❓ Do you want more information on this node? [y]es [n]o [q]uit: y

✨ AST node-specific fields and their values:
   - body      : [Delete(target..., ctx=Del())])]
   - handlers  : [ExceptHandler...body=[Pass()])]
   - orelse    : []
   - finalbody : []

❓ Continue traversal? [y]es [n]o [q]uit:

Metadata

Release files for ast-explore 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ast-explore 0.2.1
File Size Uploaded
ast_explore-0.2.1.tar.gz 41.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ast-explore 0.2.1
File Interpreter ABI Platform
ast_explore-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 58.9 kB

Release files / ast_explore-0.2.1.tar.gz

Download URL ast_explore-0.2.1.tar.gz
Size 41.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0f9638ed83c046a37cf9ecc046aef4f45ea3f6eed9d5accac0d654d1fce2f6e0
BLAKE2b-256 checksum
How to use checksums
ceda24884431271e480bb501cc56c0a64beb324b4ccdeead5c3a656dbae5f85a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 13, 2026.

Transparency log

Release files / ast_explore-0.2.1-py3-none-any.whl

Download URL ast_explore-0.2.1-py3-none-any.whl
Size 17.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3879da8ef2d398d9167127af7fde249951232f83f90d52143ac1d861db4f5a40
BLAKE2b-256 checksum
How to use checksums
9dff44c5e106f224510c606d85b281ac71efb9ae29e378b30a35518b8bbc86b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 13, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page