class SQLFunction(object):

    def __init__(self, connection):
        self.connection = connection

def __call__(self, args=None):
    self.cursor = self.connection.cursor()
self.run(args)
self.cursor.commit()
self.cursor.close()


class DeleteSession(SQLFunction):

    def run(self, args):
        self.cursor.execute('statement')
delete_session = DeleteSession(connection)
ищете более питонический способ доступа к базе данных