Skip to main content

Enhanced URL Parser

A powerful URL parser with detailed analysis.

Features

  • Parse URLs into components like protocol, host, path, query, and fragment.
  • Supports both IPv4 and IPv6 addresses.
  • Handles URLs with or without protocols.
  • Reconstruct the URL from parsed components.

Installation

pip install eurlparser

Usage

Here's how to use the EnhancedURLParser class to parse and analyze URLs.

Basic Example

from eurlparser import EnhancedURLParser

# Example URL
url = "https://user:password@www.example.com:8080/path/to/resource?query=python&foo=bar#section"

# Initialize the parser
parser = EnhancedURLParser(url)

# Access different components
print("Protocol:", parser.protocol)            # Output: https
print("Username:", parser.username)            # Output: user
print("Password:", parser.password)            # Output: password
print("Host:", parser.host)                    # Output: www.example.com
print("Port:", parser.port)                    # Output: 8080
print("Path:", parser.path)                    # Output: /path/to/resource
print("Query:", parser.query)                  # Output: {'query': ['python'], 'foo': ['bar']}
print("Fragment:", parser.fragment)            # Output: section

# Reconstruct the URL
reconstructed_url = parser.get_fixed_url()
print("Reconstructed URL:", reconstructed_url)
# Output: https://user:password@www.example.com:8080/path/to/resource?query=python&foo=bar#section

# Get a structured dictionary of the URL components
url_structure = parser.get_url_structure()
print("URL Structure:", url_structure)

Handling URLs Without Protocol

from eurlparser import EnhancedURLParser

# Example URL without protocol
url = "/www.example.com/path/to/resource?query=python"

# Initialize the parser
parser = EnhancedURLParser(url)

# Access components
print("Host:", parser.host)                    # Output: www.example.com
print("Path:", parser.path)                    # Output: /path/to/resource
print("Query:", parser.query)                  # Output: {'query': ['python']}

# Reconstruct the URL (defaults to path '/')
reconstructed_url = parser.get_fixed_url()
print("Reconstructed URL:", reconstructed_url)
# Output: www.example.com/path/to/resource?query=python

Parsing and Handling IPv6 Addresses

from eurlparser import EnhancedURLParser

# Example URL with IPv6 address
url = "http://[2001:db8::1]:8080/path?query=value"

# Initialize the parser
parser = EnhancedURLParser(url)

# Access components
print("Protocol:", parser.protocol)            # Output: http
print("Host:", parser.host)                    # Output: 2001:db8::1
print("Port:", parser.port)                    # Output: 8080
print("Path:", parser.path)                    # Output: /path
print("Query:", parser.query)                  # Output: {'query': ['value']}

# Reconstruct the URL
reconstructed_url = parser.get_fixed_url()
print("Reconstructed URL:", reconstructed_url)
# Output: http://[2001:db8::1]:8080/path?query=value

Handling Invalid or Unusual URLs

from eurlparser import EnhancedURLParser

# Example of an invalid protocol in the URL
url = "ht@tp://example.com/path"

# Initialize the parser
parser = EnhancedURLParser(url)

# Access components
print("Host:", parser.host)                    # Output: example.com
print("Path:", parser.path)                    # Output: /path
print("Protocol:", parser.protocol)            # Output: None (invalid protocol)

# Even with unusual inputs, the URL can be reconstructed correctly:
reconstructed_url = parser.get_fixed_url()
print("Reconstructed URL:", reconstructed_url)
# Output: example.com/path

Contribution

Feel free to contribute to the project by forking the repository and creating pull requests. If you encounter any issues or have suggestions, please open an issue on GitHub.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Metadata

Release files for eurlparser 0.0.2

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

Source distribution (sdist)

Source distribution for eurlparser 0.0.2
File Size Uploaded
eurlparser-0.0.2.tar.gz 7.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for eurlparser 0.0.2
File Interpreter ABI Platform
eurlparser-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 13.0 kB

Release files / eurlparser-0.0.2.tar.gz

Download URL eurlparser-0.0.2.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
23c9d2eaeee906d4a4653002feb55396a04a1f19d0965d49e1fb5c8f70e67bf3
BLAKE2b-256 checksum
How to use checksums
7caa0c22e88b4862160058b1c22ae0e2cd347fb8de9afe6f61b79ca9b7f34d7e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Release files / eurlparser-0.0.2-py3-none-any.whl

Download URL eurlparser-0.0.2-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f1bd379d8a20f712f9079776dd1b6eeb88638ceff69bf3254d1195184b555fa2
BLAKE2b-256 checksum
How to use checksums
a4d83e73526336a9ec2d57d770d3e8e4b76990b98b963c29d7e392df1427c747
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

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