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

Uploaded Python 3

File details

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

File metadata

  • Download URL: mutable_url-0.1.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-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d5f706d89c8b6ff9b4f28823cd0c137ef1170ff18b5ee568a3225e303e3bfc6e
MD5 019d659964f969b0b2d080ff91615ce3
BLAKE2b-256 f42b61c48701647a03a1b93aee5969a903716dd457d2f5f927a290d05ece6ac6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mutable_url-0.1.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-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4427644abe43c3ebe0640a1e4bc9c64f06e323a07a3b61ffb482eb077310d083
MD5 a11b617e4dd734860d5d1ef79bcf5c4e
BLAKE2b-256 ab42c25b54680685e002bc9b8533b34a2ef1bb73255f78650d00b93027864b8d

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