title: Is it a good practice to pass db connection as parameter to methods?
body: <p>I am writing Python application to operate on Postgres database with SQLAlchemy. Specified the database information in a <code>settings.py</code></p>
  
  <pre><code>DATABASE = {
      'drivername': 'postgres',
      'host': 'xyz.com',
      'port': '5432',
      'username': 'user',
      'password': 'pass',
      'database': 'db_dev'
  }
  </code></pre>
  
  <p>Then I created a <code>db_connection.py</code> with a method to create a connection.</p>
  
  <pre><code>from sqlalchemy import *
  from sqlalchemy.engine.url import URL
  
  from . import settings
  
  def get_engine():
      return create_engine(URL(**settings.DATABASE))
  </code></pre>
  
  <p>I want to have another module <code>db_ops.py</code> that has all the database operation <code>func1</code>, <code>func2</code> methods and call them in the main application module</p>
  
  <pre><code>engine = db.connection.get_engine()
  db_ops.func1()
  db_ops.func2()
  </code></pre>
  
  <p>And that means I will need to pass <code>engine</code> as a parameter to these methods.</p>
  
  <pre><code>func1(engine)
  func2(engine)
  </code></pre>
  
  <p>Somehow I don't like the idea of making db connection as method parameter. Is there a better way to do it?</p>