purl: A Simple, Immutable Python URL Class for Clean Manipulation
This repository profile is provided by osrepos.com, an open source repository discovery platform.

Summary
purl is a Python library offering a simple, immutable URL class designed for easy interrogation and manipulation of URLs. It provides a clean API, supports various Python versions, and includes features like URL template expansion based on RFC 6570. This makes it an excellent tool for handling URLs robustly in your Python projects.
Repository Information
Topics
Click on any tag to explore related repositories
Use at your own risk
OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of code from these repositories is the user's own responsibility. Always review the repository, source code, dependencies, licenses, and security implications before running or installing anything. OSRepos is not responsible for issues, damages, or losses resulting from third-party repositories.
Introduction
purl is a powerful yet simple Python library that provides an immutable URL class, offering a clean and intuitive API for interrogating and manipulating URLs. Designed for robustness, purl supports a wide range of Python versions, from 2.7 up to 3.8 and PyPy. A standout feature is its comprehensive support for template URLs, adhering to the specifications of RFC 6570.
Installation
Installing purl is straightforward. You can install the stable version from PyPI or the latest development version directly from GitHub.
To install from PyPI:
pip install purl
To install from GitHub (unstable):
pip install git+git://github.com/codeinthehole/purl.git#egg=purl
Examples
purl's API is designed for ease of use, allowing you to construct, interrogate, and manipulate URL objects efficiently.
Construction
You can create URL objects from strings, keyword arguments, or by chaining methods:
from purl import URL
# String constructor
from_str = URL('https://www.google.com/search?q=testing')
# Keyword constructor
from_kwargs = URL(scheme='https', host='www.google.com', path='/search', query='q=testing')
# Combine methods
from_combo = URL('https://www.google.com').path('search').query_param('q', 'testing')
A key aspect of purl is that URL objects are immutable; all methods that modify a URL return a new instance.
Interrogation
Accessing URL components is simple:
u = URL('https://www.google.com/search?q=testing')
print(u.scheme()) # 'https'
print(u.host()) # 'www.google.com'
print(u.path()) # '/search'
print(u.query()) # 'q=testing'
print(u.query_param('q')) # 'testing'
print(u.path_segments())# ('search',)
Manipulation
Accessor methods are overloaded to also act as mutators, returning a new URL instance:
u = URL.from_string('https://github.com/codeinthehole')
# Access
print(u.path_segment(0)) # 'codeinthehole'
# Mutate (creates a new instance)
new_url = u.path_segment(0, 'tangentlabs')
print(new_url is u) # False
print(new_url.path_segment(0)) # 'tangentlabs'
You can also build URLs step-by-step:
u = URL().scheme('http').domain('www.example.com').path('/some/path').query_param('q', 'search term')
print(u.as_string()) # 'http://www.example.com/some/path?q=search+term'
purl also supports URL templates as per RFC 6570:
from purl import Template, expand
tpl = Template("http://example.com{/list*}")
url = tpl.expand({'list': ['red', 'green', 'blue']})
print(url.as_string()) # 'http://example.com/red/green/blue'
expanded_url = expand(u"{/list*}", {'list': ['red', 'green', 'blue']})
print(expanded_url) # '/red/green/blue'
Why Use purl?
purl stands out for several reasons, making it an excellent choice for URL handling in Python:
- Immutability: All URL modifications return new instances, ensuring thread-safety and predictability. This also allows
URLobjects to be used as dictionary keys. - Clean and Consistent API: The API is intuitive, making it easy to interrogate and manipulate URL components with minimal boilerplate.
- RFC 6570 URL Templates: Full support for URI templates allows for powerful and flexible URL generation.
- Broad Python Compatibility: Works across a wide range of Python versions, ensuring compatibility for diverse projects.
- Robustness: Designed to handle various URL structures and edge cases, providing reliable URL parsing and construction.
Links
- GitHub Repository: codeinthehole/purl
- Official Documentation: purl.readthedocs.org
- PyPI Project Page: purl on PyPI
- RFC 6570 Specification: tools.ietf.org/html/rfc6570
Related repositories
Similar repositories that may be relevant next.

pyshorteners: Simplify URL Shortening in Python
July 27, 2026
pyshorteners is a Python library designed to make URL shortening effortless. It acts as a simple API wrapper, supporting various popular shortening services. Developers can easily integrate URL shortening capabilities into their Python applications with this versatile tool.

webargs: Efficient HTTP Request Argument Parsing for Python Web Frameworks
July 27, 2026
webargs is a robust Python library designed for parsing and validating HTTP request arguments across various web frameworks. It offers seamless integration with popular choices like Flask, Django, and aiohttp, simplifying the process of handling incoming request data. This library helps developers build more secure and reliable web applications by ensuring proper data validation.

scikit-video: Video Processing Routines for SciPy
July 27, 2026
scikit-video is a Python library designed for video processing, offering a suite of routines for tasks like I/O, quality metrics, and temporal filtering. Intended as a companion to scikit-image, it provides video-specific algorithms and aims for flexibility and GPU compute capabilities. This project offers a research-oriented alternative to existing frameworks, built entirely in Python.
vidgear: High-Performance Cross-Platform Video Processing Framework in Python
July 27, 2026
vidgear is a high-performance, cross-platform Python framework for advanced video processing. It provides a comprehensive, multi-threaded, and asyncio API for real-time video capture, writing, streaming, and network transfer. This framework simplifies complex media operations, enabling developers to build robust applications with ease.
Source repository
Open the original repository on GitHub.