oslex
OS-independent wrapper for shlex and mslex
What it is and what it does
oslex is a thin abstraction layer that provides a single, consistent interface for shell argument handling across Windows and POSIX systems. It forwards calls to either the standard library's shlex (on POSIX) or the mslex library (on Windows), so developers can write platform-agnostic code without conditional logic. The three core functions—join(), quote(), and split()—mirror their underlying implementations but automatically select the right one based on the current OS.
The package is useful when building command-line tools, subprocess wrappers, or any code that constructs or parses shell commands and needs to work correctly on both Windows and Unix-like systems. It accepts Path objects as arguments and converts them transparently, and exposes platform-specific keyword arguments (prefixed ms_ or sh_) for fine-tuning behavior when needed. It also provides _sh and _ms variants to force a specific implementation regardless of platform.
Use it for:
- Build cross-platform CLI tools that safely escape and join command arguments without platform-specific branching
- Parse shell command strings consistently on Windows and POSIX in subprocess or shell integration code
- Quote file paths and arguments safely when constructing system commands in deployment or automation scripts
- Handle mixed str and Path arguments in a single join or quote call without manual conversion
- Test shell-quoting logic against both Windows and POSIX rules in the same codebase
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides a unified API for shell argument quoting and parsing that works identically on Windows and POSIX systems by wrapping shlex and mslex.
Yes. It solves a real cross-platform pain point with minimal overhead (one dependency, low friction), active maintenance, no known vulnerabilities, and a permissive license. Install it if you build command-line tools or subprocess wrappers that must work on both Windows and POSIX systems.
Install
oslex on PyPI
pip
pip install oslexuv
uv add oslexpoetry
poetry add oslexInstalling oslex
Before you install
Low install friction with a single runtime dependency (mslex). Actively maintained with recent commits and releases spanning multiple Python versions (3.8–3.14).
License in practice
Permissive MIT license; the package itself is MIT-licensed, though it depends on mslex which is Apache 2.0-licensed, so combined use carries both permissive terms.
Quickstart
import oslex
# Quote arguments for the current platform
quoted = oslex.quote('my argument')
# Join a command list
cmd = oslex.join(['echo', 'hello world'])
# Split a command string
args = oslex.split('echo "hello world"')
Verify before relying
- Whether Path object support extends to all three main functions or only specific ones
- Performance characteristics when handling large argument lists or deeply nested quoting
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — mslex |
| Maintenance | actively maintained — 96 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 780,671/month — #5,082 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: oslex-2.0.0-py3-none-any.whl
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
bashlexbashlex parses bash shell syntax into an…
copyleft · top 5,000 on PyPI
mslexProvides Windows-compatible command-line…
permissive · top 5,000 on PyPI
shellescapeProvides a `quote()` function that…
permissive · top 5,000 on PyPI
sspilibProvides Python bindings to the Windows SSPI…
permissive · top 5,000 on PyPI
shellcheck-pyProvides a pip-installable shellcheck binary…
permissive · top 5,000 on PyPI
manygoConverts Golang platform identifiers (GOOS and…
permissive · top 15,000 on PyPI
flake8-quotesA flake8 plugin that enforces consistent quote…
permissive · top 5,000 on PyPI
quotequailIdentifies and separates quoted text from…
permissive · top 15,000 on PyPI
mozprocessProvides utilities for spawning, managing, and…
copyleft · top 15,000 on PyPI
strict-kwargsA standalone CLI linter that enforces keyword…
permissive · top 15,000 on PyPI