title: How to load data into existing database tables, using sqlalchemy?
body: <p>I have my data loaded from excel files and organized as python dict where each key is database table name and its value is defined as list of dictionaries (the rows)</p>
  
  <pre><code>system_data = {table_name1:[{'col_1':val1, 'col2': val1...},
                              {'col_1':val2, 'col2': val2..}..],     
                 table_name2:[{},{}..],[{},{}..]..}
  </code></pre>
  
  <p>This data needs to be loaded into existing database while picking <code>table_names</code> keys and values from <code>system_data</code>.</p>
  
  <p>Additionally I use ordered_table list which I've created in specific order to avoid FK problems while data is being loaded.  </p>
  
  <p>Here is the code (one of the 1000 versions I've tried):</p>
  
  <pre><code>from sqlalchemy import create_engine
  from sqlalchemy.sql import insert
  
  def alchemy_load():
      system_data = load_current_system_data()
      engine = create_engine('mysql+pymysql://username:password@localhost/my_db')
      conn = engine.connect()
      for table_name in ordered_tables:
          conn.execute(insert(table_name, system_data[table_name]))
      print("System's Data successfully loaded into Database!")
  </code></pre>
  
  <p>This function yield a following error: </p>
  
  <pre><code>"TypeError: 'method' object is not iterable"
  </code></pre>
  
  <p>I've wasted almost all day on this stuff ((( </p>
  
  <p>All the online examples describe the situation when a user uses MetaData and creates its own tables... There is nothing about how to actually add data into existing tables.</p>
  
  <p>There is a solution to my problem using "dataset" library.</p>
  
  <p>The code:</p>
  
  <pre><code>import dataset
  
  def current_data():
      db = dataset.connect(url='mysql+pymysql://user:pass@localhost/my_db')
      system_data = load_current_system_data()
  
      for table_name in ordered_tables:
          db[table_name].insert_many(system_data[table_name])
      print("System's Data successfully loaded into Database!")
  </code></pre>
  
  <p>BUT, I have no idea how to implement this code using sqlalchemy...</p>
  
  <p>Any help will be appreciated.</p>