I am not sure what they are for, I'll write my question towards the end of this post.
I have read the folowing 2 links on namespace packages:
https://docs.python.org/3/reference/import.html#namespace-packages
https://peps.python.org/pep-0420/
So if I tried to summarize my mental model of regular packages and namespace packages it is this:
1οΈβ£ Starting from the top-most directory, down to all its nested subdirectories. Python creates 1 package to correspond with every directory.
2οΈβ£ For some reason currently unknown to me, the person who wrote the documentation insists that we don't treat packages as directories. I don't want to bother thinking too deeply about that. I guess they just meant to say that python looks at a project's directory structure when making a decision of how many packages to create and what to call them.
3οΈβ£ If a directory contains an __init__.py file, it is a regular package. Otherwise it is a namespace package.
4οΈβ£ All distinct directories corresponding to the same namespace package (directories that share the same name in any directory that can be reached from one of the paths inside sys.path) have all their code mixed together into a package that is created on the spot.
5οΈβ£ This enables developers to use packages/modules located in directories not nested anywhere inside the top-most directory of their python project.
My tentative conclusion (mental model):
If we don't supply an init file in a directory (corresponding to a package), then we are telling Python to load the associated package from directories we list on sys.path.
Namespace packages are sort of virtual version of a package that can be either fetched from a directory that doesn't need to be nested in the top-most directory of a project, fetched from LAN or internet, or extracted from a compressed file.
What would be the incentive to use namespace package? What if two different directories share the same API? Does 1 get priority?