inspect

Stdlib — IntrospectionPython 2.0+Advanced

Inspect live objects: source code, signatures, class hierarchies

Quick Info

Documentation
Official Docs
Python Version
2.0+
Dependencies
None — Python Standard Library
Install
Included with Python

Learn by Difficulty

Quick Example

python
import inspect

class Example:
    def method(self, x: int, y: str = "hello") -> bool:
        """An example method."""
        return True

sig = inspect.signature(Example.method)
print(f"Signature: {sig}")
for name, param in sig.parameters.items():
    print(f"  {name}: {param.kind.name}, default={param.default}")

The inspect module is part of Python's standard library. Inspect live objects: source code, signatures, class hierarchies.

Try in Playground

Tags

stdlibintrospectionmetaprogrammingdebugging

Related Items