How is a package with an empty init.py file structured to give access to its modules when you import it? There's no particular structure necessary. If you have my_module containing __init__.py and my_submodule.py, then you can import import my_module.my_submodule with no additional work at all. Answer from Deleted User on reddit.com
🌐
Reddit
reddit.com › r/learnpython › can __init__.py actually be empty?
r/learnpython on Reddit: Can __init__.py actually be empty?
April 4, 2020 -

Many tutorials seem to imply that the typical __init__.py file in a package is empty. But this never works for me. Typically, I start a project by writing a series of .py modules in a directory. When I decide my project could be useful in other projects I'm working on, I try to turn it into a package by adding an empty __init__.py file. But when I try to import that package, I don't have access to any of the modules I wrote unless I import them in the __init__.py file.

Is this normal? How is a package with an empty __init__.py file structured to give access to its modules when you import it?

🌐
Quora
quora.com › In-Python-what-does-it-mean-when-a-class-has-no-init__
In Python, what does it mean when a class has no __init__? - Quora
Answer (1 of 5): It means that the __init__ method is inherited If you actually specified a parent class, then the __init__ of this parent class will be called If you didn't, it will use the object __init__ method, which doesn't do anything significant for you This behavior is the same as non-...
🌐
GitHub
github.com › pypa › packaging.python.org › issues › 1357 › linked_closing_reference
__init__ should not be empty · Issue #1292 · pypa/packaging.python.org
September 6, 2023 - In the webpage: https://packaging.python.org/en/latest/tutorials/packaging-projects/ was stated the following: "init.py is required to import the directory as a package, and should be empty." It did not work for me. Instead, when I wrote my methods in the init file as before then it worked.
Author   pypa
🌐
Reddit
reddit.com › r/learnpython › why have empty __init__.py files?
r/learnpython on Reddit: Why have empty __init__.py files?
July 10, 2023 -

I've been looking into some projects for some opensource software i use and noticed a few of them have empty __init__.py files (for example https://github.com/netbox-community/netbox/blob/develop/netbox/core/__init__.py)

Whats the point of these?

🌐
Arie Bovenberg
dev.arie.bovenberg.net › blog › still-use-init-py
init.py files are optional. Here’s why you should still use them | Arie Bovenberg
October 7, 2024 - What you might not know is that in modern Python, you can omit the __init__.py file and still be able to run the same import!
Find elsewhere
🌐
Quora
quora.com › What-is-the-use-of-file-init-PY-in-a-package-even-when-it-is-empty
What is the use of file __ init __ PY in a package even when it is empty? - Quora
Answer (1 of 2): A [code ]package/__init__.py[/code] file initializes the package on [code ]import package[/code]. For example, this file allows one to load a data cache into memory for the library to use. * Chapter 6. Modules & Packages - Python 3.9.1 documentation * Package Initialization – ...
🌐
Ansible
docs.ansible.com › ansible › latest › dev_guide › testing › sanity › empty-init.html
empty-init — Ansible Community Documentation
The __init__.py files under the following directories must be empty. For some of these (modules and tests), __init__.py files with code won’t be used. For others (module_utils), we want the possibility of using Python namespaces which an empty __init__.py will allow for.
🌐
Real Python
realpython.com › python-init-py
What Is Python's __init__.py For? – Real Python
June 11, 2023 - Click the Show/Hide toggle beside each question to reveal the answer. ... An empty __init__.py file indicates to Python that the directory is a regular package, allowing you to import modules from it.
🌐
LabEx
labex.io › questions › what-is-the-role-of-an-empty-init-py-994003
What is the role of an empty __init__.py? | LabEx
January 19, 2026 - Understand the essential role of an empty __init__.py file in Python. It marks directories as packages, enabling module imports and ensuring tooling compatibility, which is a best practice.
🌐
Python.org
discuss.python.org › python help
Issue with Module Import and Role of __init__.py in Python 3.9 - Python Help - Discussions on Python.org
Subject: Issue with Module Import and Role of __init__.py in Python 3.9 Dear Python Community, I’m currently facing an issue with module import in my Python project, and I’m hoping someone can help me understand the un…
Published   March 25, 2025
🌐
BeginnersBook
beginnersbook.com › 2018 › 03 › python-constructors-default-and-parameterized
Python Constructors – default and parameterized
March 10, 2018 - Example: When we do not declare a constructor In this example, we do not have a constructor but still we are able to create an object for the class. This is because there is a default constructor implicitly injected by python during program compilation, this is an empty default constructor that looks like this: def __init__(self): # no body, does nothing.
🌐
X
x.com › pamelafox › status › 1848427696449011900
Pamela Fox on X: "Nice short explanation of __init__.py files, and why you should use them to mark your importable modules: https://t.co/CvDAEsALQv" / X
Nice short explanation of __init__.py files, and why you should use them to mark your importable modules: ... If you’ve ever googled the question “Why do Python packages have empty __init__.py files?, you could get the idea that Python packages wouldn’t work without them.
🌐
StrataScratch
stratascratch.com › blog › what-is-the-purpose-of-__init__-in-python
What Is the Purpose of __init__ in Python? - StrataScratch
November 7, 2024 - This method stores arguments (name and age ) in self. name and self. age. When a new Person object is created, these attributes are automatically assigned to an empty state using the __init__ method.
Top answer
1 of 14
2111

It used to be a required part of a package (old, pre-3.3 "regular package", not newer 3.3+ "namespace package").

Here's the documentation.

Python defines two types of packages, regular packages and namespace packages. Regular packages are traditional packages as they existed in Python 3.2 and earlier. A regular package is typically implemented as a directory containing an __init__.py file. When a regular package is imported, this __init__.py file is implicitly executed, and the objects it defines are bound to names in the package’s namespace. The __init__.py file can contain the same Python code that any other module can contain, and Python will add some additional attributes to the module when it is imported.

But just click the link, it contains an example, more information, and an explanation of namespace packages, the kind of packages without __init__.py.

2 of 14
1357

Files named __init__.py are used to mark directories on disk as Python package directories. If you have the files

mydir/spam/__init__.py
mydir/spam/module.py

and mydir is on your path, you can import the code in module.py as

import spam.module

or

from spam import module

If you remove the __init__.py file, Python will no longer look for submodules inside that directory, so attempts to import the module will fail.

The __init__.py file is usually empty, but can be used to export selected portions of the package under more convenient name, hold convenience functions, etc. Given the example above, the contents of the init module can be accessed as

import spam

This answer is based on this webpage.

🌐
CodingNomads
codingnomads.com › creating-python-objects-from-classes
Python Classes, Objects and Instance Variables
The blueprint for your class constructor is Python's dunder init (__init__()) method. This method gets called when you're creating a new instance.