# Python API exposure mechanisms (public/internal) - determining status quo

**URL:** <https://discuss.python.org/t/python-api-exposure-mechanisms-public-internal-determining-status-quo/108869>\
**Category:** Ideas\
**Created:** [September 3, 2026, 1:54am UTC](https://discuss.python.org/t/python-api-exposure-mechanisms-public-internal-determining-status-quo/108869 "2026-09-03T01:54:46Z")\
**Posts on this page:** 19\
**Page:** 2

<div class="post-metadata">

**Author:** ![warden](https://avatars.discourse-cdn.com/v4/letter/w/13edae/32.png) [@warden](https://discuss.python.org/u/warden)\
**Post date:** [September 4, 2026, 7:25am UTC](https://discuss.python.org/t/python-api-exposure-mechanisms-public-internal-determining-status-quo/108869/21 "2026-09-04T07:25:52Z")

</div>

> [@guido](#):
>
> I had previously assumed that type checkers also took ` __all__ ` to define the public API of a module in other contexts, but I can’t find any evidence of that; I tested pyright, mypy and ty.

I tested pyright/pylance (see below) and my understanding is that that type checker does not use ` __all__ ` to define public API, but it does model runtime behavior of star imports and ` __all__ ` correctly.

```python
# ./base.py
__all__ = ["f"]

def f() -> None: pass
def g() -> None: pass

# ./hub.py
from .base import *

# ./ __main__.py
from . import base
from . import hub

base.f # ok
base.g # ok
hub.f # ok
hub.g # unknown attribute

```

A lying `base.pyi` stub-file that incorrectly implements `g` and either has no ` __all__ ` or puts `"g"` into it breaks this behavior by overwriting the `base.py`, but predictably and as expected.

---

<div class="post-metadata">

**Author:** ![timhoffm](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/timhoffm/32/19468_2.png) [@timhoffm](https://discuss.python.org/u/timhoffm)\
**Post date:** [September 4, 2026, 8:46am UTC](https://discuss.python.org/t/python-api-exposure-mechanisms-public-internal-determining-status-quo/108869/22 "2026-09-04T08:46:42Z")

</div>

> [@guido](#):
>
> I am interested in listing precisely what the runtime and type-checkers _currently_ do (because the runtime is the language spec)

That’s an interesting statement. Let me expand on that: “public” is first and foremost intent (“should a 3rd party make use of this”). There is little the runtime _does_ differently for public vs. internal names. In fact, the only difference is wildcard imports in absence of ` __all__ `. The spec says that wildcard imports import all public names, and in fact leading underscores are correctly excluded.

Considering imported names, the runtime does not record whether a name is imported or declared in the module. Therefore, wildcard imports cannot special-handle imported names (i.e. considering them internal).

In other words, the only place where the runtime _does_ something differently (wildcard imports) has technically no information in imported names, which means that imported names are public is not a free choice, but a technical limitation.

So technically yes this statement is true:

> [@guido](#):
>
> The runtime considers imported names public by default if they don’t start with an underscore

But given the limited behavior impact and technical limitations, I would give that statement much less weight that what one may deduce from reading it in isolation.

---

<div class="post-metadata">

**Author:** ![pf\_moore](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/pf_moore/32/35_2.png) [@pf\_moore](https://discuss.python.org/u/pf_moore)\
**Post date:** [September 4, 2026, 9:44am UTC](https://discuss.python.org/t/python-api-exposure-mechanisms-public-internal-determining-status-quo/108869/23 "2026-09-04T09:44:10Z")

</div>

> [@timhoffm](#):
>
> But given the limited behavior impact and technical limitations, I would give that statement much less weight that what one may deduce from reading it in isolation.

Your reasoning is completely correct, but I dispute your conclusion. If we’re planning on documenting and/or clarifying the current behaviour _in the language spec_, then runtime behaviour takes priority (I’d even be willing to argue it’s all that matters).

Typing behaviour, and the typing spec, is a separate matter. Although it seems to me that having consistent behaviour is better, that’s not the current reality so we need to decide whether to document how things are now, or make a change. Given that the runtime _can’t_ change, making typing behave like runtime is the only possible change here.

We could, of course, document all of this in a different document (or section of the docs), essentially a style and usage guide. But even then, what works in the runtime is pretty important. Even if we are only documenting how people can express their intent independent of the language semantics (or lack of them), being clear about what’s the language behaviour and what’s purely convention (which may or may not be respected by 3rd party tools) is still important.

If the plan is to introduce new language constructs/features, all bets are off. We can decide what semantics we want, as well as how it’s indicated in the language. But that means tackling the whole question of what people _want_ “public” to mean - which brings us back to the problem that people have widely differing opinions on that matter.

Honestly, I wish typing had never added that rule that `from x import a as a` means something specific. It feels like a very dangerous precedent to set that two ways of writing the same thing (as far as the runtime is concerned) can mean significantly different things to external tools.

---

<div class="post-metadata">

**Author:** ![timhoffm](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/timhoffm/32/19468_2.png) [@timhoffm](https://discuss.python.org/u/timhoffm)\
**Post date:** [September 4, 2026, 10:41am UTC](https://discuss.python.org/t/python-api-exposure-mechanisms-public-internal-determining-status-quo/108869/24 "2026-09-04T10:41:01Z")

</div>

> [@pf\_moore](#):
>
> Although it seems to me that having consistent behaviour is better, that’s not the current reality so we need to decide whether to document how things are now, or make a change.

I would welcome a discussion on whether and how we could make a change. Even if typing is optional and a separate topic, both worlds overlap in practice if people use typing. IMHO we should not burden developers with handling conflicting statements.

> [@pf\_moore](#):
>
> Given that the runtime _can’t_ change, making typing behave like runtime is the only possible change here.

Is that set in stone? All our options have disadvantages (keeping the inconsistency, changing runtime, changing typing). Can we weigh the respective costs and benefits before excluding options?

---

<div class="post-metadata">

**Author:** ![matthewyu0311](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/matthewyu0311/32/20118_2.png) [@matthewyu0311](https://discuss.python.org/u/matthewyu0311)\
**Post date:** [September 4, 2026, 10:52am UTC](https://discuss.python.org/t/python-api-exposure-mechanisms-public-internal-determining-status-quo/108869/25 "2026-09-04T10:52:43Z")

</div>

As a user reading this I find all this discussion surrounding the “private”, “public” terminology confusing and there seems to be little consensus on what they mean in practice. These public/private terms already carry too many connotations within and outside Python. Meanwhile the actual runtime behavior of `_underscore` and ` __all__ ` is clear. Perhaps we should refer to them by what they actually do rather than their connotations:

- ` __all__ `is the _explicit wildcard-exported symbols_
- In the absence of ` __all__ `, the _implicit wildcard-exported symbols_ are defined as the names in the global namespace, that don’t begin with an underscore
- The sequence of _wildcard-exported symbols_ are evaluated at the time at the time of star-import, and might or might not be statically determinable. This is because ` __all__ ` and the module globals can be populated by any means, including `global` statements inside functions, dynamically modifying ` __dict__ /globals()`, and so on. The runtime makes no distinction of how the module globals are populated.
- Anything not in the global namespace, such as a method in a class namespace, is irrelevant.

Type checkers and style guides can of course tighten things up to encourage readable code and discourage surprises; IDEs and type-checkers don’t seem to support dynamically determining wildcard-exported symbols well, and a dynamically-varying list of exported symbols will be quite surprising to most users. But I don’t think it’s the remit of the language reference (much less the runtime) to _legislate_ on these issues, their job is to define minimum behavior which they already do well.

---

<div class="post-metadata">

**Author:** ![matthewyu0311](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/matthewyu0311/32/20118_2.png) [@matthewyu0311](https://discuss.python.org/u/matthewyu0311)\
**Post date:** [September 4, 2026, 11:00am UTC](https://discuss.python.org/t/python-api-exposure-mechanisms-public-internal-determining-status-quo/108869/26 "2026-09-04T11:00:08Z")

</div>

I don’t think there’s been a serious case arguing that the existing runtime behavior is causing the confusion. Changing the runtime behavior will break a lot of existing code for no good benefit, and that’s an automatic no-go.

It’s the conflating _terminology_ that we use to describe the runtime behavior in the language reference, in the typing spec, the expected API and so on that’s really the trouble. As a general rule, we can always expect the typing spec and style guides to be tighter than what the runtime does or what language reference states, but that they are using the same terminology to describe different things is unfortunate.

---

<div class="post-metadata">

**Author:** ![mgedmin](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/mgedmin/32/2190_2.png) [@mgedmin](https://discuss.python.org/u/mgedmin)\
**Post date:** [September 4, 2026, 11:12am UTC](https://discuss.python.org/t/python-api-exposure-mechanisms-public-internal-determining-status-quo/108869/27 "2026-09-04T11:12:39Z")

</div>

> [@timhoffm](#):
>
> Considering imported names, the runtime does not record whether a name is imported or declared in the module. Therefore, wildcard imports cannot special-handle imported names (i.e. considering them internal).

Has anyone considered changing that? `import X` could be compiled to the current IMPORT\_NAME + STORE\_NAME, plus an additional bit that does something like ` __imported_names__.append('X')`.

Fleshing out the details (how to initialize ` __imported_names__ ` to `[]` before the first import, how to ignore `import` statements inside function or class scopes, how to make imports of submodules also add to the ` __imported_names__ ` of their parent package) are left as an exercise for the reader.

---

<div class="post-metadata">

**Author:** ![tmk](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/tmk/32/10935_2.png) [@tmk](https://discuss.python.org/u/tmk)\
**Post date:** [September 4, 2026, 11:19am UTC](https://discuss.python.org/t/python-api-exposure-mechanisms-public-internal-determining-status-quo/108869/28 "2026-09-04T11:19:28Z")

</div>

This might already be too far into “proposing solutions” territory as opposed to “determining status quo” territory, but anyway, one question I’d have about that scheme is: what happens with

```python
import X
class X: ...

```

?

---

<div class="post-metadata">

**Author:** ![mgedmin](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/mgedmin/32/2190_2.png) [@mgedmin](https://discuss.python.org/u/mgedmin)\
**Post date:** [September 4, 2026, 11:37am UTC](https://discuss.python.org/t/python-api-exposure-mechanisms-public-internal-determining-status-quo/108869/29 "2026-09-04T11:37:26Z")

</div>

There would have to be an override mechanism of some kind (e.g. `from somewhere export thing` PEP?), not just for this, but also to support the hub module pattern. But I agree that discussing possible implementation issues is a digression. My point was to disagree with

> Therefore, wildcard imports cannot special-handle imported names (i.e. considering them internal).

We could make wildcard imports special-case imported names, if we wanted to. (It would not be backward-compatible, and I’m not entirely sure that doing this would be worth the pain.)

---

<div class="post-metadata">

**Author:** ![pf\_moore](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/pf_moore/32/35_2.png) [@pf\_moore](https://discuss.python.org/u/pf_moore)\
**Post date:** [September 4, 2026, 11:55am UTC](https://discuss.python.org/t/python-api-exposure-mechanisms-public-internal-determining-status-quo/108869/30 "2026-09-04T11:55:54Z")

</div>

> [@timhoffm](#):
>
> Is that set in stone?

Sorry, what I meant was that the runtime has no way of distinguishing `from x import a` and `from x import a as a`. So the typing behaviour simply isn’t expressible at runtime.

We could of course change the semantics of `from x import a as a`, but that’s a much bigger change and would likely involve formalising some new runtime mechanism for marking a name as “public”.

We’re getting beyond “determining the status quo” though, so I suggest we defer any discussion of harmonising the runtime and typing behaviours to a thread (or probably multiple threads, given how this debate is currently going 🙁) that’s focused on a specific proposal.

---

<div class="post-metadata">

**Author:** ![timhoffm](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/timhoffm/32/19468_2.png) [@timhoffm](https://discuss.python.org/u/timhoffm)\
**Post date:** [September 4, 2026, 1:52pm UTC](https://discuss.python.org/t/python-api-exposure-mechanisms-public-internal-determining-status-quo/108869/31 "2026-09-04T13:52:55Z")

</div>

Yes, let’s stick to the status quo for now.

If we are reducing the scope to language spec / runtime behavior we could condense [Python API exposure mechanisms (public/internal) - determining status quo - #14 by timhoffm](https://discuss.python.org/t/python-api-exposure-mechanisms-public-internal-determining-status-quo/108869/14) basically to 1 and 3, rephrasing as

- all names and namespaces with a leading underscore (with exception to dunders) are internal.
- all other names are public
- modules can override this by explicitly defining the public interface via ` __all__ `.

That imports are public is is a corollary. If you want an import to be internal, you either can `import X as _X` or define ` __all__ `.

Is there anything more to be said about the status quo?

---

<div class="post-metadata">

**Author:** ![Kurt](https://avatars.discourse-cdn.com/v4/letter/k/b19c9b/32.png) [@Kurt](https://discuss.python.org/u/Kurt)\
**Post date:** [September 4, 2026, 5:18pm UTC](https://discuss.python.org/t/python-api-exposure-mechanisms-public-internal-determining-status-quo/108869/32 "2026-09-04T17:18:40Z")

</div>

I think this is correct, but I think it is important to give also the big picture. So it should explicitly state additionally that the typing spec is orthogonal to the language spec and that it differs regarding the import → private interpretation and the corresponding typing idiom `import x as x`.

---

<div class="post-metadata">

**Author:** ![bwoodsend](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/bwoodsend/32/4027_2.png) [@bwoodsend](https://discuss.python.org/u/bwoodsend)\
**Post date:** [September 5, 2026, 12:12am UTC](https://discuss.python.org/t/python-api-exposure-mechanisms-public-internal-determining-status-quo/108869/33 "2026-09-05T00:12:07Z")

</div>

> [@timhoffm](#):
>
> There is little the runtime _does_ differently for public vs. internal names. In fact, the only difference is wildcard imports in absence of ` __all__ `.

There’s also the REPL’s completion, only suggesting names without underscore prefixes unless an underscore has already been typed. (It ignores ` __all__ `.)

---

<div class="post-metadata">

**Author:** ![edvilme](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/edvilme/32/35395_2.png) [@edvilme](https://discuss.python.org/u/edvilme)\
**Post date:** [September 5, 2026, 2:49am UTC](https://discuss.python.org/t/python-api-exposure-mechanisms-public-internal-determining-status-quo/108869/35 "2026-09-05T02:49:53Z")

</div>

I actually have a PR for that waiting on some guidance from this thread

[gh-149167: PyREPL autocomplete imports to only display public members by edvilme · Pull Request #156146 · python/cpython](https://github.com/python/cpython/pull/156146)

More specifically, if ` __all__ ` includes an underscored member, should it be public?

> [@bwoodsend](#):
>
> > [@timhoffm](#):
> >
> > There is little the runtime _does_ differently for public vs. internal names. In fact, the only difference is wildcard imports in absence of ` __all__ `.
> 
> There’s also the REPL’s completion, only suggesting names without underscore prefixes unless an underscore has already been typed. (It ignores ` __all__ `.)

Pd: Feedback/guidance appreciated

---

<div class="post-metadata">

**Author:** ![elis.byberi](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/elis.byberi/32/35937_2.png) [@elis.byberi](https://discuss.python.org/u/elis.byberi)\
**Post date:** [September 5, 2026, 8:48am UTC](https://discuss.python.org/t/python-api-exposure-mechanisms-public-internal-determining-status-quo/108869/36 "2026-09-05T08:48:43Z")

</div>

> [@edvilme](#):
>
> More specifically, if ` __all__ ` includes an underscored member, should it be public?

Explicit language semantics take precedence over conventions, though conventions may still inform the intended meaning. In this specific case, it is essentially saying, “I am intentionally exposing this underscored member.” If that happens by mistake, tests should help catch it.

---

<div class="post-metadata">

**Author:** ![jfine2358](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/jfine2358/32/36944_2.png) [@jfine2358](https://discuss.python.org/u/jfine2358)\
**Post date:** [September 14, 2026, 3:47pm UTC](https://discuss.python.org/t/python-api-exposure-mechanisms-public-internal-determining-status-quo/108869/37 "2026-09-14T15:47:05Z")

</div>

> [@timhoffm](#):
>
> This is a summary of the API exposure mechanisms currently used in Python, i.e. whether interaction with names from outside of the namespace they live in is intended and supported.

I have a question. Is the behaviour of `dir` and `help`, for example as in the REPL, part of the scope of this thread?

I ask because I use the REPL a lot to explore new to me modules and to remind myself about familiar modules. This request for help [LSP for Python?](https://discuss.python.org/t/lsp-for-python/22194) in this forum is related. (LSP is Language Server Protocol - I had to look it up.)

---

<div class="post-metadata">

**Author:** ![pf\_moore](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/pf_moore/32/35_2.png) [@pf\_moore](https://discuss.python.org/u/pf_moore)\
**Post date:** [September 14, 2026, 4:35pm UTC](https://discuss.python.org/t/python-api-exposure-mechanisms-public-internal-determining-status-quo/108869/38 "2026-09-14T16:35:26Z")

</div>

> [@jfine2358](#):
>
> I have a question. Is the behaviour of `dir` and `help`, for example as in the REPL, part of the scope of this thread?

I believe so. However, for `dir` the status quo is:

> If the object is a module object, the list contains the names of the module’s attributes.

There is also a note:

> Because `dir()` is supplied primarily as a convenience for use at an interactive prompt, it tries to supply an interesting set of names more than it tries to supply a rigorously or consistently defined set of names, and its detailed behavior may change across releases.

So basically, `dir` takes no account of “public” vs “private”, except in terms of any undocumented behaviour it might have around choosing “interesting” names.

The `help` function says nothing more than “a help page is printed on the console”. So again, no documented behaviour that isn relevant to this discussion.

Any discussion about what `dir` or `help` “should” do is out of scope here - this thread is for confirming the status quo as documented, not for designing improvements.

---

<div class="post-metadata">

**Author:** ![barry](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/barry/32/42_2.png) [@barry](https://discuss.python.org/u/barry)\
**Post date:** [September 14, 2026, 5:29pm UTC](https://discuss.python.org/t/python-api-exposure-mechanisms-public-internal-determining-status-quo/108869/39 "2026-09-14T17:29:19Z")

</div>

> [@pf\_moore](#):
>
> So basically, `dir` takes no account of “public” vs “private”, except in terms of any undocumented behaviour it might have around choosing “interesting” names.

It’s not outside the realm of possibility that `dir()` could grow a keyword-only argument that would enable more specific meaning to “interesting”, e.g. `dir(public=True)` or some such.

---

<div class="post-metadata">

**Author:** ![pf\_moore](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/pf_moore/32/35_2.png) [@pf\_moore](https://discuss.python.org/u/pf_moore)\
**Post date:** [September 14, 2026, 6:52pm UTC](https://discuss.python.org/t/python-api-exposure-mechanisms-public-internal-determining-status-quo/108869/40 "2026-09-14T18:52:50Z")

</div>

> [@barry](#):
>
> It’s not outside the realm of possibility that `dir()` could grow a keyword-only argument that would enable more specific meaning to “interesting”, e.g. `dir(public=True)` or some such.

Absolutely. As I said, that’s a topic for a different thread, not for this one, though.

[Previous page](https://discuss.python.org/t/python-api-exposure-mechanisms-public-internal-determining-status-quo/108869.md?page=1)
