Registry / testing / atpublic

atpublic

JSON →
library7.0.0pypypi✓ verified 25d ago

atpublic is a Python library that offers simple decorators and a utility function to synchronize a module's `__all__` variable, explicitly defining its public API. This helps prevent `__all__` from becoming outdated, which is a common issue when functions or classes are added, renamed, or removed. The library is currently in version 7.0.0 and maintains an active development cadence with regular updates.

pip install atpublic
INSTALL
IMPORT
SIG · ATPUBLIC
A
atpublic
testingpythonv7.0.0
Install
1.5s avg
Import
13ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.014s · 17.8MB
glibc
py 3.103.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)")
Debug
Known issues
gotchaThe PyPI package name is `atpublic`, but the Python module you import from is `public`. Importing `from atpublic import ...` will fail. Always use `from public import ...`.
fix
Ensure your import statements read `from public import public, private, populate_all` (or specific symbols), not `from atpublic import ...`.
affects: All versions
breakingVersion 7.0.0 and subsequent releases require Python 3.10 or newer. Older Python versions are not supported.
fix
Upgrade your Python environment to 3.10 or a newer compatible version.
affects: 7.0.0+
gotchaIf `__all__` is manually defined in your module *before* calling `populate_all()`, `populate_all()` will overwrite it with the list of names decorated as public. This is the intended behavior for synchronizing `__all__`.
fix
Rely solely on `@public` and `@private` decorators and a single call to `populate_all()` (typically at the end of the module) to manage your `__all__`. Avoid manual modification of `__all__` if using `populate_all()`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'public'
Attempting to import 'public' instead of the correct package name 'atpublic'.
fix
Use '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.
fix
Apply '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.
fix
Use 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.
fix
Install 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.
fix
Ensure 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.
Agent activity
35 hits · last 30 days
node
30
OpenAI (training)
1
Resources
atpublic — pip install atpublic · libregistry