A helper library full of URL-related heuristics.
Project description
Ural
A helper library full of URL-related heuristics.
Installation
You can install ural
with pip with the following command:
pip install ural
Usage
ensure_protocol
A function checking if the url has a protocol, and adding the given one if there is none.
from ural import ensure_protocol
ensure_protocol('www2.lemonde.fr', protocol='https')
>>> 'https://www2.lemonde.fr'
Arguments
- url string: URL to format.
- protocol string: protocol to use if there is none in url. Is 'http' by default.
force_protocol
A function force-replacing the protocol of the given url.
from ural import force_protocol
force_protocol('https://www2.lemonde.fr', protocol='ftp')
>>> 'ftp://www2.lemonde.fr'
Arguments
- url string: URL to format.
- protocol string: protocol wanted in the output url. Is
'http'
by default.
is_url
A function returning True if its argument is a url.
from ural import is_url
is_url('https://www2.lemonde.fr')
>>> True
Arguments
- string string: string to test.
- require_protocol boolean: whether the argument has to have a protocol to be considered a url. Is
True
by default.
normalize_url
Function normalizing the given url by stripping it of usually non-discriminant parts such as irrelevant query items or sub-domains etc.
This is a very useful utility when attempting to match similar urls written slightly differently when shared on social media etc.
from ural import normalize_url
normalize_url('https://www2.lemonde.fr/index.php?utm_source=google')
>>> 'lemonde.fr'
Arguments
- url string: URL to normalize.
- sort_query boolean [
True
]: whether to sort query items. - strip_authentication boolean [
True
]: whether to strip authentication. - strip_index boolean [
True
]: whether to strip trailing index. - strip_trailing_slash boolean [
False
]: whether to strip trailing slash.
strip_protocol
Function removing the protocol from the url.
from ural import strip_protocol
strip_protocol('https://www2.lemonde.fr/index.php')
>>> 'www2.lemonde.fr/index.php'
Arguments
- url string: URL to format.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ural-0.4.0.tar.gz
.
File metadata
- Download URL: ural-0.4.0.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dff1512b31d62f5ae862647f1d47d61e31ea56fda34157082dca1d1d2238fd14 |
|
MD5 | 80e7ac467093ca9977851669ac67930d |
|
BLAKE2b-256 | d07bdd36c65908f5194556e6fd13b0562a758db765efc2dc11a0fd4f070a516b |
File details
Details for the file ural-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: ural-0.4.0-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3735b44ea753e3d675fd74955cd288850084aa803e5ba5413a0822c2efa5464 |
|
MD5 | abe1bd726844cac86b4d07d2bdefc766 |
|
BLAKE2b-256 | 373e9b5d385adeac56f3c1a99a86f2bf4163d094a47a06ba2db956de1b53cb28 |