<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/protected-module-members-an-interesting-feature-in-python-q1ajhttpi" -->

---
title: Protected Module Members: An Interesting Feature in Python
description: A leading underscore in Python is usually just a naming convention, but at the module level it has actual runtime behavior: functions and variables prefixed...
canonical: https://daily.dev/posts/protected-module-members-an-interesting-feature-in-python-q1ajhttpi
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Protected Module Members: An Interesting Feature in Python | daily.dev
og:description: A leading underscore in Python is usually just a naming convention, but at the module level it has actual runtime behavior: functions and variables prefixed...
og:url: https://daily.dev/posts/protected-module-members-an-interesting-feature-in-python-q1ajhttpi
og:image: https://api.daily.dev/og/posts/q1AjHttPI.png
og:image:alt: Protected Module Members: An Interesting Feature 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.

# Protected Module Members: An Interesting Feature in Python

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

## Summary

A leading underscore in Python is usually just a naming convention, but at the module level it has actual runtime behavior: functions and variables prefixed with a single underscore are excluded from wildcard (star) imports. A demonstration walks through building a text.py module with a public length function and a protected example function, showing that `from text import *` skips the underscore-prefixed function while still exposing public ones. The video also touches on name mangling with double underscores in classes as a stronger (but still bypassable) form of hiding attributes.

## Full article

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

## Questions this post answers

### Does a single leading underscore on a Python module-level function actually do anything besides signal convention?

Yes, at the module level a single leading underscore has real runtime behavior beyond convention: it excludes that function or variable from wildcard imports done with `from module import *`. Public names without the underscore are still imported normally, but underscore-prefixed ones are skipped, even though they remain fully accessible via normal dotted access like module._name.

_Developers untangling Python import behavior can find explainers like this through daily.dev._

### How does Python name mangling work for double-underscore class attributes?

Changing a class attribute's prefix from one leading underscore to two triggers Python's name mangling, which renames the attribute internally (for example turning _value into _ClassName__value). This makes the attribute harder to access from outside the class, but it is not truly private since the mangled name can still be accessed directly if you know the pattern.

_daily.dev surfaces practical Python internals like this for developers reasoning about encapsulation._

## 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
- [Only Python: Breaking a four year hiatus to talk about the export keyword \(PEPs 842 and 843\)](https://daily.dev/posts/only-python-breaking-a-four-year-hiatus-to-talk-about-the-export-keyword-peps-842-and-843--zvh7mwwtg) · Planet Python · 0 upvotes · 0 comments

---

Tags: [#general-programming](https://daily.dev/tags/general-programming), [#python](https://daily.dev/tags/python), [#zed](https://daily.dev/tags/zed)

[View this post on daily.dev](https://daily.dev/posts/protected-module-members-an-interesting-feature-in-python-q1ajhttpi)

```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":"Protected Module Members: An Interesting Feature in Python","url":"https://daily.dev/posts/protected-module-members-an-interesting-feature-in-python-q1ajhttpi","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/protected-module-members-an-interesting-feature-in-python-q1ajhttpi"},"datePublished":"2026-09-12T16:05:21.552Z","dateModified":"2026-09-12T16:05:44.064Z","description":"A leading underscore in Python is usually just a naming convention, but at the module level it has actual runtime behavior: functions and variables prefixed...","image":"https://i.ytimg.com/vi/gQwe1Fq_MQA/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/gQwe1Fq_MQA/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/protected-module-members-an-interesting-feature-in-python-q1ajhttpi","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"general-programming,python,zed","timeRequired":"PT6M","video":{"@type":"VideoObject","name":"Protected Module Members: An Interesting Feature in Python","description":"A leading underscore in Python is usually just a naming convention, but at the module level it has actual runtime behavior: functions and variables prefixed...","thumbnailUrl":"https://i.ytimg.com/vi/gQwe1Fq_MQA/sddefault.jpg","uploadDate":"2026-09-12T16:05:21.552Z","duration":"PT6M","url":"https://api.daily.dev/r/q1AjHttPI","embedUrl":"https://www.youtube.com/embed/gQwe1Fq_MQA"}}
{"@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":"Protected Module Members: An Interesting Feature in Python"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/protected-module-members-an-interesting-feature-in-python-q1ajhttpi#faq","mainEntity":[{"@type":"Question","name":"Does a single leading underscore on a Python module-level function actually do anything besides signal convention?","acceptedAnswer":{"@type":"Answer","text":"Yes, at the module level a single leading underscore has real runtime behavior beyond convention: it excludes that function or variable from wildcard imports done with `from module import *`. Public names without the underscore are still imported normally, but underscore-prefixed ones are skipped, even though they remain fully accessible via normal dotted access like module._name. Developers untangling Python import behavior can find explainers like this through daily.dev."}},{"@type":"Question","name":"How does Python name mangling work for double-underscore class attributes?","acceptedAnswer":{"@type":"Answer","text":"Changing a class attribute's prefix from one leading underscore to two triggers Python's name mangling, which renames the attribute internally (for example turning _value into _ClassName__value). This makes the attribute harder to access from outside the class, but it is not truly private since the mangled name can still be accessed directly if you know the pattern. daily.dev surfaces practical Python internals like this for developers reasoning about encapsulation."}}]}
```

