Get primary key after inserting rows using sqlalchemy

Maybe your ResultsProxy is a list or list-like object, so you should iterate over the elements=db-rows of that object:

for e in topic_res:
    print e.inserted_primary_key

EDIT: the method "inserted_primary_key" seems to work only for single-row insertions. See http://docs.sqlalchemy.org/en/rel_0_6/core/connections.html#sqlalchemy.engine.base.ResultProxy.inserted_primary_key


the inserted_primary_key attribute is only functional for a single-row insert:

https://docs.sqlalchemy.org/en/latest/core/connections.html#sqlalchemy.engine.ResultProxy.inserted_primary_key

This only applies to single row insert() constructs which did not explicitly specify Insert.returning().

this is due to a widely prevalent limitation in database client libraries including all Python DBAPIs where only one "last inserted id" attribute is left available at a time.