Namex: Python API Surface Management
Namex is a Python utility that helps package developers define and manage their public API surface, primarily by simplifying the construction of the `__all__` attribute in `__init__.py`. It prevents accidental exposure of internal details and ensures a consistent public interface. The current version is 0.1.0, and it is likely to see active development with potential for API evolution.
Warnings
- gotcha As an early-stage library (v0.1.0), the public API of `namex` is subject to rapid evolution. Breaking changes may occur in minor releases until a stable API is established (e.g., v1.0.0).
- gotcha Namex relies on conventions (e.g., leading underscores for private members) and explicit configuration (e.g., `excludes`). Misunderstandings of these conventions can lead to unintended API exposure or hidden public components.
- gotcha Mixing Namex with manual `__all__` management or other API surface management tools within the same package can lead to unpredictable behavior and difficult-to-debug import errors.
Install
-
pip install namex
Imports
- Config
from namex import Config
- get_api
from namex import get_api
Quickstart
# my_package/__init__.py
from namex import Config, get_api
config = Config(
modules=["my_package.module_a", "my_package.module_b"],
excludes=["my_package.module_a.private_func"]
)
__all__ = get_api(config)
# my_package/module_a.py
def public_func_a():
pass
def _private_func_a(): # Excluded by convention
pass
def private_func(x): # Explicitly excluded
pass
# my_package/module_b.py
class PublicClassB:
pass