Prototype for stdlib webbrowser.open functionality
Project description
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 | requires ctypes and access to libobjc. This is the mac equivalent to the ios implementation in Python 3.13 |
| 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 necessary a webbrowser, which webbrowser.open is meant to launch.
The result is often webbrowser.open 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.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file webbrowser_open-0.1.0.tar.gz.
File metadata
- Download URL: webbrowser_open-0.1.0.tar.gz
- Upload date:
- Size: 13.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bdbf5fe33cd736e74b662effdaaab2c213716c43bba09c3cb95096b997cb61e6
|
|
| MD5 |
d72ddeda3e1f69e362859d6b5d4e57f8
|
|
| BLAKE2b-256 |
c40610e7bcc12fea7a4373af1117733ba9cb816db6e6194a47a89e732f7ca283
|
Provenance
The following attestation bundles were made for webbrowser_open-0.1.0.tar.gz:
Publisher:
release.yaml on minrk/webbrowser_open
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
webbrowser_open-0.1.0.tar.gz -
Subject digest:
bdbf5fe33cd736e74b662effdaaab2c213716c43bba09c3cb95096b997cb61e6 - Sigstore transparency entry: 173293996
- Sigstore integration time:
-
Permalink:
minrk/webbrowser_open@b0db600d08bc4922dd21fcbb6f0a5480e4c3f240 -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/minrk
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@b0db600d08bc4922dd21fcbb6f0a5480e4c3f240 -
Trigger Event:
push
-
Statement type:
File details
Details for the file webbrowser_open-0.1.0-py3-none-any.whl.
File metadata
- Download URL: webbrowser_open-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7f0dc15a4774b5d83468a805f101ee741620c218271e2754ea1255b1e4ef5bb
|
|
| MD5 |
cff9fa02c9f0010db38c8f295cda854b
|
|
| BLAKE2b-256 |
42ab79d1dc450aeaa744ae9b1315462ff49fc4c3740a9495a49ebd076eab4ce3
|
Provenance
The following attestation bundles were made for webbrowser_open-0.1.0-py3-none-any.whl:
Publisher:
release.yaml on minrk/webbrowser_open
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
webbrowser_open-0.1.0-py3-none-any.whl -
Subject digest:
e7f0dc15a4774b5d83468a805f101ee741620c218271e2754ea1255b1e4ef5bb - Sigstore transparency entry: 173293998
- Sigstore integration time:
-
Permalink:
minrk/webbrowser_open@b0db600d08bc4922dd21fcbb6f0a5480e4c3f240 -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/minrk
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@b0db600d08bc4922dd21fcbb6f0a5480e4c3f240 -
Trigger Event:
push
-
Statement type: