<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/init-py-explained-in-just-7-minutes-beginner-tutorial--nrpztnirg" -->

---
title: "__init__.py" Explained in Just 7 minutes (Beginner...
description: A beginner-friendly explanation of what __init__.py does in Python. Covers how it marks a regular folder as a Python package, how it runs automatically on...
canonical: https://daily.dev/posts/init-py-explained-in-just-7-minutes-beginner-tutorial--nrpztnirg
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: "__init__.py" Explained in Just 7 minutes (Beginner Tutorial) | daily.dev
og:description: A beginner-friendly explanation of what __init__.py does in Python. Covers how it marks a regular folder as a Python package, how it runs automatically on...
og:url: https://daily.dev/posts/init-py-explained-in-just-7-minutes-beginner-tutorial--nrpztnirg
og:image: https://api.daily.dev/og/posts/NRpZtniRg.png
og:image:alt: "__init__.py" Explained in Just 7 minutes (Beginner Tutorial)
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# "__init__.py" Explained in Just 7 minutes (Beginner Tutorial)

**[Indently](https://daily.dev/sources/indently)** · 6 min read · 6 upvotes · 0 comments

## Summary

A beginner-friendly explanation of what __init__.py does in Python. Covers how it marks a regular folder as a Python package, how it runs automatically on import for initialization logic, how to use __all__ to control star imports, and how to simplify deeply nested module imports by creating aliases in __init__.py.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.youtube.com/watch?v=xn7nZLWXYSg>

## Questions this post answers

### What does __init__.py do in a Python package?

It marks a regular folder as a Python package and runs automatically every time that package is imported, making it useful for initialization logic. Without it, a folder is just a directory, not a package Python recognizes. You can leave it empty or add setup code, imports, or aliases inside it.

_Developers structuring Python projects can revisit package fundamentals like this on daily.dev._

### How do I control what gets imported with a star import from a Python package?

Define a list named __all__ inside __init__.py containing the names of the modules or attributes you want exposed. Anything left out of __all__ will not be included when someone uses a star import (from package import *) against that package, letting you limit what gets pulled in.

_Anyone tuning package exports in Python can dig deeper into import behavior via daily.dev._

### How can I simplify imports for a deeply nested Python module?

Add an import alias inside the package's __init__.py, for example from a.b.c import pizza, so users can write from food_package import pizza instead of typing out the full nested path. Include the imported name in __all__ too, so linters don't flag it as an unused import.

_Developers cleaning up nested package imports can find more Python packaging tips on daily.dev._

## Similar posts on daily.dev

- [.py Do? – Real Python](https://daily.dev/posts/py-do-real-python-f87ns34ep) · Real Python · 0 upvotes · 0 comments
- [Managing Imports With Python's](https://daily.dev/posts/managing-imports-with-python-s-pyw4xgkat) · Real Python · 4 upvotes · 0 comments

---

Tags: [#python](https://daily.dev/tags/python)

[View this post on daily.dev](https://daily.dev/posts/init-py-explained-in-just-7-minutes-beginner-tutorial--nrpztnirg)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"\"__init__.py\" Explained in Just 7 minutes (Beginner Tutorial)","url":"https://daily.dev/posts/init-py-explained-in-just-7-minutes-beginner-tutorial--nrpztnirg","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/init-py-explained-in-just-7-minutes-beginner-tutorial--nrpztnirg"},"datePublished":"2026-08-02T16:08:34.779Z","dateModified":"2026-09-14T07:04:54.816Z","description":"A beginner-friendly explanation of what __init__.py does in Python. Covers how it marks a regular folder as a Python package, how it runs automatically on...","image":"https://i.ytimg.com/vi/xn7nZLWXYSg/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/xn7nZLWXYSg/sddefault.jpg","isAccessibleForFree":true,"articleSection":"Indently","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Indently","logo":"https://media.daily.dev/image/upload/s--u6wAXJI9--/f_auto/v1725038127/logos/indently","url":"https://daily.dev/sources/indently"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/init-py-explained-in-just-7-minutes-beginner-tutorial--nrpztnirg","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":6},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"python","timeRequired":"PT6M","video":{"@type":"VideoObject","name":"\"__init__.py\" Explained in Just 7 minutes (Beginner Tutorial)","description":"A beginner-friendly explanation of what __init__.py does in Python. Covers how it marks a regular folder as a Python package, how it runs automatically on...","thumbnailUrl":"https://i.ytimg.com/vi/xn7nZLWXYSg/sddefault.jpg","uploadDate":"2026-08-02T16:08:34.779Z","duration":"PT6M","url":"https://api.daily.dev/r/NRpZtniRg","embedUrl":"https://www.youtube.com/embed/xn7nZLWXYSg"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Indently","item":"https://daily.dev/sources/indently"},{"@type":"ListItem","position":3,"name":"\"__init__.py\" Explained in Just 7 minutes (Beginner Tutorial)"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/init-py-explained-in-just-7-minutes-beginner-tutorial--nrpztnirg#faq","mainEntity":[{"@type":"Question","name":"What does __init__.py do in a Python package?","acceptedAnswer":{"@type":"Answer","text":"It marks a regular folder as a Python package and runs automatically every time that package is imported, making it useful for initialization logic. Without it, a folder is just a directory, not a package Python recognizes. You can leave it empty or add setup code, imports, or aliases inside it. Developers structuring Python projects can revisit package fundamentals like this on daily.dev."}},{"@type":"Question","name":"How do I control what gets imported with a star import from a Python package?","acceptedAnswer":{"@type":"Answer","text":"Define a list named __all__ inside __init__.py containing the names of the modules or attributes you want exposed. Anything left out of __all__ will not be included when someone uses a star import (from package import *) against that package, letting you limit what gets pulled in. Anyone tuning package exports in Python can dig deeper into import behavior via daily.dev."}},{"@type":"Question","name":"How can I simplify imports for a deeply nested Python module?","acceptedAnswer":{"@type":"Answer","text":"Add an import alias inside the package's __init__.py, for example from a.b.c import pizza, so users can write from food_package import pizza instead of typing out the full nested path. Include the imported name in __all__ too, so linters don't flag it as an unused import. Developers cleaning up nested package imports can find more Python packaging tips on daily.dev."}}]}
```

