> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Python Star Import

A star import (wildcard import) is an import statement that binds all public names from a specified module directly into the current local namespace. This mechanism allows the importing module to access the target module's functions, classes, and variables without qualifying them with the module's namespace prefix.

```python theme={"dark"}
from module_name import *
```

## Name Resolution Mechanics

When the Python interpreter executes a star import, it determines which names to bind to the current namespace based on the presence of the `__all__` dunder attribute in the target module.

**1. With `__all__` defined:**
If the target module defines a list or tuple named `__all__`, the star import will strictly bind only the names specified as strings within that sequence.

```python theme={"dark"}

# target_module.py
__all__ = ['active_connection', 'connect']

def connect(): pass
def disconnect(): pass
active_connection = True
```

```python theme={"dark"}

# main.py
from target_module import *

connect()                # Resolves successfully
print(active_connection) # Resolves successfully
disconnect()             # NameError: name 'disconnect' is not defined
```

**2. Without `__all__` defined:**
If `__all__` is not defined, the interpreter falls back to a default behavior: it imports all names defined in the target module's global namespace, excluding any names that begin with a single underscore (`_`).

```python theme={"dark"}

# target_module.py
def public_function(): pass
def _internal_function(): pass
```

```python theme={"dark"}

# main.py
from target_module import *

public_function()    # Resolves successfully
_internal_function() # NameError: name '_internal_function' is not defined
```

## Namespace Shadowing

Star imports directly mutate the `globals()` dictionary of the importing module. If a name imported via the wildcard matches a name already defined in the current namespace, the existing reference is silently overwritten.

```python theme={"dark"}

# external_lib.py
def process_data():
    return "External implementation"
```

```python theme={"dark"}

# main.py
def process_data():
    return "Local implementation"

from external_lib import * # Overwrites the local 'process_data' definition

print(process_data()) # Output: External implementation
```

## PEP 8 and Namespace Pollution

PEP 8 strongly discourages the use of wildcard imports in production code. Because star imports inject an unknown set of names into the current environment, they cause severe namespace pollution. This behavior makes it difficult for human readers and static analysis tools (such as linters and type checkers) to determine where names originate, significantly increasing the likelihood of shadowing bugs and maintenance overhead.

## Scope Restrictions

In Python 3, star imports are strictly restricted to the module level. Attempting to execute a wildcard import within a function block or class definition will raise a `SyntaxError`. This restriction exists because Python's compiler optimizes local variable access at compile time; dynamically injecting unknown names into a local scope via a star import would invalidate these optimizations.

```python theme={"dark"}
def initialize_system():
    from math import *  # Raises SyntaxError: import * only allowed at module level
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Python Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
