Griffe

raw JSON →
2.0.2 verified Tue May 12 auth: no python install: verified

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.

pip install griffe
error ModuleNotFoundError: No module named 'griffe.enumerations'
cause The `griffe.enumerations` module was removed in `griffe` 1.x as part of breaking changes to the library's API.
fix
Downgrade griffe to a version prior to the breaking change (e.g., pip install griffe==0.48) or update your code to use the current API of griffe if an alternative exists.
error ModuleNotFoundError: No module named 'griffe.dataclasses'
cause This error often occurs when a project relies on an older structure of `griffe`, specifically `griffe.dataclasses`, which was refactored or removed in `griffe` 1.0.0 and subsequent versions.
fix
Pin griffe to a compatible version for your project or its dependencies (e.g., pip install 'griffe<1.0.0' or griffe==0.48) or update your project's code to align with griffe's current API.
error ModuleNotFoundError: No module named 'griffe'
cause The `griffe` library is not installed in the Python environment where the code is being executed.
fix
Install the griffe package using your package manager (e.g., pip install griffe).
error griffe._internal.exceptions.AliasResolutionError: Could not resolve alias ...
cause `griffe` encountered an alias it could not resolve, often due to the use of wildcard imports (`from module import *`), undeclared `__all__` variables, or name shadowing between modules and members.
fix
To fix this, avoid wildcard imports, explicitly define __all__ in your modules to declare the public API, and prevent name shadowing where a module and a member within its parent package share the same name.
breaking Version 2.0.0 removed several previously deprecated public APIs, including `ExportedName`, `infer_docstring_style`, `parse_auto`, `parse_google`, `parse_numpy`, `parse_sphinx`, `assert_git_repo`, `get_latest_tag`, `get_repo_root`, and `tmp_worktree`.
fix Review the 2.0.0 changelog for a complete list of removed APIs. Replace usage of these deprecated functions/objects with their current equivalents, or remove dependencies on them.
deprecated The signature of the `on_alias` event changed in version 1.14.0. It changed from `on_alias(self, *, node: AST | ObjectNode, alias: Alias, agent: Visitor | Inspector, **kwargs)` (an analysis event) to `on_alias(self, *, alias: Alias, loader: GriffeLoader, **kwargs)` (a load event).
fix Update custom handlers or extensions that interact with the `on_alias` event to match the new signature `on_alias(self, *, alias: Alias, loader: GriffeLoader, **kwargs)`.
gotcha Internal packages and modules, particularly those starting with an underscore (e.g., `_griffe`), may be refactored or moved without prior deprecation. Version 1.11.1 moved the private `_griffe` package under `griffe._internal`.
fix Avoid importing from or relying on undocumented internal modules or packages. Stick to the public API exposed directly under the `griffe` top-level module to ensure forward compatibility. If you must use internals, pin your `griffe` version tightly.
pip install griffe[pypi]
python os / libc variant status wheel install import disk mem side effects
3.10 alpine (musl) griffe wheel - 0.18s 19.4M 5.6M clean
3.10 alpine (musl) griffe - - 0.20s 19.4M 5.6M -
3.10 alpine (musl) pypi wheel - 0.17s 18.4M 5.6M clean
3.10 alpine (musl) pypi - - 0.20s 18.2M 5.6M -
3.10 slim (glibc) griffe wheel 1.7s 0.14s 20M 6.5M clean
3.10 slim (glibc) griffe - - 0.14s 20M 6.5M -
3.10 slim (glibc) pypi wheel 2.9s 0.13s 19M 6.5M clean
3.10 slim (glibc) pypi - - 0.14s 19M 6.5M -
3.11 alpine (musl) griffe wheel - 0.32s 21.6M 6.8M clean
3.11 alpine (musl) griffe - - 0.38s 21.6M 6.8M -
3.11 alpine (musl) pypi wheel - 0.31s 21.9M 6.8M clean
3.11 alpine (musl) pypi - - 0.40s 21.9M 6.8M -
3.11 slim (glibc) griffe wheel 1.8s 0.29s 22M 7.6M clean
3.11 slim (glibc) griffe - - 0.29s 22M 7.6M -
3.11 slim (glibc) pypi wheel 1.9s 0.29s 22M 7.6M clean
3.11 slim (glibc) pypi - - 0.29s 22M 7.6M -
3.12 alpine (musl) griffe wheel - 0.25s 13.4M 6.4M clean
3.12 alpine (musl) griffe - - 0.37s 13.4M 6.4M -
3.12 alpine (musl) pypi wheel - 0.25s 14.9M 6.4M clean
3.12 alpine (musl) pypi - - 0.29s 14.6M 6.4M -
3.12 slim (glibc) griffe wheel 1.6s 0.28s 14M 7.4M clean
3.12 slim (glibc) griffe - - 0.30s 14M 7.4M -
3.12 slim (glibc) pypi wheel 1.8s 0.30s 15M 7.4M clean
3.12 slim (glibc) pypi - - 0.29s 15M 7.4M -
3.13 alpine (musl) griffe wheel - 0.25s 13.1M 7.1M clean
3.13 alpine (musl) griffe - - 0.27s 13.0M 7.1M -
3.13 alpine (musl) pypi wheel - 0.24s 14.6M 7.1M clean
3.13 alpine (musl) pypi - - 0.27s 14.3M 7.1M -
3.13 slim (glibc) griffe wheel 1.6s 0.25s 14M 8.0M clean
3.13 slim (glibc) griffe - - 0.28s 14M 8.0M -
3.13 slim (glibc) pypi wheel 1.9s 0.26s 15M 8.0M clean
3.13 slim (glibc) pypi - - 0.29s 15M 8.0M -
3.9 alpine (musl) griffe wheel - 0.17s 18.8M 6.1M clean
3.9 alpine (musl) griffe - - 0.20s 18.8M 6.1M -
3.9 alpine (musl) pypi wheel - 0.18s 18.8M 6.1M clean
3.9 alpine (musl) pypi - - 0.21s 18.8M 6.1M -
3.9 slim (glibc) griffe wheel 1.9s 0.16s 19M 6.5M clean
3.9 slim (glibc) griffe - - 0.18s 19M 6.5M -
3.9 slim (glibc) pypi wheel 1.9s 0.16s 19M 6.5M clean
3.9 slim (glibc) pypi - - 0.17s 19M 6.5M -

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')