Skip to main content

Parse url and get all the different parts out of it

Project description

URL Parser

PyPI - Format PyPI - Status Downloads PyPI - Python Version

A small yet nice package to help you parse all types of URL's and return the parsed URL in groups.
To not brake the API parse_url (returns a dict) still works and we made a new function to get the url parts as as object instead called get_url.
In version 2.1 we also included get_basic_url a small yet neat function to get a the main url back from a string

Installation

pip install url-parser

Usage

from url_parser import parse_url, get_url, get_basic_url


url = parse_url('https://open.prospecta.app/my_user_login?user=url-parser&password=H3ll0') # returns url sections as a dict  
url_object = get_url('https://open.prospecta.app/my_user_login?user=url-parser&password=H3ll0') # Does the same, bur returns a object  
basic_url = get_basic_url('https://open.prospecta.app/my_user_login?user=url-parser&password=H3ll0') # Returns just the main url  

print(url['domain']) # Outputs -> prospecta  
print(url_object.domain) # Outputs -> prospecta  
print(basic_url) # Outputs -> https://open.prospecta.app  

Keywords get_url and parse_url

When using the parse_url and get_url function, you get a dict (parse_url) or object (get_url) back with different parts of the URL.

The different parts can be accessed by keywords like this:
result['top_domain] <- For parse_url
result.top_domain <- For get_url

Here is a list of all the available keywords:

Keyword Desription Value when not present in URL
protocol The protocol, e.g. https or ftp None
www Returns www if www is used in the URL None
sub_domain The sub domain, e.g. my.subdomain in my.subdomain.example.com. Note that the sub domain also includes www. None
domain The domain, e.g. example in example.com Is always present
top_domain The domain, e.g. com in example.com Is always present
dir The directory, e.g. /my/directory/ in example.com/my/directory/ None
file The file, e.g. my_file.js in example.com/home/my_file.js None
path The full path, e.g. /home/my_file.js in example.com/home/my_file.js None
fragment The URL fragment, e.g. my_link in example.com#my_link None
query The URL query, e.g. my_parameter=1&foo=bar in example.com?my_parameter=1&foo=bar None

Testing

Use the following command to run tests.

python -m unittest url_parser.tests.test_url_parser.TestUrlParser

Versions:

v 2.1.0 | Added function to get url back as Object. Also added a function to get the basics of a url returned
v 2.0.0 | Added new regex and support for foreign languages
v 1.0.0 | Small bugfixes and optimisation for stable release
v 0.9.9 | Bugfixes on the readme file.
v 0.9.8 | Added support for args.
v 0.9.7 | Changed setup.py and readme for PyPi optimisation.
v 0.9.6 | Added support for secondary top domain (like: co.uk, .parliament.uk, .gov.au).

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

url_parser-2.1.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

url_parser-2.1.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file url_parser-2.1.0.tar.gz.

File metadata

  • Download URL: url_parser-2.1.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for url_parser-2.1.0.tar.gz
Algorithm Hash digest
SHA256 ce8ea6ca50410ec3d321eb4a32013dfbd8c12a97612639c9af21d4775853b24a
MD5 e3e936005c8d0b053c2a861c1cd0c846
BLAKE2b-256 153f9c955ba811ea92d4ef3523e94eb567a1a2fe3af2c1665477a7d280003c09

See more details on using hashes here.

File details

Details for the file url_parser-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: url_parser-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for url_parser-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cb07aef725a41829c9a2f0984d7a4e3a3031dde3495dd7ecfc1909477d44640c
MD5 6e1aa03dd5e19bedfef36f775963217f
BLAKE2b-256 4a7d38da0002bf905aec9effbea429ca31d9919cc796e9f74e0165138f0674b3

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