Skip to main content

A Python library to normalize, clean, and validate URLs.

Project description

linkfixer

linkfixer is a Python library for cleaning, normalizing, and validating messy or partial URLs. It transforms any input — paths, queries, or malformed links — into well-formed, full URLs.


🚀 Features

  • Default scheme handling (auto-prepends https:// if needed)
  • Optional base domain attachment for partial URLs
  • Path and query cleanup
  • www prefix enforcement
  • Tracking parameter stripping (utm_source, gclid, etc.)
  • Trailing slash and fragment removal
  • DNS resolution check
  • Smart relative-to-absolute URL building
  • Structured output or clean URL string
  • Friendly error messages for malformed input

🧠 Smart Use Case Handling

normalize_url("example.com/path")
 https://example.com/path

normalize_url("/docs", base_domain="example.com")
 https://example.com/docs

normalize_url("?ref=abc", base_domain="example.com")
 https://example.com/?ref=abc

normalize_url("ftp://example.com", allow_non_http=False)
 https://example.com

⚙️ Parameters

Parameter Type Description
raw_url str The input URL (may be partial or relative)
base_domain str Optional domain to attach to relative URLs
default_scheme str Scheme to use when missing (default: https)
force_https bool Enforces HTTPS
force_www bool Add www. if missing
remove_tracking bool Strip known tracking query params
remove_query_string bool Remove entire query string
clear_paths bool Remove all paths
remove_trailing_slash bool Remove trailing slash from path
strip_fragment bool Remove #fragment
add_query dict Add or override query params
output str "url" or "parts"
allow_non_http bool Allow ftp://, mailto:, etc.
blacklist_domains set Domains to reject
allowlist_tlds set Allow only certain TLDs
shortlink_domains set Domains to detect as shortlinks
tracking_params set Custom keys to remove from query
idn_format str "punycode" or "unicode"
verify_dns bool Ensure domain resolves via DNS
verbose bool Enable debug logs

✅ Error Handling

Invalid URLs return a clear structured result:

{
  "success": False,
  "error": "Missing domain — please provide a valid raw_url or base_domain"
}

📤 Output Modes

✅ Full URL (default)

normalize_url("example.com/path")
 "https://example.com/path"

✅ Structured Parts

normalize_url("example.com/path", output="parts")
 {
  "success": True,
  "url": "https://example.com/path",
  "parts": {
    "scheme": "https",
    "netloc": "example.com",
    "path": "/path",
    ...
  }
}

📄 License

MIT © 2025 Renukumar R

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

linkfixer-0.2.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

linkfixer-0.2.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file linkfixer-0.2.0.tar.gz.

File metadata

  • Download URL: linkfixer-0.2.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for linkfixer-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e40f21843219a4309a676cf28dd948ceeae18ff5578427ba6a0ec4aa1e620c2f
MD5 9b492b27515b3cebad19587cb6689b0e
BLAKE2b-256 62fd1cd88ef44766f5c3c8b3c2487513934b00d33c351edfdf517077c2579c28

See more details on using hashes here.

File details

Details for the file linkfixer-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: linkfixer-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for linkfixer-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c8d7d73558e20c5a211872d0d058e19122777f7a9815073fea48baffb68548fc
MD5 981e20fb095495c480557a1a2a11c85a
BLAKE2b-256 6def65337d2fe6dea8563a7e86597e18403901d20e603ef10343db9e912a9f20

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page