The module and package names inform about the purpose of their content. The names are short, in lowercase, and without underscores:
sqlite
postgres
sha1
They are often suffixed with lib
if they are implementing a protocol:
import smtplib import urllib import telnetlib
They also need to be consistent within the namespace, so their usage is easier:
from widgets.stringwidgets import TextWidget # bad from widgets.strings import TextWidget # better
Again, always avoid using the same name as that of one of the modules from the standard library.
When a module is getting complex, and contains a lot of classes, it is good practice to create a package and split the module's elements in other modules.
The __init__
module can also be used to put back some APIs at the top level as it will not impact its usage, but will help with re-organizing the code into smaller parts. For example, consider the __init__
module in a foo
package with the following content:
from .module1 import...