Skip to main content

cleanurl

Remove clutter from URLs and return a canonicalized version

Install

pip install cleanurl

or if you're using poetry:

poetry add cleanurl

Usage

By default cleanurl retuns a cleaned URL without respecting semantics. For example:

>>> import cleanurl
>>> r = cleanurl.cleanurl('https://www.xojoc.pw/blog/focus.html?utm_content=buffercf3b2&utm_medium=social&utm_source=snapchat.com&utm_campaign=buffe')
>>> r.url
'https://xojoc.pw/blog/focus'
>>> r.parsed_url
ParseResult(scheme='https', netloc='xojoc.pw', path='/blog/focus', params='', query='', fragment='')

The default parameters are useful if you want to get a canonical URL without caring if the resulting URL is still valid.

If you want to get a clean URL which is still valid call it like this:

>>> r = cleanurl.cleanurl('https://www.xojoc.pw/blog/////focus.html', respect_semantics=True)
>>> r.url
'https://www.xojoc.pw/blog/focus.html'

celeanurl.cleanurl parameters:

  • generic -> if True don't use site specific rules
  • respect_semantics -> if True make sure the returned URL is still valid, altough it may still contain some superfluous elements
  • host_remap -> whether to remap hosts. Example:
>>> import cleanurl
>>> cleanurl.cleanurl('https://threadreaderapp.com/thread/1453753924960219145', host_remap=True).url
'https://twitter.com/i/status/1453753924960219145'
>>> cleanurl.cleanurl('https://threadreaderapp.com/thread/1453753924960219145', host_remap=False).url
'https://threadreaderapp.com/thread/1453753924960219145'

For more examples see the unit tests.

Why?

While there are some libraries that handle general cases, this library has website specific rules that more aggresivly normalize urls.

Users

Initially used for discu.eu.

Discussions around the web

Who?

cleanurl was written by Alexandru Cojocaru.

License

cleanurl is Free Software and is released as AGPLv3

Metadata

Release files for cleanurl 0.1.15

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cleanurl 0.1.15
File Size Uploaded Provenance Actions
cleanurl-0.1.15.tar.gz 18.3 kB Without provenance Details for cleanurl-0.1.15.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cleanurl 0.1.15
File Interpreter ABI Platform Actions
cleanurl-0.1.15-py3-none-any.whl Python 3 none any Details for cleanurl-0.1.15-py3-none-any.whl

Total release size: 36.9 kB

Release files / cleanurl-0.1.15.tar.gz

Download URL cleanurl-0.1.15.tar.gz
Size 18.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e05e9fe59491a5df51dd4a08015d82259cdd1c2fe2f6b573205d8ec09877bbaa
BLAKE2b-256 checksum
How to use checksums
92fbbf71e2b1060f36fb26f1b62f26f8a9d27c13a95b9a86310118f963071619
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.0 CPython/3.11.2 Linux/6.1.0-1-amd64

Release files / cleanurl-0.1.15-py3-none-any.whl

Download URL cleanurl-0.1.15-py3-none-any.whl
Size 18.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
24edd6f8d4d01b8781c709b122e0f0d55defa081535ef416f7f04aaedf9bde7a
BLAKE2b-256 checksum
How to use checksums
e6d932b98ad854a35cde655f462d0d0fc55ae052188eb54c7c835dfb8dd0b35e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.0 CPython/3.11.2 Linux/6.1.0-1-amd64

Security for cleanurl 0.1.15

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page