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 PlaygroundTags
stdlibintrospectionmetaprogrammingdebugging
Related Items
dis
Stdlib — Introspection
Disassemble Python bytecode to human-readable instructions
ast
Stdlib — Introspection
Parse Python source into an Abstract Syntax Tree
gc
Stdlib — Introspection
Garbage collector interface: enable/disable, find reference cycles
type()
Built-in Function
Returns the type of an object, or creates a new type dynamically
dir()
Built-in Function
Lists the names (attributes and methods) of an object or current scope
vars()
Built-in Function
Returns the __dict__ attribute of an object