Install & Compatibility
Where this runs
tested against v7.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.014s · 17.8MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.5s · import 0.012s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
public
✓ from public import public
✗ from atpublic import public
The PyPI package is 'atpublic' but the top-level module to import from is 'public' due to a historical name conflict.
private
✓ from public import private
✗ from atpublic import private
The PyPI package is 'atpublic' but the top-level module to import from is 'public' due to a historical name conflict.
populate_all
✓ from public import populate_all
✗ from atpublic import populate_all
The PyPI package is 'atpublic' but the top-level module to import from is 'public' due to a historical name conflict.
This example demonstrates how to use the `@public` and `@private` decorators, along with `populate_all()`, to define and synchronize your module's public API. After running `populate_all()`, the `__all__` list will contain the names marked `@public`, including those renamed via the decorator. This ensures `from module import *` only exposes intended symbols.
import inspect
from public import public, private, populate_all
@public
def my_public_function():
"""This function is part of the public API."""
return "Hello from public"
@private
def _my_private_function():
"""This function is explicitly private."""
return "Shhh, private"
@public(name="renamed_public_function")
def _internal_name_function():
"""This function is public under a different name."""
return "Hello from renamed public"
class PublicClass:
@public
def public_method(self):
return "Public method call"
# Populate __all__ based on decorators
populate_all(inspect.currentframe().f_globals)
# Verify the __all__ list
if __name__ == '__main__':
print(f"Module __all__: {__all__}")
# Expected: ['my_public_function', 'renamed_public_function', 'PublicClass']
# Test public access
try:
print(my_public_function())
print(_internal_name_function())
instance = PublicClass()
print(instance.public_method())
except NameError as e:
print(f"Error accessing public member: {e}")
# Test private access (should be NameError if 'from module import *' was used)
try:
_my_private_function()
print("Accessed private function (this shouldn't happen with import *)")
except NameError:
print("Cannot access private function directly (as expected with import * semantics)")
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'public'
Attempting to import 'public' instead of the correct package name 'atpublic'.
fixUse 'from atpublic import public' instead of 'from public import public'.
TypeError: 'public' object is not callable
Using 'public' as a function instead of as a decorator.
fixApply 'public' as a decorator: '@public\ndef my_function():\n pass'.
AttributeError: module 'atpublic' has no attribute 'private'
Attempting to use a 'private' decorator that does not exist in the 'atpublic' module.
fixUse the 'public' decorator for public API elements; 'private' is not provided by 'atpublic'.
ModuleNotFoundError: No module named 'atpublic'
The 'atpublic' library has not been installed in the current Python environment.
fixInstall the library using pip: `pip install atpublic`
NameError: name 'MyPublicClass' is not defined
This typically occurs when attempting a wildcard import (`from my_module import *`) and the `MyPublicClass` was not properly marked as public by `atpublic` or the module's `__all__` variable (managed by `atpublic`) was not correctly updated, preventing the name from being exported.
fixEnsure the `atpublic.public` decorator is applied to the class or function you intend to expose: `import atpublic
@atpublic.public
class MyPublicClass:
pass
# Or, if using the utility function explicitly:
# from atpublic import auto_sync_public
# __all__ = auto_sync_public(globals(), __name__)` Upgrade
Version history
7.0.0latest on PyPI · released Nov 29, 2025
Audit
Dependencies
pythonrequiredRequires Python 3.10 or newer.