webbrowser-open


Namewebbrowser-open JSON
Version 0.3.0 PyPI version JSON
download
home_pageNone
SummaryPrototype for stdlib webbrowser.open functionality
upload_time2025-02-27 12:09:16
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseBSD-3-Clause
keywords webbrowser
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # webbrowser_open

prototyping opening things with the default webbrowser

## Use

The simplest way to use this package is to replace:

```python
import webbrowser

...
webbrowser.open(url)
```

with

```python
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](<https://developer.apple.com/documentation/appkit/nsworkspace/urlforapplication(toopen:)-7qkzf?language=objc>) | 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`](https://github.com/python/cpython/blob/5d66c55c8ad0a0aeff8d06021ddca1d02c5f4416/Lib/webbrowser.py#L524) 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`](https://github.com/python/cpython/blob/5d66c55c8ad0a0aeff8d06021ddca1d02c5f4416/Lib/webbrowser.py#L421).
This is still known to fail [at least sometimes](https://github.com/jupyter/notebook/issues/4304).

This is a prototype package for testing implementations to be submitted to the standard library.

ref: https://github.com/python/cpython/issues/128540

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "webbrowser-open",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "webbrowser",
    "author": null,
    "author_email": "Min RK <benjaminrk@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/48/40/2e6eb1c513b60fe489da49bbdfca3e0d8c4ae5657352c90dad1dde2cc3c4/webbrowser_open-0.3.0.tar.gz",
    "platform": null,
    "description": "# webbrowser_open\n\nprototyping opening things with the default webbrowser\n\n## Use\n\nThe simplest way to use this package is to replace:\n\n```python\nimport webbrowser\n\n...\nwebbrowser.open(url)\n```\n\nwith\n\n```python\nimport webbrowser_open\n\n...\nwebbrowser_open.open(url)\n```\n\nYou can also launch a URL with\n\n```\npython3 -m webbrowser_open URL\n```\n\nto see the difference (if any) in your environment.\n\nThe only difference in behavior is that `webbrowser_open` looks up the default browser application before opening the URL.\nThis should only result in a change in behavior for opening `file://` URLs\nwhere the default application associated with the file type is used instead of the default browser.\n\nThe $BROWSER environment variable still takes priority, if defined,\nin which case `webbrowser_open.open` just wraps a call to `webbrowser.open` with no changes.\n\nThis package uses the following APIs to explicitly launch the default browser:\n\n| platform | API                                                                                                                                         | notes                                                                                                                                                                                                               |\n| -------- | ------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| mac      | [URLForApplicationToOpenURL](<https://developer.apple.com/documentation/appkit/nsworkspace/urlforapplication(toopen:)-7qkzf?language=objc>) | implemented via applescript                                                                                                                                                                                         |\n| 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                                                                                    |\n| 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. |\n\n## Background\n\nMost platforms have at least a semi-standard way to open URLs and discover the default browser.\n\n`webbrowser.open` uses generic not-browser-specific APIs (e.g. `open`, `xdg-open`, `os.startfile`), which works fine with `http[s]` URLs.\nHowever, 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.\nThe result is often `webbrowser.open(\"file:///path/to/page.html\")` launching a file editor instead of a browser.\n\n`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,\nwhich it often is, except for developers.\n\nLinux is in the best situation by default, because it does call [`xdg-settings get default-web-browser`](https://github.com/python/cpython/blob/5d66c55c8ad0a0aeff8d06021ddca1d02c5f4416/Lib/webbrowser.py#L524) to actually lookup a browser,\nbut it only uses this if a matching browser is already known ahead of time and found in [`register_X_browsers`](https://github.com/python/cpython/blob/5d66c55c8ad0a0aeff8d06021ddca1d02c5f4416/Lib/webbrowser.py#L421).\nThis is still known to fail [at least sometimes](https://github.com/jupyter/notebook/issues/4304).\n\nThis is a prototype package for testing implementations to be submitted to the standard library.\n\nref: https://github.com/python/cpython/issues/128540\n",
    "bugtrack_url": null,
    "license": "BSD-3-Clause",
    "summary": "Prototype for stdlib webbrowser.open functionality",
    "version": "0.3.0",
    "project_urls": {
        "Homepage": "https://github.com/minrk/webbrowser_open",
        "Source": "https://github.com/minrk/webbrowser_open",
        "Tracker": "https://github.com/minrk/webbrowser_open/issues"
    },
    "split_keywords": [
        "webbrowser"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "2d0e16fa8d77cfefd4f09c7c21e518e8f7cc5d0c1b80c57048a38deabc13b96b",
                "md5": "d66ef7cf10ec2ce55d6ed436473e3bce",
                "sha256": "bd44ce80df1db634df3156f6b56ec2b445812e7bcff82d9f22b2217acaede23f"
            },
            "downloads": -1,
            "filename": "webbrowser_open-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d66ef7cf10ec2ce55d6ed436473e3bce",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 9315,
            "upload_time": "2025-02-27T12:09:14",
            "upload_time_iso_8601": "2025-02-27T12:09:14.089013Z",
            "url": "https://files.pythonhosted.org/packages/2d/0e/16fa8d77cfefd4f09c7c21e518e8f7cc5d0c1b80c57048a38deabc13b96b/webbrowser_open-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "48402e6eb1c513b60fe489da49bbdfca3e0d8c4ae5657352c90dad1dde2cc3c4",
                "md5": "6160040074b073e46fee78c78dc43b40",
                "sha256": "d751dd76e888d105d786b86ac890b9c0dd7b273d6f39e67c57a1cc7ddefe03a2"
            },
            "downloads": -1,
            "filename": "webbrowser_open-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "6160040074b073e46fee78c78dc43b40",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 14657,
            "upload_time": "2025-02-27T12:09:16",
            "upload_time_iso_8601": "2025-02-27T12:09:16.143963Z",
            "url": "https://files.pythonhosted.org/packages/48/40/2e6eb1c513b60fe489da49bbdfca3e0d8c4ae5657352c90dad1dde2cc3c4/webbrowser_open-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-27 12:09:16",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "minrk",
    "github_project": "webbrowser_open",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "webbrowser-open"
}
        
Elapsed time: 0.71115s