PEP 844 proposes `public()` and `private()` builtins for improved Python module APIs
Python Enhancement Proposal 844 (PEP 844) introduces `public()` and `private()` builtins for Python 3.16, designed to synchronize a module's `__all__` with explicitly declared public and private names. These new functions, primarily used as decorators, address long-standing ergonomic issues with `__all__` by declaring name visibility at the point of definition. The proposal aims to formalize a pattern already proven by the `atpublic` third-party package. This change will affect Python developers managing module APIs, especially for libraries, by making it easier to maintain accurate public interface declarations.
- →Introducing PEP 844 for Public/Private Builtins
- →Addressing `__all__` Synchronization Challenges
- →Specification of `public()` and `private()` Builtins
Notes (3) ›
- Introducing PEP 844 for Public/Private Builtins
PEP 844 proposes adding `public()` and `private()` built-in functions to Python 3.16. These functions, typically used as decorators, will automatically keep a module's `__all__` synchronized with names explicitly designated as public or private.
- Addressing `__all__` Synchronization Challenges
The proposal tackles common problems with `__all__`, such as names being added to modules but not `__all__`, or names being removed without `__all__` being updated. It aims to improve the ergonomics of declaring a module's public interface, acknowledging that Python's language reference already defines `__all__` as normative for public API declaration.
- Specification of `public()` and `private()` Builtins
`public()` can be used as a decorator for functions and classes, or as a function call for constants, appending names to `__all__`. `private()` is exclusively a decorator, signaling that a name is not part of the module's public interface and ensuring it is not in `__all__`. Both functions affect only module-level visibility and create `__all__` if it does not already exist.
https://peps.python.org/pep-0844/
Related releases
- Python Packaging Council: 2026 Election Candidates Announced Python Insider ·
- FastAPI 0.140.7 Patch Update Improves OpenAPI Dependency Handling FastAPI Releases ·
- Pydantic-AI v2.29.0 Adds Azure AI Voice Live Support and FastMCP 4 Pydantic AI Releases ·
- Python 3.12.14, 3.11.16, and 3.10.21 Released with Critical Security Patches Python Insider ·
- Django Software Foundation Hosts Office Hours to Discuss ED Search and Fundraising Django Weblog ·
- Pydantic-AI v1.107.4 Addresses High-Severity Web UI Vulnerability Pydantic AI Releases ·