Examples
Unwrap a short link
Inspect the whole chain
from lupaxa.real_url import resolve
for url in resolve("https://example.com", full=True):
print(url)
Include status codes
from lupaxa.real_url import resolve
for hop in resolve("https://example.com", status=True):
print(f"{hop.status} {hop.url}")
Detect a loop
from lupaxa.real_url import RedirectLoopError, resolve
try:
resolve("https://example.com")
except RedirectLoopError as exc:
print("Loop:", [hop.url for hop in exc.hops])
Cap the hop count
from lupaxa.real_url import TooManyRedirectsError, resolve
try:
resolve("https://example.com", max_redirects=5)
except TooManyRedirectsError as exc:
print(f"Stopped after {len(exc.hops)} hops")
Shell
Capture the landing URL when the lookup succeeds:
if landing="$(real-url https://example.com)"; then
echo "Landed on $landing"
else
echo "Could not resolve"
fi
Print the chain with statuses: