{"id":1802,"library":"atpublic","title":"atpublic","description":"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.","status":"active","version":"7.0.0","language":"en","source_language":"en","source_url":"https://gitlab.com/warsaw/public","tags":["__all__","public API","module management","decorator","documentation"],"install":[{"cmd":"pip install atpublic","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Requires Python 3.10 or newer.","package":"python","optional":false}],"imports":[{"note":"The PyPI package is 'atpublic' but the top-level module to import from is 'public' due to a historical name conflict.","wrong":"from atpublic import public","symbol":"public","correct":"from public import public"},{"note":"The PyPI package is 'atpublic' but the top-level module to import from is 'public' due to a historical name conflict.","wrong":"from atpublic import private","symbol":"private","correct":"from public import private"},{"note":"The PyPI package is 'atpublic' but the top-level module to import from is 'public' due to a historical name conflict.","wrong":"from atpublic import populate_all","symbol":"populate_all","correct":"from public import populate_all"}],"quickstart":{"code":"import inspect\nfrom public import public, private, populate_all\n\n@public\ndef my_public_function():\n    \"\"\"This function is part of the public API.\"\"\"\n    return \"Hello from public\"\n\n@private\ndef _my_private_function():\n    \"\"\"This function is explicitly private.\"\"\"\n    return \"Shhh, private\"\n\n@public(name=\"renamed_public_function\")\ndef _internal_name_function():\n    \"\"\"This function is public under a different name.\"\"\"\n    return \"Hello from renamed public\"\n\nclass PublicClass:\n    @public\n    def public_method(self):\n        return \"Public method call\"\n\n\n# Populate __all__ based on decorators\npopulate_all(inspect.currentframe().f_globals)\n\n# Verify the __all__ list\nif __name__ == '__main__':\n    print(f\"Module __all__: {__all__}\")\n    # Expected: ['my_public_function', 'renamed_public_function', 'PublicClass']\n\n    # Test public access\n    try:\n        print(my_public_function())\n        print(_internal_name_function())\n        instance = PublicClass()\n        print(instance.public_method())\n    except NameError as e:\n        print(f\"Error accessing public member: {e}\")\n\n    # Test private access (should be NameError if 'from module import *' was used)\n    try:\n        _my_private_function()\n        print(\"Accessed private function (this shouldn't happen with import *)\")\n    except NameError:\n        print(\"Cannot access private function directly (as expected with import * semantics)\")\n","lang":"python","description":"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."},"warnings":[{"fix":"Ensure your import statements read `from public import public, private, populate_all` (or specific symbols), not `from atpublic import ...`.","message":"The 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 ...`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade your Python environment to 3.10 or a newer compatible version.","message":"Version 7.0.0 and subsequent releases require Python 3.10 or newer. Older Python versions are not supported.","severity":"breaking","affected_versions":"7.0.0+"},{"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()`.","message":"If `__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__`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}