title: Packaging python with circular imports
body: <p>I looked through previous questions to this effect, but my situation is slightly different...</p>
  
  <p>I've got a directory that contains several python classes that import one another here and there where necessary.  I'd like to start packaging them up into smaller modules, mostly for purposes of organization.  The central component of the package sets up a wsgi application and then additional modules provide functionality to it (this has worked great so far since I can test the mods individually on the command line before hooking their inputs up to the web app.)</p>
  
  <p>I understand how supplying an <code>__init__.py</code> module works, its namespacing, and when it releases control.  What I am having trouble with is that the modules in certain cases import one another.</p>
  
  <p>For example, I have a JSONEncoder that is used as the <code>cls</code> argument for many calls to <code>json.dumps()</code>  This class is used in virtually every file.  If I move some of these modules to subdirectories within the package, how would I go "up one level" to import the json encoder?  Would I need to put the parent directory on the PYTHONPATH in every file?  Would it be better to give the encoder its own directory as well, with a separate __init__.py file?</p>
  
  <p>Alternatively, would I just be better off putting in a function that drills down through all directories below the current working dir and adds them to the path?</p>
  
  <p>Currently the main directory that contains all the code is not package in of itself... what would be the best approach to migrating like classes to subdirectories taking into account that they have circular imports?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>For clarification:</p>
  
  <p>The main working directory I've been developing is just a regular directory containing about ten .py files, all of which contain classes with names like their filenames.  Currently the whole thing is just a git repo of .py files.</p>
  
  <pre><code>-project
    search.py
    jsonencoder.py
    webapp.py
    modela.py
    modelb.py
    modelc.py
  </code></pre>
  
  <p>Names are of course for example purposes.</p>
  
  <p>Now as I understand it (which could be totally wrong) the sensible thing to do would be to package those models together, correct?</p>
  
  <pre><code>-project
    search.py
    jsonencoder.py
    webapp.py
    -models
      __init__.py
      modela.py
      modelb.py
      modelc.py
  </code></pre>
  
  <p>But then in turn, would the <code>project</code> folder need an <code>__init__</code> too?  How would modela, which uses jsonencoder, import it?</p>