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.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

shopen-0.2.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: shopen-0.2.0.tar.gz
  • Upload date:
  • Size: 4.9 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.0.tar.gz
Algorithm Hash digest
SHA256 791f72d8ad323e4253cdcc56df6460c6cd66db26223ffcbc9bddc67a10031bc1
MD5 192280d345fb761b6659a046b32d072c
BLAKE2b-256 953e8c06bac435a0f7fd374709ebf3f00af4e628822fe48c9aedab7a0e4b71e4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: shopen-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.0 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7eaada052980d13ae2fabe58dc620b98f2bec59e8eedef777c06d4b97d63f7fc
MD5 dcaf8cc316c9fad6d446c8fd9bcb5758
BLAKE2b-256 14c244bd555242f446b2196a2061ac2ae4c49be6f56018727ba200b437921930

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