Introducing Symbex: A Tiny Python CLI Tool
Symbex is a tiny Python CLI tool for recursively searching for functions and classes by name or wildcard. Learn how it can be used to pipe code to an LLM for command-line code explanations and refactoring.
Simon Willison
Creator @datasetteproj, co-creator Django. PSF board. @nichemuseums. Hangs out with @natbat + @cleopaws. He/Him. Mastodon: https://t.co/t0Mrmo0Z2K
-
I just released symbex, a tiny Python CLI tool for recursively searching for functions and classes by name or wildcard
— Simon Willison (@simonw) June 18, 2023
It's mainly useful for finding code to pipe to my LLM tool for command-line code explanations and refactoringhttps://t.co/zxIpfCYfMn -
Being able to pipe code to an LLM in the terminal is really fun
— Simon Willison (@simonw) June 18, 2023
symbex Request | llm --system 'add type hints to this' pic.twitter.com/R7YUAoNes7 -
The hardest part of this project was picking a name for it!
— Simon Willison (@simonw) June 18, 2023
I ended up using ChatGPT Browse, since it could both read the README and then check ideas for names on PyPI to see if they were taken or not
I wrote about my process for that here: https://t.co/IiXcOSu84K pic.twitter.com/I3AfFqURwi -
symbex 0.2.1 is out with a couple of minor bug fixes https://t.co/VnE0J4yzRw
— Simon Willison (@simonw) June 19, 2023 -
I released symbex 0.3 with a couple of neat new features
— Simon Willison (@simonw) June 19, 2023
symbex 'test_*' --signatures (or -s) will display just matching signatures, not the whole body
symbex 'MyClass.method' can be used to find specific methods - or use wildcards like '*.get_*'https://t.co/9F8Ury241o -
OK, tearing myself away from this project now.
— Simon Willison (@simonw) June 19, 2023
0.4 fixes a bunch of issues - I can now run "symbex --signatures -d ~/Dev" and it processes over 300,000 function and class definitions in 2m30s without any errors (that's a whole lot of virtual environments) https://t.co/DdiHRSPoT4 pic.twitter.com/IEZWbYvYUH -
symbex 0.5 adds a --count option, plus filters that can select functions based on the presence or absence of type annotations.
— Simon Willison (@simonw) June 20, 2023
For example, this will give you a count of the number of async functions with type annotations:
symbex --async --typed --counthttps://t.co/P2a0YeAV4j pic.twitter.com/J6QJJNZZiA -
symbex 0.6 adds a new --docstrings option for showing just function/class signatures with their docstrings, plus --documented and --undocumented filters for showing only classes and functions that have docstrings or are lacking docstrings, respectivelyhttps://t.co/hClem1ELMy
— Simon Willison (@simonw) June 20, 2023 -
My llm, strip-tags, symbex and ttok commands can now all be installed using Homebrew (for people who don't habitually use pip and pipx) - details here:https://t.co/iiUD1HBRM7
— Simon Willison (@simonw) June 21, 2023 -
Here's my TIL on how to automatically maintain Homebrew formulas like that using GitHub Actions https://t.co/CPzTdCbEOx
— Simon Willison (@simonw) June 21, 2023 -
symbex 0.7 adds a whole host of extra features for more easily searching code in the Python standard library (using --stdlib) or in importable packages, using options like "-m pathlib" or "-m httpx"https://t.co/iuGnaPYklj pic.twitter.com/abSIJcuD0s
— Simon Willison (@simonw) June 23, 2023