title: How do I alias a python module at packaging time?
body: <p>For historic reasons and backwards compatibility I want to package a module (let's call it <code>myapi</code>) in a way that this set of imports:</p>
  
  <pre><code>from myapi.utils import helpers
  from myapi.api.rest import MyRest
  import myapi
  </code></pre>
  
  <p>Import the same code (without duplication) as these below:</p>
  
  <pre><code>from oldname.utils import helpers
  from oldname.api.rest import MyRest
  import oldname
  </code></pre>
  
  <p>Assuming the package was installed the regular way with <code>pip install myapi</code> or <code>pip install --user myapi</code>.</p>
  
  <p>I.e., I want to alias the complete module structure of <code>myapi</code> under another name <code>oldname</code> <strong>at packaging</strong>, so the user can import any module using <code>oldname</code> or the new name (here <code>myapi</code>) without duplicating the code. Is there something in Python or <code>setuptools</code> that can accomplish that?</p>
  
  <p><strong>Alternatives, that don't work for me:</strong></p>
  
  <p>I'm aware that the user could just do:</p>
  
  <pre><code>import myapi as oldname
  </code></pre>
  
  <p>My goal is to avoid confusion, because the package name changed at some point. The users should be able to use both the old and the new name interchangeably, without having to know the name changed at all.</p>
  
  <p>On some systems, the easiest way would be to just create a symbolic link upon running <code>setup.py install</code>:</p>
  
  <pre><code>ln -s /usr/local/lib/python2.7/dist-packages/myapi \
        /usr/local/lib/python2.7/dist-packages/oldname
  </code></pre>
  
  <p>But that is hacky and will most certainly confuse Python's import system and lead to other problems (<code>oldname.__name__</code>, <code>pip show oldname</code> and such). Also it won't work with wheels. I prefer a built-in way but am not that deep into Python packaging that I would know one. Maybe there is a something I could put in my <code>setup.py</code> (which btw. uses <code>setuptools</code>). Any suggestions? Is there a better way?</p>