There were bound to be questions.
URLs were designed as a text format, so, apart from the principle of structuring structured data, why use URL objects?
There are two major advantages of using
representing URLs as strings. The first is that it’s really easy to
evaluate a relative hyperlink, for example, when crawling documents,
to figure out what is linked:
>>> URL.from_text(u'https://example.com/base/uri/').click(u"/absolute") URL.from_text(u'https://example.com/absolute') >>> URL.from_text(u'https://example.com/base/uri/').click(u"rel/path") URL.from_text(u'https://example.com/base/uri/rel/path')
The other is that URLs have two normalizations. One representation is
suitable for humans to read, because it can represent data from many
character sets - this is the Internationalized, or IRI, normalization.
The other is the older, US-ASCII-only representation, which is
necessary for most contexts where you would need to put a URI. You
can convert between these representations according to certain
URL exposes these conversions as methods:
>>> URL.from_text(u"https://→example.com/foo⇧bar/").to_uri() URL.from_text(u'https://xn--example-dk9c.com/foo%E2%87%A7bar/') >>> URL.from_text(u'https://xn--example-dk9c.com/foo%E2%87%A7bar/').to_iri() URL.from_text(u'https://\\u2192example.com/foo\\u21e7bar/')
For more info, see A Tale of Two Representations, above.
Hyperlink’s first release, in 2017, comes somewhere between 23 and 30 years after URLs were already in use. Is the URL really still that big of a deal?
Look, buddy, I don’t know how you got this document, but I’m pretty sure you (and your computer) used one if not many URLs to get here. URLs are only getting more relevant. Buy stock in URLs.
And if you’re worried that URLs are just another technology with an
obsoletion date planned in advance, I’ll direct your attention to the
IPvFuture rule in the BNF grammar. If it has plans to outlast
IPv6, the URL will probably outlast you and me, too.