purl: A Simple, Immutable Python URL Class for Clean Manipulation

This repository profile is provided by osrepos.com, an open source repository discovery platform.

purl: A Simple, Immutable Python URL Class for Clean Manipulation

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

Analyzed by OSRepos on July 27, 2026

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 URL objects 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

Related repositories

Similar repositories that may be relevant next.

AREX-Skill: A Skill Library for Automated Machine Learning and Auto-Research

AREX-Skill: A Skill Library for Automated Machine Learning and Auto-Research

September 21, 2026

AREX-Skill is a powerful skill library designed to advance automated machine learning and auto-research. It distills over 5,000 executable skills from more than 1,000 popular GitHub repositories, making complex ML knowledge directly usable by coding agents. This project significantly enhances agent performance in various research tasks by providing structured, validated operating knowledge.

PythonAutomated Machine LearningAI Agents
oh-my-hermes: Enhance Hermes Agent with Advanced AI Workflow and Memory

oh-my-hermes: Enhance Hermes Agent with Advanced AI Workflow and Memory

September 17, 2026

oh-my-hermes is an all-in-one plugin designed to significantly enhance the Hermes Agent. It provides advanced coding intelligence, a robust long-term memory system, and optimized workflow packages, transforming standard Hermes requests into structured, actionable tasks with clear operational layers.

AI AgentHermes AgentAI Tools
ASC: A Super Fast Android Decompiler for Mobile Reverse Engineering

ASC: A Super Fast Android Decompiler for Mobile Reverse Engineering

September 17, 2026

ASC is an innovative and exceptionally fast Android decompiler front-end, specifically designed for mobile researchers and agents. It redefines traditional decompilation by directly querying compiled artifacts, offering on-demand code extraction and analysis without heavy preprocessing. This approach results in significantly reduced memory usage and lightning-fast performance, even on large APKs.

AndroidDecompilerReverse Engineering
Open Index: A Deterministic Memory Layer for Your AI Agents

Open Index: A Deterministic Memory Layer for Your AI Agents

September 16, 2026

Open Index is a powerful tool for building domain-specific, accurate, and structured data that AI agents can effectively operate on. It enables the creation of a "brain," a searchable and continuously improving context graph tailored to any domain. This system ensures agents have access to reliable, up-to-date information, enhancing their capabilities and decision-making processes.

AI AgentsKnowledge GraphAgent Memory

Source repository

Open the original repository on GitHub.

20 counted GitHub visits

View on GitHub
OS
OSRepos

Analysis and discovery of open source repositories. Find interesting projects and follow their updates.

Monitor your website with YourWebsiteScore

OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of third-party repository code is at your own risk. Always review source code, dependencies, licenses, and security implications before running anything.

© 2025 OSRepos. Built with Nuxt 3 and lots of ❤️