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.0.tar.gz (10.7 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.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mutable_url-0.1.0.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for mutable_url-0.1.0.tar.gz
Algorithm Hash digest
SHA256 79a2fc75d3d66ca9f4de1e5d44c3d722f7a17eb2652bc63456cb93496dea0fca
MD5 ccca05c36a99b3b31bdb504b5a1ae67d
BLAKE2b-256 895542cbe4579f45c1813adccd58b2c14bcf41c1ae88ddd43bd79a75b2b22bb3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mutable_url-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for mutable_url-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 097f21d5e04b93c8b5e25e958672705ebac929419741b827994597d8e4a0357f
MD5 71d8f49444d980b5c668f98ea6156eef
BLAKE2b-256 4652deb385ffa00d1f4c8032392b896e222946a340cabc8b2ceed504765a67c3

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