webutil
Common utilities and handler code for Python web apps.
Install with
pip install webutilSupports Python 3.9+
webutil is dedicated to the public domain. You may also use it under the CC0 public domain dedication.
Contents
flask_util: Flask decorators and handlers for caching, exception handling, regular expression URL routing, domain-wide redirects, rate limiting, headers, and serving XRD and JRD templates.
logs: Flask request handler that collects full trace logs from Google Cloud Logging, formats them nicely, and serves them
models: minor utility Model classes for the Google Cloud Datastore ndb library
testutil: misc utilities and helpers for unittest, requests, and urllib
util: wide variety of utilities for data structures, web code, etc.
webmention: Webmention endpoint discovery and sending
Changelog
3.0 - 2026-10-14
Breaking changes:
util:Remove
if_changed.pretty_link: only linkhttpandhttpsURLs. For other URLs, return just the link text.
Non-breaking changes:
flask_util:Add
bool_paramfor getting boolean query params/form arguments.Add
csp_reporthandler for loggingContent-Security-Policyviolation reports.MODERN_HEADERS: tightenContent-Security-Policysignificantly.
models:Fix missing import in
Cache.get/Cache.put.
testutil:Add
assert_html_equals, which compares HTML strings and ignores insignificant whitespace and attribute order.requests_response: back the returned response with aurllib3.HTTPResponseinstead of a bareBytesIO, so thatresp.raw.stream()works for code that streams responses.
util:requests_*: addcachekwarg, an opt-in Flask-request-local cache of GET/HEAD responses and exceptions, keyed on method, URL, andAcceptheader.encode: fixencodingkwarg, it was ignored for nested values and always used UTF-8.is_connection_failure: makeprawcoreimport optional.linkify,tokenize_links: fix duplicated trailing punctuation after a link, eghttp://foo.com/a)..becamehttp://foo.com/a)......clean_url: fix query params with escaped delimiters, eg?a=b%26clost the%26c. The query string was unescaped before it was parsed.maybe_iso8601_to_rfc3339: return non-string inputs unchanged instead of raisingAttributeError.pretty_link: HTML-escape the URL inhrefand theattrsvalues.to_utc_timestamp: fix timezone aware datetimes, they were read as wall clock time and their UTC offset was ignored.trim_nulls: addkeep_empty_values_inkwarg.
2.0 - 2026-06-29
appengine_info:Add Cloud Run support.
flask_util:Add
block, abefore_requesthandler that blocks requests by client IP CIDR and/orUser-Agent.
models:Add new
WriteOnce,WriteOnceBlobPropertyndb property classes. (Moved here from arroba.)Add support for
$ENCRYPTED_PROPERTY_KEYenvironment variable.
testutil:Add new
@head_returns_200decorator.Drop
moxfromTestCase.Add new
unittest.mockandrequestshelpers toTestCase.
util:requests_*: add newlog_databoolean kwarg.
1.0 - 2026-05-27
Initial PyPI release. Moved out of oauth-dropins, where it’s been
maintained for the last 10+ years, into its own dedicated package,
pywebutil.
Release instructions
Here’s how to package, test, and ship a new release.
Pull from remote to make sure we’re at head.
sh git checkout main git pullRun the unit tests.
sh source .venv/bin/activate.csh gcloud emulators firestore start --host-port=:8089 --database-mode=datastore-mode < /dev/null >& /dev/null & python -m unittest discover python -m unittest webutil/tests/hypothesis/*.pyBump the version number in
pyproject.tomlanddocs/conf.py.git grepthe old version number to make sure it only appears in the changelog. Change the current changelog entry inREADME.mdfor this new version from unreleased to the current date.Build the docs. If you added any new modules, add them to the appropriate file(s) in
docs/source/. Then run./docs/build.sh.setenv ver X.Y git commit -am "release v$ver"
Upload to test.pypi.org for testing.
sh uv build twine upload -r pypitest dist/pywebutil-$ver.tar.gz dist/pywebutil-$ver-py3-none-any.whlInstall from test.pypi.org.
sh cd /tmp python3 -m venv .venv source .venv/bin/activate.csh pip3 install -i https://test.pypi.org/simple --extra-index-url https://pypi.org/simple pywebutilSmoke test that the code trivially loads and runs.
sh python # run test code belowTest code to paste into the interpreter:py from webutil import util util.__file__ util.UrlCanonicalizer()('http://asdf.com') # should print 'https://asdf.com/' exit()Tag the release in git. In the tag message editor, delete the generated comments at bottom, leave the first line blank (to omit the release “title” in github), put
### Notable changeson the second line, then copy and paste this version’s changelog contents below it.sh git tag -a v$ver --cleanup=verbatim git push git push --tagsClick here to draft a new release on GitHub. Enter
vX.Yin the Tag version box. Leave Release title empty. Copy### Notable changesand the changelog contents into the description text box.Upload to pypi.org!
sh twine upload dist/pywebutil-$ver-* dist/pywebutil-$ver.*