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.1.tar.gz (4.4 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.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: linkfixer-0.2.1.tar.gz
  • Upload date:
  • Size: 4.4 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.1.tar.gz
Algorithm Hash digest
SHA256 d9ba7c0f35ce1237de214e13a27221aad4df51536f7dbdd5aa43ba86ace87e75
MD5 e8afd7335d58619c76be758c3f4f7b24
BLAKE2b-256 fa66dc9ad605b286f3400fd1691558c6a0136adc594a5d2cbf971f17c6abce59

See more details on using hashes here.

File details

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

File metadata

  • Download URL: linkfixer-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 4.9 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 208fadf7e62d1226ce7d5bf36d91c7e7713c889cbef8c25050c9d9f329f0d719
MD5 56665c418a05c8631f4b17ee163701f0
BLAKE2b-256 97ef3ab56d40b503c4252c9434f2aa9bd00e317edf4c3346e97346e77a9252ce

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