title: How to properly deal with optional features in python
body: <p>I'm working on python packages that implement scientific models and I'm wondering what is the best way to handle optional features.
  Here's the behavior I'd like:
  If some optional dependencies can't be imported (plotting module on a headless machine for example), I'd like to disable the functions using these modules in my classes, warn the user if he tries to use them and all that without breaking the execution.
  so the following script would work in any cases:</p>
  
  <pre><code>mymodel.dostuff()
  mymodel.plot() &lt;= only plots if possible, else display log an error 
  mymodel.domorestuff() &lt;= get executed regardless of the result of the previous statement
  </code></pre>
  
  <p>So far the options I see are the following:</p>
  
  <ul>
  <li>check in the <code>__init __.py</code> for available modules and keep a list of
  them (but how to properly use it in the rest of the package?) </li>
  <li>for each function relying on optional dependencies have a <code>try import ... 
  except ...</code> statement </li>
  <li>putting functions depending on a particular module in a separated file</li>
  </ul>
  
  <p>These options should work, but they all seem to be rather hacky and hard to maintain. what if we want to drop a dependency completely? or make it mandatory?</p>