<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/what-does-init-py-do-in-python--svzjn0g6f" -->

---
title: What does &#x27;__init__.py&#x27; do in Python? | daily.dev
description: The __init__.py file in Python is used to mark a directory as a package and runs any setup code required for the package. It is essential for allowing Python...
canonical: https://daily.dev/posts/what-does-init-py-do-in-python--svzjn0g6f
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: What does &#x27;__init__.py&#x27; do in Python? | daily.dev
og:description: The __init__.py file in Python is used to mark a directory as a package and runs any setup code required for the package. It is essential for allowing Python...
og:url: https://daily.dev/posts/what-does-init-py-do-in-python--svzjn0g6f
og:image: https://api.daily.dev/og/posts/svzJn0g6F.png
og:image:alt: What does &#x27;__init__.py&#x27; do in Python?
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.

# What does '__init__.py' do in Python?

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

## Summary

The __init__.py file in Python is used to mark a directory as a package and runs any setup code required for the package. It is essential for allowing Python to recognize the folder as a package and enabling imports from it. The file is executed every time the package is imported, and it can be used to define which modules or functions are accessible when using a wildcard import (from package import *). The tutorial demonstrates how to create a package, define modules, and use the __init__.py file to manage different import behaviors.

## Full article

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

## Community discussion

Top comments from developers on daily.dev.

**@prathameshkorde** · 4 upvotes

> sure it helps a lot thanks man for help us out

**@chrisjohnsson** · 2 upvotes

> s-tier vid. instant upvote

**@miguelrobredo** · 1 upvotes

> If building a package, does It make sense to start the logger into the init file?

**@royalboss** · 1 upvotes

> __ all __ was new to me. Thanks!

**@iriadomj** · 0 upvotes

> Absolutely new to me
> Thanks a lot🙏

## Similar posts on daily.dev

- [Don’t just attend KubeCon \+ CloudNativeCon, Merge Forward your experience\!](https://daily.dev/posts/don-t-just-attend-kubecon-cloudnativecon-merge-forward-your-experience--l0rpp73x8) · CNCF · 1 upvotes · 0 comments
- [Announcing H2 2026 KCDs](https://daily.dev/posts/announcing-h2-2026-kcds-m96goajm1) · CNCF · 1 upvotes · 0 comments
- [Two months of Open Community Groups](https://daily.dev/posts/two-months-of-open-community-groups-asf52zhbs) · CNCF · 0 upvotes · 0 comments

---

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

[View this post on daily.dev](https://daily.dev/posts/what-does-init-py-do-in-python--svzjn0g6f)

```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":"What does '__init__.py' do in Python?","url":"https://daily.dev/posts/what-does-init-py-do-in-python--svzjn0g6f","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/what-does-init-py-do-in-python--svzjn0g6f"},"datePublished":"2024-10-10T04:10:13.415Z","dateModified":"2024-10-10T04:10:22.531Z","description":"The __init__.py file in Python is used to mark a directory as a package and runs any setup code required for the package. It is essential for allowing Python...","image":"https://i.ytimg.com/vi/EH-TFaX-R-o/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/EH-TFaX-R-o/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":28,"discussionUrl":"https://daily.dev/posts/what-does-init-py-do-in-python--svzjn0g6f","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":716},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":28}],"keywords":"python","timeRequired":"PT6M","video":{"@type":"VideoObject","name":"What does '__init__.py' do in Python?","description":"The __init__.py file in Python is used to mark a directory as a package and runs any setup code required for the package. It is essential for allowing Python...","thumbnailUrl":"https://i.ytimg.com/vi/EH-TFaX-R-o/sddefault.jpg","uploadDate":"2024-10-10T04:10:13.415Z","duration":"PT6M","url":"https://api.daily.dev/r/svzJn0g6F","embedUrl":"https://www.youtube.com/embed/EH-TFaX-R-o"}}
{"@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":"What does '__init__.py' do in Python?"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/what-does-init-py-do-in-python--svzjn0g6f","comment":[{"@type":"Comment","text":"sure it helps a lot thanks man for help us out","datePublished":"2024-10-10T05:42:58.031Z","url":"https://daily.dev/posts/svzJn0g6F#c-1QAwThTBA","author":{"@type":"Person","name":"Prathamesh korde","url":"https://daily.dev/prathameshkorde","image":"https://lh3.googleusercontent.com/a/ACg8ocIi_NhahrxHH_7VuUulRjNao-v6e47wJCUrKWEBsg3tqHhPJg=s96-c"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":4}},{"@type":"Comment","text":"s-tier vid. instant upvote","datePublished":"2024-10-10T14:42:03.994Z","url":"https://daily.dev/posts/svzJn0g6F#c-pWm28QGIn","author":{"@type":"Person","name":"Chris Johnsson","url":"https://daily.dev/chrisjohnsson","image":"https://lh3.googleusercontent.com/a/ACg8ocKr-ZKdooohOxOuBz7J3ydHVyRQVh-YtcbZqZGsgq_lC0D0fw=s96-c"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2}},{"@type":"Comment","text":"If building a package, does It make sense to start the logger into the init file?","datePublished":"2024-10-12T00:20:10.330Z","url":"https://daily.dev/posts/svzJn0g6F#c-jhN6e2rIC","author":{"@type":"Person","name":"Miguel Robredo","url":"https://daily.dev/miguelrobredo","image":"https://lh3.googleusercontent.com/a/ACg8ocIFSAV5CoA-YoEhb1XeKOwsNz1lYi3UmC9p1OnlLvZpAQDP6Q=s96-c"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1}},{"@type":"Comment","text":"__ all __ was new to me. Thanks!","datePublished":"2024-10-14T06:04:41.221Z","dateModified":"2024-10-14T06:04:52.614Z","url":"https://daily.dev/posts/svzJn0g6F#c-Mes7TNMmL","author":{"@type":"Person","name":"Ayush Munot","url":"https://daily.dev/royalboss","image":"https://lh3.googleusercontent.com/a/ACg8ocJRnM9_yxLtDkLhZgCPG3rPjBcTz2skKDiXgAr_TA4d=s96-c"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1}},{"@type":"Comment","text":"Absolutely new to me\nThanks a lot🙏","datePublished":"2024-11-18T08:57:15.928Z","url":"https://daily.dev/posts/svzJn0g6F#c-mI6sgyRQh","author":{"@type":"Person","name":"Iriavboi jethro oshoma","url":"https://daily.dev/iriadomj","image":"https://lh3.googleusercontent.com/a/ACg8ocIVq7Tk_V8QhI-p5eg3oAHjngU-6s7fIne75kHBzRtNFbOixCI=s96-c"}}]}
```

