Standard Library

URL

The url module parses, builds, and encodes URLs.

from url import parse, builder, encode_query

let u = parse("https://example.com/path?q=hello").unwrap()
print(u.host)     # example.com
print(u.path)     # /path

let built = builder()
    .scheme("https")
    .host("api.example.com")
    .path("/v1/search")
    .query("q", "vary lang")
    .build()

let qs = encode_query({"key": "value", "name": "Alice"})

Functions

FunctionReturnsDescription
parse(text)Result[Url, UrlError]Parse a URL string
builder()UrlBuilderCreate a URL builder for programmatic construction
encode_query(params)StrEncode a dict as a URL query string
decode_query(s)Dict[Str, Str]Decode a query string into a dict
encode_component(s)StrPercent-encode a single URL component

Url fields

FieldTypeDescription
.schemeStrProtocol (http, https, etc.)
.hostStrHostname
.portInt?Port number (None if not specified)
.pathStrPath component
.queryStr?Query string (without ?)
.fragmentStr?Fragment (without #)
← Money
UUID →