Here is how I've used the spatial analyst tools to return a longest flow path line from the top of a watershed hope this helps:
import arcpy
from arcpy.sa import *
from arcpy import env
watershed = # Path to watershed polygon
dem = # Path to DEM
fdr = # path to flow direction
env.workspace = # path to output workspace
try:
intermediate = [] # Empty container for intermediate data
fdrClip = ExtractByMask(fdr, watershed) # Clip the flow direction raster to the watershed polygon
arcpy.SetProgressorLabel("Computing longest flow path for the basin...")
flowLength = Int(FlowLength(fdrClip, "DOWNSTREAM")) # Compute a downstream flow length raster
arcpy.CalculateStatistics_management(flowLength)
maxValue = int(arcpy.GetRasterProperties_management(flowLength, "MAXIMUM").getOutput(0)) # Get the maximum cell value from the flow length
maxCell = Con(flowLength, "1", where_clause="Value = {}".format(repr(maxValue))) # Return the maximum cell from flow length
lfpRas = CostPath(maxCell, dem, fdrClip, destination_field="Value") # Use cost path to compute raster line from the max cell
intermediate.append(lfpRas)
rasLine = arcpy.RasterToPolyline_conversion(lfpRas, "rasLine", "ZERO", simplify="NO_SIMPLIFY") # Generate a polyline from the cost path raster
intermediate.append(rasLine)
lfp = arcpy.Dissolve_management(rasLine, "LongestFlowPath") # Dissolve the polyline to generate a single longest flow path line
intermediate.append(lfp)
finally:
# Clean up intermediate data
arcpy.SetProgressorLabel("Removing Intermediate data... ")
for data in intermediate:
arcpy.Delete_management(data)
del intermediate