PackageDescription | yet another URL library for Python
URL is constructed from `str`:
.
>>> from yarl import URL
>>> url = URL('https://www.python.org/~guido?arg=1#frag')
>>> url
URL('https://www.python.org/~guido?arg=1#frag')
.
All URL parts: scheme, user, passsword, host, port, path, query and fragment
are accessible by properties:
.
>>> url.scheme
'https'
>>> url.host
'www.python.org'
>>> url.path
'/~guido'
>>> url.query_string
'arg=1'
>>> url.query
<MultiDictProxy('arg': '1')>
>>> url.fragment
'frag'
.
All URL manipulations produces a new URL object:
.
>>> url.parent / 'downloads/source'
URL('https://www.python.org/downloads/source')
.
Strings passed to constructor and modification methods are automatically
encoded giving canonical representation as result::
.
>>> url = URL('https://www.python.org/путь')
>>> url
URL('https://www.python.org/%D0%BF%D1%83%D1%82%D1%8C')
.
Regular properties are percent-decoded, use `raw_` versions for getting
encoded strings:
.
>>> url.path
'/путь'
.
>>> url.raw_path
'/%D0%BF%D1%83%D1%82%D1%8C'
.
Human readable representation of URL is available as `.human_repr()`:
.
>>> url.human_repr()
'https://www.python.org/путь' |