Skip to main content

Remove clutter from URLs and return a canonicalized version

Project description

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

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

cleanurl-0.1.10.tar.gz (17.8 kB view details)

Uploaded Source

Built Distribution

cleanurl-0.1.10-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file cleanurl-0.1.10.tar.gz.

File metadata

  • Download URL: cleanurl-0.1.10.tar.gz
  • Upload date:
  • Size: 17.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.9.2 Linux/5.10.0-13-amd64

File hashes

Hashes for cleanurl-0.1.10.tar.gz
Algorithm Hash digest
SHA256 fa89f36ffe6b62adb9395baf839b09b8bddb3534836fc830c0e8333c49c56105
MD5 324aa1a3a3ad9c27b2287bfb726a7e89
BLAKE2b-256 265fcc0121ae5826f29d51d7710e0c67d167727621c5bf49909c5dbd797dc6a9

See more details on using hashes here.

File details

Details for the file cleanurl-0.1.10-py3-none-any.whl.

File metadata

  • Download URL: cleanurl-0.1.10-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.9.2 Linux/5.10.0-13-amd64

File hashes

Hashes for cleanurl-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 f31ed17fd50ff5eb05cd07334db4a00a42518dff7f32722df4e21023e73bd243
MD5 9d5e4c36f7cb5cbeb44228ea4017041d
BLAKE2b-256 e14668fa7aabd5d4a0772c60e2e6435639a7781ebbf6aa9a0481d21d462a80d0

See more details on using hashes here.

Supported by

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