furl

? URL parsing and manipulation made easy.

Github星跟蹤圖

furl is a small Python library that makes parsing andmanipulating URLs easy.

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

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

Code time: Paths and query arguments are easy. Really easy.

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

Or use furl's inline modification methods.

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

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

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

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
'http://www.google.com/some%20encoding%20here?and+some+encoding=here,+too'
>>> f.set(host=u'ドメイン.テスト', path=u'джк', query=u'☃=☺')
>>> f.url
'http://xn--eckwd4c7c.xn--zckzah/%D0%B4%D0%B6%D0%BA?%E2%98%83=%E2%98%BA'

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
'http://www.google.com/#two/directories?one=argument'

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
'http://taco.com/pumps.html#party'
>>>
>>> f.asdict()
{ 'url': 'http://taco.com/pumps.html#party',
  'scheme': 'http',
  'username': None,
  'password': None,
  'host': 'taco.com',
  'host_encoded': 'taco.com',
  'port': 80,
  'netloc': 'taco.com',
  'origin': 'http://taco.com',
  'path': { 'encoded': '/pumps.html',
            'isabsolute': True,
            'isdir': False,
            'isfile': True,
            'segments': ['pumps.html']},
  'query': { 'encoded': '',
             'params': []},
  'fragment': { 'encoded': 'party',
                'path': { 'encoded': 'party',
                          'isabsolute': False,
                          'isdir': False,
                          'isfile': True,
                          'segments': ['party']},
                'query': { 'encoded': '',
                           'params': []},
                'separator': True}, }

API

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

Installation

Installing furl with pip is easy.

$ pip install furl

主要指標

概覽
名稱與所有者gruns/furl
主編程語言Python
編程語言Python (語言數: 1)
平台
許可證Other
所有者活动
創建於2011-11-17 01:08:16
推送於2025-03-25 22:57:18
最后一次提交2025-03-25 15:57:18
發布數19
最新版本名稱v2.1.4 (發布於 2025-03-08 21:43:02)
第一版名稱v0.5 (發布於 )
用户参与
星數2.7k
關注者數36
派生數158
提交數563
已啟用問題?
問題數119
打開的問題數33
拉請求數21
打開的拉請求數7
關閉的拉請求數29
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?