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.CalledProcessErrorexception. 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:
- Executing external command: Conveniently invoke external commands.
- File and directory operations: Provide a consistent and intuitive file system operations API, that clearly distinguish between file and directory operations.
- User interactions: Do common interactions with one line of code.
- 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.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| shell_lib-2.0.5.tar.gz | 29.5 kB | Without provenance | Details for shell_lib-2.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| shell_lib-2.0.5-py3-none-any.whl | Python 3 | none | any | Details for shell_lib-2.0.5-py3-none-any.whl |
Total release size: 43.8 kB
Release files / shell_lib-2.0.5.tar.gz
| Download URL | shell_lib-2.0.5.tar.gz |
|---|---|
| Size | 29.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
23b5911388e3f4eeb8ab9cb2e1a05da75849dab8470cbb92fbe9c04bababc8ff
|
|
BLAKE2b-256 checksum How to use checksums |
2d2fdd90a2c96061bf39c137e46c961a274046057f8ef37c632b11da5532ac5d
|
| 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.5-py3-none-any.whl
| Download URL | shell_lib-2.0.5-py3-none-any.whl |
|---|---|
| Size | 14.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dafc767ff20baf1e3edff33656f185dc6fc01539d7b02a9e3d4f5336f48e36e7
|
|
BLAKE2b-256 checksum How to use checksums |
8b6eeae4a9fa4a9624ab04b4a332223385cf28d45ed2458518498e5ce159f98f
|
| 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.5
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.