And here's how to read coordinates from a single Placemark section in a bigger KML file, and build a smaller file with just that part:
from pykml import parser from lxml import etree from pykml.factory import KML_ElementMaker as KML with open('input.kml') as f: tree = parser.parse(f) root = tree.getroot() coords = root.Document.Folder.Placemark.LineString.coordinates doc = KML.kml( KML.Placemark( KML.name("test"), KML.Style(KML.LineStyle(KML.color("FF0000FF"))), KML.LineString( KML.coordinates(coords) ) ) ) outfile = open('output.kml','wb') outfile.write(etree.tostring(doc, pretty_print=True))