urllibparsequote
urllib.parse.quote is a function in Python’s standard library module urllib.parse that percent-encodes a string for safe inclusion in a URL. It converts characters outside an allowed set into their %XX hexadecimal representations, ensuring the resulting string can be transmitted in a URL without misinterpretation.
The function signature is quote(string, safe='/', encoding='utf-8', errors='strict'). The safe parameter specifies characters that should not
Common usage includes constructing query or path components from user input. For example, quote("caf\xc3\xa9") returns 'caf%C3%A9'
- from urllib.parse import quote; quote("[email protected]") -> 'email%40example.com'
- quote("café", encoding="utf-8") -> 'caf%C3%A9'
- quote("path with spaces/", safe="/") -> 'path%20with%20spaces/'
See also: quote_plus, unquote, unquote_plus, urlencode, and the urllib.parse module documentation.