How can I create a line, with Python functions, with many points that are records in PostGIS?
Not 100% what you are asking for, but why not creating the line in PostGIS first?
SELECT gps.gps_track, ST_MakeLine(gps.the_geom ORDER BY gps_time) As newgeom FROM gps_points As gps GROUP BY gps.gps_track;
That will create a different line for each gps track and order them by time. I use that to create bus routes, ordered by stop sequence.
Really fast too.