webbrowser_open
prototyping opening things with the default webbrowser
Use
The simplest way to use this package is to replace:
import webbrowser
...
webbrowser.open(url)
with
import webbrowser_open
...
webbrowser_open.open(url)
You can also launch a URL with
python3 -m webbrowser_open URL
to see the difference (if any) in your environment.
The only difference in behavior is that webbrowser_open looks up the default browser application before opening the URL.
This should only result in a change in behavior for opening file:// URLs
where the default application associated with the file type is used instead of the default browser.
The $BROWSER environment variable still takes priority, if defined,
in which case webbrowser_open.open just wraps a call to webbrowser.open with no changes.
This package uses the following APIs to explicitly launch the default browser:
| platform | API | notes |
|---|---|---|
| mac | URLForApplicationToOpenURL | implemented via applescript |
| Windows | HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\https\UserChoice | I don't yet know which cases this might not work for (UWP, minumum Windows versions, etc.), but it works in my own limited tests |
| linux | xdg-settings get default-webbrowser or xdg-mime query default x-scheme-handler/https plus gtk-launch or gio launch |
gtk-launch appears to locate .deskop files correctly, while gio launch only appears to accept absolute paths. I'm not sure how many different ways there are to lookup and/or launch default browsers on linux. |
Background
Most platforms have at least a semi-standard way to open URLs and discover the default browser.
webbrowser.open uses generic not-browser-specific APIs (e.g. open, xdg-open, os.startfile), which works fine with http[s] URLs.
However, all of these systems associate file:// URLs with the default application for the file type, not necessarily a webbrowser, which webbrowser.open is meant to launch.
The result is often webbrowser.open("file:///path/to/page.html") launching a file editor instead of a browser.
webbrowser.open does not work reliably with file:// URLs on any platform, though it may if the default application for HTML files is a browser,
which it often is, except for developers.
Linux is in the best situation by default, because it does call xdg-settings get default-web-browser to actually lookup a browser,
but it only uses this if a matching browser is already known ahead of time and found in register_X_browsers.
This is still known to fail at least sometimes.
This is a prototype package for testing implementations to be submitted to the standard library.
Release files for webbrowser-open 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| webbrowser_open-0.3.0.tar.gz | 14.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| webbrowser_open-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 24.0 kB
Release files / webbrowser_open-0.3.0.tar.gz
| Download URL | webbrowser_open-0.3.0.tar.gz |
|---|---|
| Size | 14.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d751dd76e888d105d786b86ac890b9c0dd7b273d6f39e67c57a1cc7ddefe03a2
|
|
BLAKE2b-256 checksum How to use checksums |
48402e6eb1c513b60fe489da49bbdfca3e0d8c4ae5657352c90dad1dde2cc3c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 27, 2025.
Transparency logRelease files / webbrowser_open-0.3.0-py3-none-any.whl
| Download URL | webbrowser_open-0.3.0-py3-none-any.whl |
|---|---|
| Size | 9.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bd44ce80df1db634df3156f6b56ec2b445812e7bcff82d9f22b2217acaede23f
|
|
BLAKE2b-256 checksum How to use checksums |
2d0e16fa8d77cfefd4f09c7c21e518e8f7cc5d0c1b80c57048a38deabc13b96b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 27, 2025.
Transparency log