url.py

Safe helpers for opening supported external URLs and fetching web resources.

Global Functions

def _http_url(url: str) -> Any

No documentation

def open_url(url: str) -> bool

Open an ``http``, ``https``, or ``mailto`` URL; return False otherwise.

def fetch_url(url: str, timeout: float = 5.0, parse: str = 'auto') -> Any

Fetch an HTTP(S) URL synchronously and return parsed content or ``None``.

This is a **blocking** network call.  ``parse`` may be ``"bytes"`` (raw
bytes), ``"text"`` (decoded text), ``"json"`` (decoded JSON), or
``"auto"`` (JSON when the content type says so, otherwise text for a
text content type, otherwise bytes).  Any invalid URL, non-2xx response,
timeout, connection failure, decode failure, or JSON parse failure returns
``None`` without raising.

Back to Utils Module