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

Thanks,

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

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

Where script.py file contains:

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

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/add_header.py -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?