Skip to main content

Introduction

Documentation | Changelog | Repository

shell-lib is designed to simplify the writing of shell-like scripts:

  • Python syntax: Write scripts in readable Python, freeing from complex shell command syntax.
  • Reliable error handling: Use Python's exception to manage command failure. If a command fails, by default, it raises a subprocess.CalledProcessError exception. For commands that may fail, user can also only check the exit-code.
  • Cross-platform compatibility: Write a single script that works across Linux, macOS, and Windows platforms.
  • Rich ecosystem integration: Easily integrate with both the CLI tool and Python library ecosystems.
  • Lightweight and portable: Only use Python standard library.
  • Well tested: Consistent and reliable behavior on different platforms and Python versions.
  • Friendly: Readers can understand the code without consulting the documentation. If writers use modern IDEs, then almost no need to consult the documentation.

It provides some functions that make writing shell-like scripts easy:

  1. Executing external command: Conveniently invoke external commands.
  2. File and directory operations: Provide a consistent and intuitive file system operations API, that clearly distinguish between file and directory operations.
  3. User interactions: Do common interactions with one line of code.
  4. Obtaining system information: Get common system information for shell-like scripts.

This module was co-created with Google Gemini.

Usage

#!/usr/bin/python3
from shell_lib import sh

PROJECT_PATH = "my_project"
FILE = "hello.txt"

sh.create_dir(PROJECT_PATH)
# sh.cd() context manager restores the previous working directory when
# exiting the code block, even if an exception raised within the code block.
with sh.cd(PROJECT_PATH):
    sh(f"echo 'Hello, World!' > {FILE}")
    print(f"File size: {sh.get_file_size(FILE)} bytes")
sh.remove_dir(PROJECT_PATH)

There is a demo script at the documentation page.

Metadata

Release files for shell-lib 2.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for shell-lib 2.0.4
File Size Uploaded Provenance Actions
shell_lib-2.0.4.tar.gz 29.4 kB Without provenance Details for shell_lib-2.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for shell-lib 2.0.4
File Interpreter ABI Platform Actions
shell_lib-2.0.4-py3-none-any.whl Python 3 none any Details for shell_lib-2.0.4-py3-none-any.whl

Total release size: 43.6 kB

Release files / shell_lib-2.0.4.tar.gz

Download URL shell_lib-2.0.4.tar.gz
Size 29.4 kB
Tags Source
SHA-256 checksum
How to use checksums
037a51df0786711a2c6a32c58112cfdaa7519aa1e603580fa9aba85d1206c2f9
BLAKE2b-256 checksum
How to use checksums
324a26e98ae2ae7193f25f7eb23cd918e78c63617328104aea815c8ac7e04edf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.15

Release files / shell_lib-2.0.4-py3-none-any.whl

Download URL shell_lib-2.0.4-py3-none-any.whl
Size 14.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4df7799b1011bc8b268a6cda2538aac11a4c386953da726d1d0110ac942b8052
BLAKE2b-256 checksum
How to use checksums
ef87dd610653b8474e7c2ac0d53af6afcf9c9741f9c90f5f6b42d87b06bcb489
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.15

Security for shell-lib 2.0.4

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page