Socket
Socket
Sign inDemoInstall

url-parser

Package Overview
Dependencies
0
Maintainers
2
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    url-parser

Parse url and get all the different parts out of it


Maintainers
2

Readme

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:

KeywordDesriptionValue when not present in URL
protocolThe protocol, e.g. https or ftpNone
wwwReturns www if www is used in the URLNone
sub_domainThe sub domain, e.g. my.subdomain in my.subdomain.example.com. Note that the sub domain also includes www.None
domainThe domain, e.g. example in example.comIs always present
top_domainThe domain, e.g. com in example.comIs always present
dirThe directory, e.g. /my/directory/ in example.com/my/directory/None
fileThe file, e.g. my_file.js in example.com/home/my_file.jsNone
pathThe full path, e.g. /home/my_file.js in example.com/home/my_file.jsNone
fragmentThe URL fragment, e.g. my_link in example.com#my_linkNone
queryThe URL query, e.g. my_parameter=1&foo=bar in example.com?my_parameter=1&foo=barNone

Testing

Use the following command to run tests.

python -m unittest url_parser.tests.test_url_parser

Changelog:

See CHANGELOG.md

FAQs


Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc