Skip to content

@public

@public declares that a method is unrestricted, overriding the underscore naming convention. It is rarely needed — only when you must keep an underscore-prefixed name for compatibility reasons but want it to remain callable from anywhere.

from strictaccess import strict_access_control, public

@strict_access_control()
class API:
    @public
    def _legacy_endpoint(self) -> str:
        """Kept underscore-prefixed for backwards compatibility."""
        return "ok"

API()._legacy_endpoint()                # "ok" (no exception)

Without @public, the underscore-prefixed name would be treated as protected and rejected from outside callers.

When you don't need it

For ordinary public methods, omit it. A name without a leading underscore is already public by convention; the engine has a fast path that returns immediately.

@strict_access_control()
class Greeter:
    def hello(self) -> str:             # already public, no decorator needed
        return "hello"

When you do need it

  • Migrating a legacy API where the underscore is part of the published contract and removing it would break consumers.
  • Renaming is planned but not yet possible — @public documents the intent until the rename happens.

Stacking

@public can stack with @classmethod and @staticmethod:

@strict_access_control()
class Tools:
    @public
    @staticmethod
    def _helper(): ...