__all__ — Easy Examples
List of public names exported by a module with 'from module import *'
Accessing __all__
How to access and use __all__.
python
# __all__ controls what 'from module import *' exports # In a module, you would define: # __all__ = ["public_func", "PublicClass"] print("__all__ is typically defined at module level") print("It restricts star imports to listed names only") import math print(hasattr(math, "__all__"))
__all__ is a special attribute that list of public names exported by a module with 'from module import *'.
__all__ in practice
Using __all__ in everyday code.
python
# More __all__ examples print("__all__ is a special Python attribute") # Every object has certain dunder attributes obj = object() attrs = [a for a in dir(obj) if a.startswith("__")] print(f"object has {len(attrs)} dunder attributes")
Understanding __all__ helps you introspect and debug Python objects.
Want to try these examples interactively?
Open Easy Playground