What does __all__ mean in Python?

In Python, __all__ is a list of strings that defines the names that should be imported when from <module> import * is used. For example:

__all__ = ['foo', 'bar']

def foo():

def bar():

def baz():

If someone writes from my_module import *, only foo and bar will be imported, because they are the only names listed in __all__. baz will not be imported, because it is not in __all__.

Watch a course Python - The Practical Guide

__all__ is often used as a way to specify which names should be publicly available when a module is imported using the * syntax. It is not required for a module to define __all__, but if it does not, then from <module> import * will import all names that do not begin with an underscore (_).