How do I get list of methods in a Python class?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Python provides several ways to list the methods of a class: dir() returns all attributes and methods (including inherited ones), inspect.getmembers() with inspect.ismethod or inspect.isfunction filters for callable methods, and vars() returns only attributes defined directly on the class (not inherited). For practical use, inspect.getmembers(cls, predicate=inspect.isfunction) is the most reliable approach for listing user-defined methods.
Method 1: dir()
dir() returns all attribute names (methods, properties, dunder methods, inherited attributes):
Filtering dir() for User-Defined Methods
Method 2: inspect.getmembers()
The inspect module provides filtered access to class members:
inspect.isfunction returns functions defined with def (including @staticmethod). inspect.ismethod returns bound methods (like @classmethod when inspecting the class).
Method 3: vars()
vars() returns the class's own __dict__, which contains only attributes defined directly in the class (not inherited):
Filtering vars() for Methods
Method 4: type.dict
Equivalent to vars() but works on any type:
Getting Method Signatures
Listing Methods on an Instance
Note: inspect.ismethod returns True for bound methods on instances, while inspect.isfunction returns True for unbound functions on classes.
Comparing Approaches
| Method | Inherited | Dunder | Properties | Use Case |
dir(cls) | Yes | Yes | Yes | Quick overview |
inspect.getmembers(cls, isfunction) | Yes | Yes | No | Filtered list of methods |
vars(cls) | No | Yes | Yes | Only directly defined |
cls.__dict__ | No | Yes | Yes | Same as vars() |
Common Pitfalls
dir()includes inherited methods and dunder methods:dir()returns everything —__init__,__str__, inherited methods, properties, and class variables. Always filter the result to get only the methods you care about.- Confusing
isfunctionandismethodininspect: On a class, user-defined methods show up as functions (isfunction). On an instance, they are bound methods (ismethod). The predicate you need depends on whether you inspect the class or an instance. vars()misses inherited methods:vars(Child)only shows attributes defined inChild, not those inherited fromBase. Usedir()orinspect.getmembers()if you need the complete method list including inherited methods.- Properties appearing as methods:
@propertydescriptors are not callable — they appear indir()but not withinspect.isfunction. Filtering withcallable(getattr(cls, name))incorrectly includes properties because they are accessible. - Dynamic methods not appearing: Methods added at runtime with
setattr()appear indir()andvars()on the instance but not on the class. Inspect the specific instance if methods may have been added dynamically.
Summary
- Use
dir(cls)for a quick list of all attributes, then filter withcallable()andnot m.startswith('_') - Use
inspect.getmembers(cls, inspect.isfunction)for a clean list of defined methods - Use
vars(cls)to see only methods defined directly on the class, excluding inherited ones - Use
inspect.signature()to get method parameters and type annotations isfunctionworks on classes,ismethodworks on instances — choose based on what you are inspecting

