How you structure you package depends on how it is to be used. There are several cases:
(1) You package contains many different loosely related classes which can be used separately. In this case you should create submodules (or even subpackages) so that user uses import package.thing
or import package.another
.
(2) Your package must always work together as a single program. In that case, it makes sense to write a "public interface" so that user can do
import package
package.Thing().work() ...
package.do_something()
After you finalize public interface, how you structure your package should be an implementation detail and you are free to create several files without changing the public interface, e.g.
# _thing.py
"Implementation of Thing. Don't import this file --- use main package instead."
class Thing: ...
# __init__.py
from ._thing import Thing
It's still best not to declare anything in the __init__.py
since it's harder to unittest. However, you might not know in the beginning how you want your files to be organized. In that case I would first write a dummy __init__.py
with all the empty classes and then move them one by one into other files as I fill them in.
(3)
It's not hard to see that the most practical is a middle way where you structure your package into separate files but also import the most useful classes and functions in the __init__.py
. User will have the choice of importing the main namespace or directly a submodule --- yes, that's redundant, but "practicality beats purity".