Furl
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
- breaking As of v2.1.4, furl dropped support for all Python versions prior to Python 3.8, which are now long past EOL.
- breaking The division operator (`/`) for `furl` and `Path` objects no longer modifies the instance in-place. It now returns a new instance, mirroring `Pathlib`'s behavior.
- gotcha Due to changes in Python 3.9's `urllib.parse.urljoin()`, the `furl.join()` method's behavior for specific relative URLs (e.g., starting with a scheme-like string such as 'foo:1') will differ on Python 3.9+ compared to older Python versions. On Python < 3.9, `furl('wss://slrp.com/').join('foo:1')` returned `'wss://slrp.com/foo:1'`, but on Python >= 3.9, it returns `'foo:1'`.
- gotcha Support for semicolon (`;`) as a query delimiter has been dropped in alignment with `urllib.parse`'s behavior. URLs using semicolons as delimiters in their query string will now be parsed differently.
Install
-
pip install furl
Imports
- furl
from furl import furl
Quickstart
from furl import furl
# Create a URL object
f = furl("https://www.example.com/path/to/resource?param1=value1¶m2=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}")