<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/python-modules-and-packages-an-introduction-real-python-trpja5ltz" -->

---
title: Python Modules and Packages – An Introduction – Real Python
description: Python modules and packages let you break large programs into smaller, reusable pieces. A module is any `.py` file; Python finds it by searching `sys.path`,...
canonical: https://daily.dev/posts/python-modules-and-packages-an-introduction-real-python-trpja5ltz
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Python Modules and Packages – An Introduction – Real Python | daily.dev
og:description: Python modules and packages let you break large programs into smaller, reusable pieces. A module is any `.py` file; Python finds it by searching `sys.path`,...
og:url: https://daily.dev/posts/python-modules-and-packages-an-introduction-real-python-trpja5ltz
og:image: https://api.daily.dev/og/posts/trPja5lTZ.png
og:image:alt: Python Modules and Packages – An Introduction – Real 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.

# Python Modules and Packages – An Introduction – Real Python

**[Real Python](https://daily.dev/sources/rpython)** · 24 min read · 0 upvotes · 0 comments

## Summary

Python modules and packages let you break large programs into smaller, reusable pieces. A module is any `.py` file; Python finds it by searching `sys.path`, built from the script directory, the `PYTHONPATH` variable, and installation-dependent paths. The `import` statement has several forms, including `import x`, `from x import y`, and aliasing with `as`. Packages group modules using directory structure and dot notation, and since Python 3.3 no longer require an `__init__.py` file thanks to implicit namespace packages. An `__all__` list in `__init__.py` controls what `from package import *` imports, and `..` enables relative imports between sibling subpackages.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://realpython.com/python-modules-packages>

## Questions this post answers

### Do I still need an __init__.py file to create a package in Python 3?

No, Python does not require an __init__.py file to define a package. Starting with Python 3.3, Implicit Namespace Packages were introduced, letting the operating system's directory structure alone define a package. An __init__.py can still be included if you need package initialization code, but it is optional.

_Developers structuring new Python projects can find similar packaging clarifications on daily.dev._

### Why does from module import * not bring in everything when I import a package with import *?

For a package, from <package_name> import * imports nothing by default unless the package's __init__.py defines a list named __all__ listing the module names to import. This differs from a plain module, where import * imports every name not starting with an underscore when __all__ is absent.

_Anyone debugging unexpected import behavior can track these Python import quirks on daily.dev._

### How do I import a function from a sibling subpackage using a relative import in Python?

Use dot notation where a single dot refers to the current package and two dots refer to the parent package, for example 'from ..sub_pkg1.mod1 import foo' inside a module in sub_pkg2. This relative import resolves sub_pkg1 as a subpackage of the shared parent package, letting modules in sibling subpackages reference each other's functionality.

_Developers organizing multi-package Python codebases can revisit import patterns like this 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
- [: Packages, Modules, and Wildcard Imports Quiz – Real Python](https://daily.dev/posts/packages-modules-and-wildcard-imports-quiz-real-python-ahhafnalg) · Real Python · 1 upvotes · 0 comments

---

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

[View this post on daily.dev](https://daily.dev/posts/python-modules-and-packages-an-introduction-real-python-trpja5ltz)

```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":"Python Modules and Packages – An Introduction – Real Python","url":"https://daily.dev/posts/python-modules-and-packages-an-introduction-real-python-trpja5ltz","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/python-modules-and-packages-an-introduction-real-python-trpja5ltz"},"datePublished":"2026-10-25T14:16:25.665Z","dateModified":"2026-10-25T14:17:06.128Z","description":"Python modules and packages let you break large programs into smaller, reusable pieces. A module is any `.py` file; Python finds it by searching `sys.path`,...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/78a7d020154fcc4c9870264460fabed3?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/78a7d020154fcc4c9870264460fabed3?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Real Python","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":"Real Python","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/rpython","url":"https://daily.dev/sources/rpython"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/python-modules-and-packages-an-introduction-real-python-trpja5ltz","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"python","timeRequired":"PT24M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Real Python","item":"https://daily.dev/sources/rpython"},{"@type":"ListItem","position":3,"name":"Python Modules and Packages – An Introduction – Real Python"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/python-modules-and-packages-an-introduction-real-python-trpja5ltz#faq","mainEntity":[{"@type":"Question","name":"Do I still need an __init__.py file to create a package in Python 3?","acceptedAnswer":{"@type":"Answer","text":"No, Python does not require an __init__.py file to define a package. Starting with Python 3.3, Implicit Namespace Packages were introduced, letting the operating system's directory structure alone define a package. An __init__.py can still be included if you need package initialization code, but it is optional. Developers structuring new Python projects can find similar packaging clarifications on daily.dev."}},{"@type":"Question","name":"Why does from module import * not bring in everything when I import a package with import *?","acceptedAnswer":{"@type":"Answer","text":"For a package, from \u003cpackage_name\u003e import * imports nothing by default unless the package's __init__.py defines a list named __all__ listing the module names to import. This differs from a plain module, where import * imports every name not starting with an underscore when __all__ is absent. Anyone debugging unexpected import behavior can track these Python import quirks on daily.dev."}},{"@type":"Question","name":"How do I import a function from a sibling subpackage using a relative import in Python?","acceptedAnswer":{"@type":"Answer","text":"Use dot notation where a single dot refers to the current package and two dots refer to the parent package, for example 'from ..sub_pkg1.mod1 import foo' inside a module in sub_pkg2. This relative import resolves sub_pkg1 as a subpackage of the shared parent package, letting modules in sibling subpackages reference each other's functionality. Developers organizing multi-package Python codebases can revisit import patterns like this on daily.dev."}}]}
```

