Skip to main content

Python URL Parser

PyPI - Format PyPI - Status Downloads PyPI - Python Version

A nice package to help you parse all types of URL's in vanilla python and return the parsed URL in groups.

To not brake the API parse_url (returns a dict) still works and we made get_url to get the url parts as as object instead.

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_base_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_base_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:
For parse_url use: result['top_domain]
For get_url use: result.top_domain

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

Changelog:

See CHANGELOG.md

Metadata

Release files for url-parser 3.0.3

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

Source distribution (sdist)

Source distribution for url-parser 3.0.3
File Size Uploaded Provenance Actions
url_parser-3.0.3.tar.gz 78.2 kB Without provenance Details for url_parser-3.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for url-parser 3.0.3
File Interpreter ABI Platform Actions
url_parser-3.0.3-py3-none-any.whl Python 3 none any Details for url_parser-3.0.3-py3-none-any.whl

Total release size: 156.1 kB

Release files / url_parser-3.0.3.tar.gz

Download URL url_parser-3.0.3.tar.gz
Size 78.2 kB
Tags Source
SHA-256 checksum
How to use checksums
402ffca6459e272fe91985a7d5f143731cb80236a3ff59322c0aa4cb8b97b0d2
BLAKE2b-256 checksum
How to use checksums
7f96e75d719350fbbbba3fbc7b85f6d960c06367f7201a256bab7f0b4fa966bc
Upload date
Uploaded using Trusted Publishing?
What is 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.1 CPython/3.8.3

Release files / url_parser-3.0.3-py3-none-any.whl

Download URL url_parser-3.0.3-py3-none-any.whl
Size 77.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0eaec4f935297b72ffffc2fe2baabd4f6a469189b7b56446e7243b0bc371a963
BLAKE2b-256 checksum
How to use checksums
7d3fbdc0f4b789f7f9d893bca5bfb80579c4d4e80c19f28d39e4a8fbeb9344a1
Upload date
Uploaded using Trusted Publishing?
What is 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.1 CPython/3.8.3

Security for url-parser 3.0.3

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