2017-08-30, furl

less than 1 minute read


Furl is a python package that enables the manipulation and use of urls. I think it is fantastic and much more readable than the string concat methods employed by many. github - furl

How does it work?

from furl import furl
f = furl('https://someapi/v2/checks/data')
query_string={"range":"last_hour", "metrics": ["server_time", "dom_load_time","start_render", "onload_time","visually_complete","fully_loaded_time","speed_index"],"api_key":"xxxxxx"}
f.args = query_string
print f.url

What it does is abstract the elements of the url. This allow it to start with a base url and then very easily add query string params to it. Also if there is repettion of the params such as “metrics” then it accpets a list and will iterate through the list to spawn out those params.
Additionally it has the ability to delete and manipulate params

>>> from furl import furl
>>> f = furl('http://www.google.com/?one=1&two=2')
>>> f.args['three'] = '3'
>>> del f.args['one']
>>> f.url

This, would have been a pain to do with some string splits and or regexs in order to find the params and remove them.