# Access to saved flows from script

**URL:** <https://discourse.mitmproxy.org/t/access-to-saved-flows-from-script/173>\
**Category:** Uncategorized\
**Created:** [September 17, 2016, 8:05pm UTC](https://discourse.mitmproxy.org/t/access-to-saved-flows-from-script/173 "2016-09-17T20:05:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sheebz](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mitmproxy.org/sheebz/32/60_2.png) [@sheebz](https://discourse.mitmproxy.org/u/sheebz)\
**Post date:** [September 17, 2016, 8:05pm UTC](https://discourse.mitmproxy.org/t/access-to-saved-flows-from-script/173/1 "2016-09-17T20:05:31Z")

</div>

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,

---

<div class="post-metadata">

**Author:** ![dufferzafar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mitmproxy.org/dufferzafar/32/24_2.png) [@dufferzafar](https://discourse.mitmproxy.org/u/dufferzafar)\
**Post date:** [September 19, 2016, 7:28pm UTC](https://discourse.mitmproxy.org/t/access-to-saved-flows-from-script/173/2 "2016-09-19T19:28:10Z")

</div>

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()
```

---

<div class="post-metadata">

**Author:** ![sheebz](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mitmproxy.org/sheebz/32/60_2.png) [@sheebz](https://discourse.mitmproxy.org/u/sheebz)\
**Post date:** [September 21, 2016, 5:45pm UTC](https://discourse.mitmproxy.org/t/access-to-saved-flows-from-script/173/3 "2016-09-21T17:45:26Z")

</div>

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?
