"I drew a chart of import dependencies, and I planned to aggregate classes by level level."
Python should read like English (or any other natural language.)
Import is a first-class operator that should have real meaning. The organization of things at the level level (whatever that may be) should be clear, meaningful and obvious.
Do not make arbitrary technical groupings of classes into modules and modules into packages.
Make modules and packages obvious and logical so that the import list is obvious, simple, and logical.
"In addition, I looked at some class modifications to reduce these dependencies.
Reducing dependencies sounds technically and arbitrary. It may not be so, but it sounds like that. It is impossible to say without real examples.
Your goal is clarity.
In addition, the module and package are self-contained reuse blocks. (Not classes, class, but by itself is usually not reused). The dependency tree should reflect this. You are targeting modules that you can import neatly and cleanly into your application.
If you have many closely related modules (or alternative implementations), then packages can be used, but are used sparingly. Python libraries are relatively flat; and there is some kind of wisdom.
Edit
The one-way relationship between layers is an important feature. This is more about proper software design than Python. You must (1) design in layers, (2) design so that the dependencies are very strict between the layers, and then (3) implement this in Python.
Packages may not necessarily match your location. Packages can physically be a flat list of directories with dependencies expressed only through import statements.
S. Lott
source share