Namex: Python API Surface Management

0.1.0 · active · verified Thu Apr 09

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

Install

Imports

Quickstart

This example demonstrates how to set up `namex` in a package's `__init__.py` to define its public API. It imports `Config` and `get_api`, then configures which modules to scan and which specific symbols to exclude. The resulting `__all__` ensures only specified public members are exposed.

# 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

view raw JSON →