Skip to main content

MutableURL class for editing URLs

Project description

mutable_url.py

This repository holds the source for the mutable_url Python package.

This provides one utility class, MutableURL.

It also has one hook-point, configure_idna, to allow callers to opt into using correct modern DNS internationalised hostnames; the default is to use only the IDNA support in Python stdlib, which is out of date but usually good enough.

from mutable_url import MutableURL

u = MutableURL('http://www.example.org/hum')
u.scheme = https

print(u)
call_func_wanting_url(u.url)

u2 = MutableURL.from_parts(scheme='https', host='www.example.com',
                           query_params={'foo': 'bar', 'baz': '3'})

The from_parts class-method constructor requires keyword invocation. You can start with an empty URL. There is no default scheme. At present, the query_params values must be strings.

A MutableURL can be reconstructed into a string form via str() or by using the .url property (which just does that for you). This is the most stable interface for passing into other URL handling classes: I haven't found any other intermediate representation for cross-API compatibility worth the added complexity.

The Authority section is supported, including further virtualized accessors to allow individual access to username and password fields. Either one can be empty, to support auth schemes which only use one or the other (such as issued tokens provided as a password for an empty user).

The hostname part has two forms, which differ only when IDNA internationalisation is in play:

  • host: the on-the-wire ASCII form (ACE), which is also what appears in the URL
  • hostname: the presentation-layer form, as UTF-8

There are multiple accessors for query parameters handling:

  • query_params: a simple dict view which assumes keys are not repeated
  • query_params_multi: a dict where the value is a list of strings, one for each instance
  • query_params_list: a list of (key,value) tuples.

Fragments are supported.

AI Disclosures

The original implementation of MutableURL was written by a human and committed to a private repository on 2018-04-27. That initial version depended upon urllib3 (by way of requests).

On 2026-02-18, Anthropic's Claude was used to rewrite the implementation; the code was subjected to thorough human code-review and there were many iterations as aspects were refined. The goal was to move to only depending upon the Python stdlib, to add more accessors (for compatibility with API expectations of both urllib and urllib3), and to add tests. Along the way, we also collected IDNA support, while keeping the default as stdlib-only.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mutable_url-0.1.2.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mutable_url-0.1.2-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file mutable_url-0.1.2.tar.gz.

File metadata

  • Download URL: mutable_url-0.1.2.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mutable_url-0.1.2.tar.gz
Algorithm Hash digest
SHA256 18dbf311c7e89f102046762073cd2e98c60672ba7c146200b11ae2f9f3fb0fb1
MD5 8b3d2e589c88868496dcd8552cf7d7f6
BLAKE2b-256 abc089752c5a45d354e97a8f1e87164d342e8e4d0baaa569870ed68e9835f81f

See more details on using hashes here.

File details

Details for the file mutable_url-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: mutable_url-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mutable_url-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 eebd750ff9dfa662a31d3da7b79fe1e398a13187dc75f5f5a8bd70867ab149d2
MD5 5142770bbfd4d9b7773b01bb549de2f8
BLAKE2b-256 16bb35e4a059db7abbf4960d85bf614059bb222355df7167e12db008f1ddf62a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page