title: the pythonic way of optional imports
body: <p>I have a package that allows the user to use any one of 4 packages they want to connect to a database. It works great but I'm unhappy with the way I'm importing things.</p>
  
  <p>I could simply import all the packages, but I don't want to do that in case the specific user doesn't ever need to use <code>turbodbc</code> for example:</p>
  
  <pre><code>import pyodbc
  import pymssql
  import turbodbc
  from ibmdbpy.base import IdaDataBase
  </code></pre>
  
  <p>Currently, I have the following situation. I try to import all of them, but the ones that don't import, no problem, My program simply assumes they will not be called and if they are it errors:</p>
  
  <pre><code># some envs may not have all these packages installed so we try each:
  
  try:
      import pyodbc
  except:
      pass
  
  try:
      import pymssql
  except:
      pass
  
  try:
      import turbodbc
  except:
      pass
  
  try:
      from ibmdbpy.base import IdaDataBase
  except:
      pass
  </code></pre>
  
  <p>This doesn't feel pythonic. So I know there are packages such as holoviews or tensorflow that allow you to specify a backend. They are of course orders of magnitude more complicated than mine, but they have to handle the same pattern.</p>
  
  <p>How can I make this code right? it is technically buggy because if they intend to use <code>pyodbc</code> but don't have it installed, my program will not warn them, it will error at runtime. So really this goes beyond esthetics or philosophy; this is technically error-prone code.</p>
  
  <p>How would you handle this situation?</p>
  
  <p>Fyi, here is an example of how the code is called:</p>
  
  <pre><code>connect('Playground', package='pymssql')
  </code></pre>