Package: auto-all
auto-allAutomatically manage the__all__variable in Python modules.Overviewauto_allcan be used for controlling what is made available
for import from a Python module.Advantages:Easily populate the__all__variable in modules.Easily exclude imported objectsClearly differentiate between internal and external facing objects.Use simple, intuitive code.Never worry about forgetting to add new objects to__all__.Help Python IDE’s differentiate between internal and external facing objects.Installationpipinstallauto-allUsageThere are two main approaches:1) Use `start_all` and `end_all` to wrap all public functions and
   variables.
2) Use the `@public` decorator to identify publicly facing functions.start_all/end_all approachFirst, import the auto_all functions into your module.fromauto_allimportstart_all,end_allIf your module has external dependencies then these can be imported
and the imported objects can be hidden.  In this example we will import
pathlib.Path and show that it doesn’t appear on the__all__list.
We’re not actually going to use this import, it’s just for illustration.frompathlibimportPathNow we can define some internal functions that we want to keep private.
We can also do this using underscore prefixes, butauto_allgives us a
little more granular control.defa_private_function():print("This is a private function.")Now we are ready to start defining public functions, so we usestart_all().start_all()Now we can define our public functions.defa_public_function():print("This is a public function.")Finally we useend_all()to finish defining public functions and
create the__all__variable.end_all()When we look at the__all__variable we can see only the public
facing objects are listed.>>> print(__all__)
['a_public_function']Putting this all together, your module should look something like this:fromauto_allimportstart_all,end_allfrompathlibimportPathdefa_private_function():print("This is a private function.")start_all()defa_public_function():print("This is a public function.")end_all()It is possible to pass the globals dict to thestart_allandend_allfunction calls. This is not typically necessary, and is
only included for backward compatibility.start_all(globals())defanother_public_function():passend_all(globals())defa_private_function():passprint(__all__)@publicdecorator approachThe second approach is to use the@publicdecorator. Note that this
approach is only suitable for functions, and will not work for declaring
classes or variables as public.First, import the decorator:fromauto_allimportpublicWe can define any private functions without any decorator:defa_private_function():passWe can define public functions by decorating with the@publicdecorator:@publicdefa_public_function():passThe__all__variable will only include functions that have been
declared as public:>>> print(__all__)
['a_public_function']Combining the two approachesIn the event that you need to declare variables and classes as public, and
also want to make use of the@publicdecorator for functions you can
combine both methods.Private variables can be defined outside the start/end block:PRIVATE_VARIABLE="I am private"Public items can be defined between thestart_all()andend_all()function calls:start_all()PUBLIC_VARIABLE="I am public"classPublicClass:passend_all()Private functions can be defined undecorated outside the start/end block:defprivate_function():passPublic functions can be decorated with the@publicdecorator:@publicdefpublic_function():passThe__all__variable will include any object declared between thestart_allandend_allcalls, and any function decorated with the@publicdecorator:>>> print(__all__)
['PUBLIC_VARIABLE', 'PublicClass', 'public_function']