URL manipulation made simple.



Badge fury Build status

furl is a small Python library that makes manipulating URLs simple.

Python's standard urllib and urlparse modules provide a number of URL manipulation functions, but using these functions to perform common URL manipulations proves tedious. Furl makes manipulating URLs easy.

Furl is well tested, Unlicensed in the public domain, and supports both Python 2 and 3.

Query arguments are easy. Really easy.

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

Or use furl's inline modification methods.

>>> furl('http://www.google.com/?one=1').add({'two':'2'}).url

>>> furl('http://www.google.com/?one=1&two=2').set({'three':'3'}).url

>>> furl('http://www.google.com/?one=1&two=2').remove(['one']).url

Encoding is handled for you. Unicode, too.

>>> f = furl('http://www.google.com/')
>>> f.path = 'some encoding here'
>>> f.args['and some encoding'] = 'here, too'
>>> f.url
>>> f.set(host=u'ドメイン.テスト', path=u'джк', query=u'☃=☺')
>>> f.url

Fragments also have a path and a query.

>>> f = furl('http://www.google.com/')
>>> f.fragment.path.segments = ['two', 'directories']
>>> f.fragment.args = {'one':'argument'}
>>> f.url

Or get fancy.

>>> f = furl('http://www.google.com/search?q=query#1')
>>> f.copy().remove(path=True).set(host='taco.com')
...  .join('/pumps.html').add(fragment_path='party').url


See more furl magic and examples in furl's API document, API.md.


Installing furl with pip is easy.

$ pip install furl