Yet another URL library
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, password, 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/путь'
For full documentation please read https://yarl.readthedocs.org.
$ pip install yarl
The library is Python 3 only!
YARL requires multidict library.
The documentation is located at https://yarl.readthedocs.org
Comparison with other URL libraries
The library has a rich functionality but furl object is mutable.
I afraid to pass this object into foreign code: who knows if the code will modify my url in a terrible way while I just want to send URL with handy helpers for accessing URL properties.
furl has other non obvious tricky things but the main objection is mutability.
URLObject is immutable, that’s pretty good.
Every URL change generates a new URL object.
But the library doesn’t any decode/encode transformations leaving end user to cope with these gory details.
The project is hosted on GitHub
Please file an issue on the bug tracker if you have found a bug or have some suggestion in order to improve the library.
The library uses Travis for Continuous Integration.
aio-libs google group: https://groups.google.com/forum/#!forum/aio-libs
Feel free to post your questions and ideas here.
- Properly support paths without leading slash in
- Enable type annotation checks
- Normalize path #86
- Clear query and fragment parts in
- Prevent double URL args unquoting #83
- Unexpected hash behaviour #75
- Unexpected compare behaviour #73
- Do not quote or unquote + if not a query string. #74
URL.buildclass method #58
- Do not quote “:” in path
- Load from pickle without _cache #56
- Percent-encoded pluses in path variables become spaces #59
- Revert backward incompatible change (BaseURL)
- Fix BaseURL rich comparison support
- Use BaseURL
- Added BaseURL
- Remove debug print
- Do not lose tail chars #45
- Allow to quote % in non strict mode #21
- Incorrect parsing of query parameters with %3B (;) inside #34
- core dumps #41
- tmpbuf - compiling error #43
- Fix broken aiohttp: revert back
- Support more verbose error messages in
- Don’t percent-encode
:in path #32
- Don’t expose
yarl.unquote, these functions are part of private API
- Accept not only
strbut all classes inherited from
intas value for
- Explicitly use UTF8 encoding in setup.py #20
- Properly unquote non-UTF8 strings #19
- Don’t use namedtuple fields but indexes on URL construction
- Make URL construction faster by removing extra classmethod calls
- Add cython optimization for quoting/unquoting
- Provide binary wheels
- Fix typing stubs
- Expose quote() and unquote() as public API
- Support empty values in query (‘/path?arg’)
- Introduce relative() #16
- Typo fixes #15
- Support sequence of pairs as with_query() parameter
- Introduce is_default_port()
- Raise ValueError for URLs like ‘http://:8080/’
- Avoid doubling slashes when joining paths #13
- Appending path starting from slash is forbidden #12
- Add kwargs support for with_query() #10
- Document with_query(), with_fragment() and origin()
- Allow None for with_query() and with_fragment()
- Fix links, tune docs theme.
- Update README, old version used obsolete API
- The library was deeply refactored, bytes are gone away but all accepted strings are encoded if needed.
- The first release.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.