Griffe

2.0.2 · active · verified Tue Mar 31

Griffe is a Python library (current version 2.0.2) that provides signatures for entire Python programs. It extracts the structure, frame, and skeleton of a project, enabling tasks like API documentation generation and detection of breaking API changes. The library maintains a regular release cadence, with frequent updates including bug fixes, features, and occasional deprecations or breaking changes between major versions.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `griffe.load` to extract API information from a Python module. It creates a temporary Python file, loads its structure into Griffe's data models, and then prints basic information about the extracted function and class.

import griffe
import os

# Create a dummy Python file for demonstration
with open('my_dummy_module.py', 'w') as f:
    f.write('def my_function(param1: str, param2: int = 0) -> str:\n    """A dummy function."""\n    return f"{param1}-{param2}"\n\nclass MyClass:\n    """A dummy class."""\n    def __init__(self, name: str):\n        self.name = name\n\n    def greet(self) -> str:\n        """Greets by name."""\n        return f"Hello, {self.name}"\n')

# Load the module's API data
# Griffe will try to find sources and fall back to introspection if not found
# Using the current directory as a search path
package = griffe.load("my_dummy_module", search_paths=['.'])

# Access a module, class, or function
print(f"Package name: {package.name}")

my_function = package["my_function"]
print(f"Function: {my_function.name}, Parameters: {[p.name for p in my_function.parameters]}")

my_class = package["MyClass"]
print(f"Class: {my_class.name}, Methods: {[m.name for m in my_class.members.values() if m.is_function]}")

# Clean up the dummy file
os.remove('my_dummy_module.py')

view raw JSON →