Networking and Internet Modules

urllib.request

Builds URL requests and opens resources through protocol handlers. Request objects describe the target, method, data and headers without sending anything until opened. Real requests require destination validation, timeout and response-size controls; handlers can also access non-HTTP resources.

Formal Syntax & Structure

python syntaxpython
import urllib.request

Return Value

module

Module namespace available through import; import is a statement, not a value-returning expression.

Working Example

Example Snippetpython
from urllib.request import Requestrequest = Request("https://example.invalid/api", data=b"x=1")print(request.get_method())
Python Reference