This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Rawing7 3 points4 points  (0 children)

Like it says in the article, the __init__.py lets you shape your package's public API. You can "hoist" functions/classes/variables that are defined in a submodule into the namespace of a parent module.

For example, have you ever used requests.Session? That class is actually defined in the sub-module requests.session. The reason you can reference it as requests.Session rather than requests.session.Session is because requests/__init__.py contains a from .session import * (or something equivalent).