symbex  by simonw

CLI tool for Python code symbol extraction

created 2 years ago
299 stars

Top 90.0% on sourcepulse

GitHubView on GitHub
Project Summary

Symbex is a command-line tool for finding and extracting Python code for specific functions and classes. It's designed for developers and researchers who need to quickly locate, inspect, or programmatically manipulate Python source code, offering powerful filtering and integration with LLM workflows.

How It Works

Symbex parses Python files using the ast module to identify symbol definitions (functions, classes, methods). It supports flexible searching with exact names, wildcards, and class.method notation. The tool can search specified directories, files, or even the Python standard library. Its advantage lies in its granular filtering capabilities and its seamless integration with LLM tools for code explanation, embedding generation, and automated code modification.

Quick Start & Requirements

  • Install via pip: pip install symbex
  • Install via Homebrew: brew install simonw/llm/symbex
  • Requirements: Python 3.7+

Highlighted Details

  • Supports searching by symbol name, wildcards, and class.method notation.
  • Extensive filtering options: by type (function/class), async, documentation status, type annotations, and visibility (public/private).
  • Can output signatures only (-s), include docstrings (--docstrings), or provide import paths (-i).
  • Supports in-place code replacement (--replace) and command-based replacement (--rexec).
  • Integrates with LLM tools for code explanation and modification.
  • Offers structured output formats (CSV, TSV, JSON, newline-delimited JSON).
  • --check option for CI to fail if undocumented public symbols are found.

Maintenance & Community

The project is maintained by Simon Willison. Development dependencies are managed via pip install -e '.[test]' and tests can be run with pytest.

Licensing & Compatibility

The project is distributed under the MIT License, allowing for commercial use and integration with closed-source projects.

Limitations & Caveats

Symbex relies on Python's ast module, meaning it may encounter issues with syntactically incorrect Python code, though it can suppress warnings with --silent. The --replace and --rexec features modify files in-place and should be used with caution, preferably with version control.

Health Check
Last commit

3 months ago

Responsiveness

1+ week

Pull Requests (30d)
0
Issues (30d)
0
Star History
17 stars in the last 90 days

Explore Similar Projects

Feedback? Help us improve.