Access to saved flows from script

I have a script and want to return a saved response if ‘xyz’ in flow.request.url. Is there a way to access the saved flows? Is there a way to do something like this? -

for flow in mitmproxy.ctx.saved_flows
   if flow.url === 'xyz'
   return flow


Assuming you have your flows saved in a file named “flows.list”

You can do: mitmdump -r flows.list -s

Where file contains:

def request(flow):
    if flow.request.url == 'xyz':

Thanks for the reply. The answer you suggested seems to work nicely. However, I cannot seem to make updates to the response content stick. Any thoughts?

def response(flow):
         flow.response.set_content(replaced_content)  # does not persist on playback

mitmdump -ns scripts/ -r ~/./flows/dev2.flow -w dstfile.flow
mitmdump -S ./dstfile.flow -p 9053 --insecure -k --no-pop

I do not see updated content in output?