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-1.0.1.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-1.0.1-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mutable_url-1.0.1.tar.gz
  • Upload date:
  • Size: 10.7 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-1.0.1.tar.gz
Algorithm Hash digest
SHA256 3e1b757b5558000fc6022c37bdc72f182bcc4b2513759b410d3eae9247bd3a34
MD5 aff63bc58c53d6e55f76beda5d17ea4a
BLAKE2b-256 652088f2f4f90898420403f72ed36779c0a995860d991ccc5bfa38f6b71fb25e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mutable_url-1.0.1-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-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2a42c58792e62fa45e2e17a2b237cd838eff7d49db1fc4cb0770cdf710163eeb
MD5 2508db7d86565d78a860ff33bc8a7450
BLAKE2b-256 34c91eadb15e3fb6b93048122858e038fd677ac231e2821074fb390d29a3f9b2

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