title: Python Module in Django
body: <p>I am building my first Django web application and I need a bit of advice on code layout. </p>
  
  <p>I need to integrate it with several other applications that are exposed through RESTful APIs and additionally Django's internal data. I need to develop the component that will pull data from various sources, django's DB, format it consistently for output and return it for rendering by the template. </p>
  
  <p>I am thinking of the best way to write this component. There are a couple of ways to proceed and I wanted to solicit some feedback from more experienced web developers on things I may have missed. </p>
  
  <p>Way #1</p>
  
  <p>Develop a completely standalone objects for interacting with other applications via their APIs, etc... This would not have anything related with django and test independently. Then in django, import this module in the views that need it, run object methods to get required data, etc... </p>
  
  <p>If I need to access any of this functionality via a GET request (like through JavaScript), I can have a dedicated view that imports the module and returns json. </p>
  
  <p>Way #2</p>
  
  <p>Develop this completely as django view(s) expose as a series of GET/POST calls that would all call each other to get the work done. This would be directly tied in the application. </p>
  
  <p>Way #3</p>
  
  <p>Start with Way #1, but instead of creating a view, package it as a django app. Develop unit tests on the app as well as the individual objects. </p>
  
  <p>I think that way 1 or 3 would be very much encapsulated and controlled.</p>
  
  <p>Way 2 would be more complicated, but facilitate higher component re-use. </p>
  
  <p>What is better from a performance standpoint? If I roll with Way #1 or 3, would an instance of the object be instantiated for each request? </p>
  
  <p>If so this approach may be a bit too heavy for this. If I proceed with this, can they be singletons? </p>
  
  <p>Anyway, I hope this makes sense. </p>
  
  <p>thanks in advance. </p>