# Extended import syntax for aliasing module attributes

**URL:** <https://discuss.python.org/t/extended-import-syntax-for-aliasing-module-attributes/95920>\
**Category:** Ideas\
**Created:** [June 18, 2025, 12:17pm UTC](https://discuss.python.org/t/extended-import-syntax-for-aliasing-module-attributes/95920 "2025-06-18T12:17:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![softwaredevomar](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/softwaredevomar/32/28680_2.png) [@softwaredevomar](https://discuss.python.org/u/softwaredevomar)\
**Post date:** [June 18, 2025, 12:17pm UTC](https://discuss.python.org/t/extended-import-syntax-for-aliasing-module-attributes/95920/1 "2025-06-18T12:17:34Z")

</div>

Hi all,  
I would like to propose a potential addition to Python’s `import` syntax that would improve clarity and ergonomics for cases where developers want both full module access _and_ a local alias to a specific attribute within that module.

Currently, to get both behaviors, we typically write:  
import module  
optimize = module.optimize

This works fine, but it is slightly verbose and less explicit in intent.

I would like to explore syntax like:  
import module with module.optimize as optimize  
or possibly:  
import module with (  
module.optimize as optimize,  
module.validate as check  
)

The goal is to import the full module as usual, while simultaneously assigning a local name to a chosen sub-attribute all in a single declaration.

This strikes a balance between:  
_Readability_ (makes intensions clearer)  
_Convenience_ (avoids repetitive alias assignments)  
_Maintainability_ (discourages `from module import *`)

I am curious to hear whether this type of syntax has been considered before, or if it might be worth formalizing into a PEP. I would be happy to help develop a draft proposal if there is interest.

Thank you for reading.  
-Omar

---

<div class="post-metadata">

**Author:** ![effigies](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/effigies/32/35835_2.png) [@effigies](https://discuss.python.org/u/effigies)\
**Post date:** [June 18, 2025, 12:33pm UTC](https://discuss.python.org/t/extended-import-syntax-for-aliasing-module-attributes/95920/2 "2025-06-18T12:33:03Z")

</div>

```python
import module
from module import optimize, validate as check

```

I don’t find this unreadable, inconvenient, or difficult to maintain.

---

<div class="post-metadata">

**Author:** ![softwaredevomar](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/softwaredevomar/32/28680_2.png) [@softwaredevomar](https://discuss.python.org/u/softwaredevomar)\
**Post date:** [June 18, 2025, 1:48pm UTC](https://discuss.python.org/t/extended-import-syntax-for-aliasing-module-attributes/95920/3 "2025-06-18T13:48:04Z")

</div>

Thank you that clarifies things.

---

<div class="post-metadata">

**Author:** ![Monarch](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/monarch/32/18530_2.png) [@Monarch](https://discuss.python.org/u/Monarch)\
**Post date:** [June 18, 2025, 2:50pm UTC](https://discuss.python.org/t/extended-import-syntax-for-aliasing-module-attributes/95920/4 "2025-06-18T14:50:14Z")

</div>

There’s some prior art in Rust with the `self` keyword:

```rs
use std::collections::hash_map::{self, HashMap};

fn bar(map1: HashMap<String, usize>, map2: hash_map::HashMap<String, usize>){}

fn main() {

    // Both `hash_map` and `HashMap` are in scope.
    let map1 = HashMap::new();
    let map2 = hash_map::HashMap::new();
    bar(map1, map2);
}

```

I’m not a big fan of how Rust’s imports work in general, and I think this will add unnecessary complexity for very little gain.
