title: Python 3 Best practices on distinguish production and development configuration
body: <p>I'm working on an embedded system project where my <code>dev</code> setup is different than my <code>prod</code>.
  The differences include variables and packages imports.</p>
  
  <p>What is the best way to structure the config files for python3 application where <code>dev</code> and <code>prod</code> setups are different?</p>
  
  <p><code>prod</code>: My device exchange messages (using <a href="https://pypi.org/project/pyserial/" rel="nofollow noreferrer">pyserial</a>) with an electronic system and also communicates with a server.</p>
  
  <p><code>dev</code>: I use a fake and fixed response from a function to mock both the electronic and server responses.
  Even if the functions that I mock are essential in <code>prod</code> they are less in <code>dev</code>.
  I can mock them because the most important part of this project are the functions that use and treat them.
  So, there are packages imports and function calls that do not make sense and introduce errors in <code>dev</code> mode.</p>
  
  <p>Every time I need to switch from one to another I need to change a good amount of the code and some times there are errors introduced. I know this is really () not the best approach and I wanted to know what are the <strong>best practices</strong>.</p>
  
  <h2>The Closest Solution Found</h2>
  
  <p><a href="https://softwareengineering.stackexchange.com/a/396762">Here</a> there is a good solution to set up different variables for each environment. I was hoping for something similar but for projects that require different packages import for different environments.</p>
  
  <h2>My Setup</h2>
  
  <p>Basic workflow:</p>
  
  <ul>
  <li>A <code>task</code> thread is executed each second
  
  <ul>
  <li><code>module_1</code> do work and call <code>module_2</code></li>
  <li><code>module_2</code> do work and call <code>module_3</code></li>
  <li><code>module_3</code> do work and send back a response</li>
  </ul></li>
  </ul>
  
  <p>Basic folder structure:</p>
  
  <ul>
  <li><code>root</code>
  
  <ul>
  <li><code>main</code></li>
  <li><code>config.py</code></li>
  <li><code>/config</code>
  
  <ul>
  <li><code>prod</code></li>
  <li><code>dev</code></li>
  </ul></li>
  <li><code>/mod_1</code></li>
  <li><code>/mod_2</code></li>
  <li><code>/mod_3</code></li>
  <li><code>/replace_imports</code></li>
  </ul></li>
  </ul>
  
  <p><code>module_1</code> and <code>module_3</code> use, each one, a specific package for <code>prod</code> and must be replaced by a <code>dev</code> function</p>
  
  <p>What do I have:</p>
  
  <pre class="lang-py prettyprint-override"><code># config.py
  if os.environ["app"] == "dev":
      import * from root.config.dev
  if os.environ["app"] == "prod":
      import * from root.config.prod
  </code></pre>
  
  <pre class="lang-py prettyprint-override"><code># config/prod.py
  import _3rd_party_module_alpha
  import _3rd_party_module_beta
  ...
  obj_alpha = _3rd_party_module_alpha()
  func_beta = _3rd_party_module_beta()
  </code></pre>
  
  <pre class="lang-py prettyprint-override"><code># config/dev.py
  import * from root.replace_imports
  </code></pre>
  
  <pre class="lang-py prettyprint-override"><code># replace_imports.py
  obj_alpha = fake_3rd_party_module_alpha()
  func_beta = fake_3rd_party_module_beta()
  </code></pre>