Skip to main content

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

Project description

linkfixer

linkfixer is a flexible and powerful Python library for cleaning, normalizing, and validating URLs. It supports everything from simple domain fixes to advanced query stripping, DNS verification, and structured parsing.


🚀 Features

  • Enforces and fixes missing schemes (http, https)
  • Optionally forces HTTPS
  • Strips tracking parameters like utm_, gclid, fbclid
  • Removes paths, trailing slashes, query strings, and fragments
  • Enforces www. prefix if needed
  • Checks domain validity and DNS resolution
  • Preserves or fixes non-http(s) schemes
  • Returns structured output or cleaned URL

📦 Installation

pip install linkfixer

🧠 Usage

from linkfixer import normalize_url

result = normalize_url("example.com/path?utm_source=google", remove_tracking=True)
if result["success"]:
    print(result["url"])
else:
    print("❌", result["error"])

⚙️ Parameters

Parameter Type Description
raw_url str The input URL to normalize
default_scheme str Scheme to use if missing (default: https)
force_https bool Force output scheme to HTTPS
force_www bool Add www. if missing
remove_tracking bool Strip common tracking parameters
remove_query_string bool Remove everything after ?
clear_paths bool Remove all URL path segments
remove_trailing_slash bool Remove trailing slash (if path is not /)
strip_fragment bool Remove #fragment section
add_query dict Add or override query parameters
output str "url" (default) or "parts" for structured breakdown
allow_non_http bool Allow non-HTTP schemes like ftp://, mailto:
blacklist_domains set Block specific domains like malicious.com
allowlist_tlds set Only allow specific TLDs like .com, .org
shortlink_domains set Detect shortlink domains (e.g., bit.ly)
tracking_params set Custom query keys to remove
idn_format str "punycode" or "unicode" domain format
verify_dns bool Check if domain resolves using DNS
verbose bool Print intermediate steps for debugging

🧪 Examples

normalize_url("example.com")
# → https://example.com

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

normalize_url("example.com/path?utm_source=google&fbclid=123", remove_tracking=True)
# → https://example.com/path

normalize_url("example.com/page/", remove_trailing_slash=True)
# → https://example.com/page

normalize_url("example.com", add_query={"lang": "en"})
# → https://example.com?lang=en

normalize_url("bit.ly/xyz", shortlink_domains={"bit.ly"})
# → { ..., "is_shortlink": True }

📤 Output Structure (output="parts")

{
  "success": True,
  "url": "https://example.com",
  "is_shortlink": False,
  "parts": {
    "scheme": "https",
    "netloc": "example.com",
    "path": "",
    "query": "",
    "fragment": "",
    "original_input": "example.com"
  }
}

📄 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.1.0.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.1.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: linkfixer-0.1.0.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.1.0.tar.gz
Algorithm Hash digest
SHA256 1141f35803b0ee4cfe6eb067c3e1b8830fd6a6bfcf5a7019465893a2787f0644
MD5 46463f90a87b1e3419ab693896c83c85
BLAKE2b-256 53f4f1c121fe4ab855495920ac311e2120453adc2c2de80a30b89dbb1dec62c8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: linkfixer-0.1.0-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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 84914cf540d1ff8b1977cf99c0148be5fb7dab69f6588535725d04dc75db9f83
MD5 0c4b932ffe35df1240aa54b2626b4ba1
BLAKE2b-256 fec3c1f5284af3e750a81deeaa2b43cc4cdf565442074238f365b68cd7062d6d

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