A tool to easily create complicated and dynamic URLs and headers.
Install
pip install http-prep
import httpprep
URL = httpprep.URL(
protocol="https",
subdomain="www",
domain="httpbin",
top_level_domain="org",
path_segments=["post"]
)
URL.components.queries["a", "b", "b" "c", "c"] = [1, 2, ..., 4, 5]
print(URL.build(query_check=...))
>>> 'https://www.httpbin.org/post?a=1&b=2&c=4'
HEADERS = httpprep.Headers()
HEADERS.Accept = "*/*"
HEADERS.Authorization = "abc123"
HEADERS.Content_Disposition = ...
HEADERS["Some-Non-Standard-Header"] = 1234
print(HEADERS.format_dict(...))
>>> {'Accept': '*/*', 'Authorization': 'abc123', 'Some-Non-Standard-Header': 1234}
print(HEADERS.format_list(...))
>>> [('Accept', '*/*'), ('Authorization', 'abc123'), ('Some-Non-Standard-Header', 1234)]
print(HEADERS.format_lines(...))
>>> ['Accept: */*', 'Authorization: abc123', 'Some-Non-Standard-Header: 1234']