Import star

2 snippets across 2 stacks — JavaScript, Python

Also written as star import

JSJavaScript

Namespace Import

JS · Modules
syntax
import * as name from "./module.js";
example
import * as validators from "./validators.js";

const email = "[email protected]";
console.log(validators.isEmail(email));
console.log(validators.isNotEmpty(email));

Note Imports all named exports as a single object. The object is frozen (read-only). Useful when a module has many exports you want to use together.

PYPython

__all__ (Controlling Exports)

PY · Modules & Imports
syntax
__all__ = ['name1', 'name2']
example
# utils.py
__all__ = ["format_price", "validate_email"]

def format_price(amount: float) -> str:
    return f"${amount:,.2f}"

def validate_email(email: str) -> bool:
    return "@" in email

def _internal_helper():  # not exported
    pass

Note __all__ defines what 'from module import *' exports. It does not prevent direct imports of unlisted names. Prefix internal helpers with underscore by convention.