Skip to main content

Proper implementation of os.startfile to launch a target file/URL

Project description

shopen

shopen is a proper implementation of os.startfile to launch a target file/URL. Use it to launch the preferred system viewer for the user to view or edit a target file or URL.

"shopen" is short for shutil.open, the proposed builtin it's intended to be a reference implementation for.

PyPI - Version PyPI - Python Version


Usage

Simply install as a dependency of your project and then use it to launch an opener for a file or URL:

import pathlib, shopen
shopen.open("https://zombo.com/")  # Opens web browser
shopen.open(pathlib.Path("~/somefile.txt").expanduser())  # Opens file viewer
shopen.open(pathlib.Path("./somefile.toml"), "edit")  # Opens editor

Why?

Python's standard library provides nice cross-platform utilites for lots of different purposes, but so far no simple file/URL opener that would work on all platforms.

On Windows there's os.startfile, but strangely that doesn't support any other platform.

The proposal python/cpython#47427 to implement it as shutil.open was rejected for now. Python users keep asking for a decent way to do it, but the only answer had been brittle copypasta… until now!

Ideally this can be added into stdlib after proving its usefulness and then only be needed as a polyfill for older versions of python.

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

shopen-0.2.1.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

shopen-0.2.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file shopen-0.2.1.tar.gz.

File metadata

  • Download URL: shopen-0.2.1.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for shopen-0.2.1.tar.gz
Algorithm Hash digest
SHA256 41dd9c625d1c759f8409fc0d7f7405e4f8194d16ef860beeac7995b0abdde893
MD5 c6b26d27da234b9ff37b49bf19afdb23
BLAKE2b-256 ba4653b324f0d1e468b8b204afff388d04dd9af649a67ac3de1c6986598cb3e7

See more details on using hashes here.

File details

Details for the file shopen-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: shopen-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for shopen-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a3b69e6ba8192c2e933370a07d7a554798cc38a1300c4fe1c5624241fffc4427
MD5 7dc341faa63db488b8a1ff76be2f89b5
BLAKE2b-256 be0dbc6a9580d1410fc20a489166941ede7fcbc217e35b4a89363e9ec0e8d507

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page