Skip to content

AnswerDotAI/codesigs

Repository files navigation

codesigs

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:

file_sigs('../codesigs/core.py')[:3]
['def get_docstring(node, lines):\n    "Get docstring from source lines if present" ...',
 'def _node_sig(node, lines): ...',
 'def py_sigs(src):\n    "Extract class/function/method signatures from Python source" ...']

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.

About

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

Resources

License

Stars

Watchers

Forks