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
| Function | Returns | Description |
parse(text) | Result[Url, UrlError] | Parse a URL string |
builder() | UrlBuilder | Create a URL builder for programmatic construction |
encode_query(params) | Str | Encode a dict as a URL query string |
decode_query(s) | Dict[Str, Str] | Decode a query string into a dict |
encode_component(s) | Str | Percent-encode a single URL component |
Url fields
| Field | Type | Description |
.scheme | Str | Protocol (http, https, etc.) |
.host | Str | Hostname |
.port | Int? | Port number (None if not specified) |
.path | Str | Path component |
.query | Str? | Query string (without ?) |
.fragment | Str? | Fragment (without #) |