codesigs

Extract function and method signatures from source code across multiple languages.

About codesigs

codesigs extracts function and method signatures from source code across over a dozen programming languages. It uses ast-grep for most languages and Python’s built-in ast module for Python files, providing accurate syntax-aware parsing rather than brittle regex matching.

This is useful for:

  • Documentation generation - quickly summarize the public API of a codebase
  • Code search and navigation - find functions by signature pattern
  • LLM context preparation - provide compact API summaries to language models without including full implementations
  • Codebase analysis - understand the structure of unfamiliar projects

Installation

Install latest from pypi

$ pip install codesigs

How to use

Pass source code to a language-specific function to get a list of signatures:

sigs = py_sigs("""
def greet(name, age=10):
    "Say hello to someone"
    return f"Hello {name}, you are {age}"

class Calculator:
    def add(self, a, b):
        return a + b
""")
for o in sigs: print(o)
def greet(name, age=10):
    "Say hello to someone" ...
class Calculator: ...
    def add(self, a, b): ...

Use ext_sigs when you have source code and know the file extension:

ext_sigs("function greet(name) { return `Hello ${name}`; }", ".js")
['function greet(name) {...}']

Or use file_sigs to read and extract signatures from a file in one step:

for o in file_sigs('../codesigs/core.py')[:5]: print(o)
def get_docstring(node, lines):
    "Get docstring from source lines if present" ...
def _node_sig(node, lines): ...
def py_sigs(src):
    "Extract class/function/method signatures from Python source" ...
    def _collect(nodes): ...
def _get_sigs(src, lang, kinds, name_kind, params_kind, fmt): ...

The package supports Python, JavaScript/TypeScript, Java, Rust, C#, CSS, Go, Ruby, PHP, Kotlin, Swift, and Lua. Each language has a dedicated function (e.g. js_sigs, rust_sigs), or use ext_sigs/file_sigs which auto-detect from the extension.