Furl

2.1.4 · active · verified Thu Apr 09

Furl is a Python library designed for simple and powerful manipulation of URLs. It provides an object-oriented interface to parse, modify, and generate URLs, allowing easy access and modification of schemes, hosts, paths, query parameters, and fragments. The current version is 2.1.4, and it generally follows an as-needed release cadence for bug fixes and minor improvements, with major versions indicating significant API changes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a `furl` object, access and modify its various components (scheme, host, path, query, fragment), and use methods like `join()` to combine URLs.

from furl import furl

# Create a URL object
f = furl("https://www.example.com/path/to/resource?param1=value1&param2=value2#fragment")
print(f"Original URL: {f.url}")

# Access components
print(f"Scheme: {f.scheme}")
print(f"Host: {f.host}")
print(f"Path: {f.path}")
print(f"Query parameters: {f.query.params}")
print(f"Fragment: {f.fragment}")

# Modify components
f.scheme = "http"
f.host = "api.example.org"
f.path /= "v1" # Append path segment
f.query.add("apikey", "YOUR_API_KEY") # Add a query parameter
f.remove(fragment=True) # Remove fragment

print(f"Modified URL: {f.url}")

# Join URLs
base = furl("http://base.com/foo")
relative = furl("/bar?baz=qux")
joined = base.join(relative)
print(f"Joined URL: {joined.url}")

view raw JSON →