Registry / http-networking / oslex
library2.0.0pypypi✓ verified 84d ago

oslex is an OS-independent wrapper for shlex and mslex. Its main purpose is to provide functions similar in functionality to shlex.quote(), shlex.split(), and shlex.join() on both Windows and POSIX-compatible platforms. It achieves this by forwarding calls to the standard library's `shlex` on POSIX systems or the `mslex` library on Windows. The current version is 0.1.3, with the last release in July 2023.

pip install oslex
INSTALL
IMPORT
SIG · OSLEX
O
oslex
http-networkingpythonv2.0.0
Install
1.6s avg
Import
24ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.027s · 17.9MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.6s · import 0.022s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

oslex
import oslex
The library provides functions directly under the `oslex` module, such as `oslex.quote`, `oslex.split`, and `oslex.join`.

This quickstart demonstrates the core `quote`, `split`, and `join` functionalities of `oslex`, which behave consistently across operating systems by using `shlex` on POSIX and `mslex` on Windows.

import oslex import os # Example: Safely quote a string for the shell command_part = "foo; rm -rf /" quoted_command = oslex.quote(command_part) print(f"Original: '{command_part}'\nQuoted: '{quoted_command}'") # Example: Split a shell command into arguments shell_command = 'python -m pip install "oslex>=0.1.3" --upgrade' args = oslex.split(shell_command) print(f"\nShell command: '{shell_command}'\nSplit args: {args}") # Example: Join arguments into a shell command args_to_join = [os.environ.get('PYTHON_EXECUTABLE', 'python'), '-c', 'print("Hello World")'] joined_command = oslex.join(args_to_join) print(f"\nArguments: {args_to_join}\nJoined command: '{joined_command}'")
Debug
Known issues
gotchaPrior to version 0.1.3, `oslex` had compatibility issues with Python versions 3.6 through 3.8. Users on these Python versions might encounter unexpected errors.
fix
Upgrade to `oslex` version 0.1.3 or later using `pip install oslex --upgrade`.
affects: <0.1.3
gotchaWhile `oslex` itself is distributed under the MIT license, it depends on the `mslex` library for its Windows functionality, which is licensed under Apache 2.0. Users should be aware of this dual licensing for their projects.
fix
Review both MIT and Apache 2.0 licenses to ensure compatibility with your project's licensing requirements.
affects: All versions
gotchaThe `oslex` library acts as a wrapper. While it provides a unified API, the underlying behavior (especially quoting rules) for Windows systems is governed by `mslex`, which may differ subtly from `shlex` on POSIX. Always test complex shell commands in your target environment.
fix
Thoroughly test `oslex.quote()`, `oslex.split()`, and `oslex.join()` with representative commands on both Windows and POSIX environments to ensure desired behavior.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'oslex'
The 'oslex' library is not installed in the Python environment.
fix
Install the library using pip: `pip install oslex`
ModuleNotFoundError: No module named 'mslex'
On Windows systems, 'oslex' relies on the 'mslex' library, which is not automatically installed as a direct dependency for 'oslex' version 0.1.3 and needs to be installed separately.
fix
Install 'mslex' specifically for Windows: `pip install mslex`
mslex.MSLexError: Inconsistent quoting detected
This error occurs on Windows when `oslex.split` (which uses `mslex` internally) encounters a command string that cannot be consistently parsed by both the modern C runtime and the older `msvcrt.dll` parsing rules, or when `mslex`'s `check=True` option is used with unquoted metacharacters.
fix
Ensure the input string to `oslex.split` is correctly quoted for Windows shell syntax. If parsing problematic input, consider passing `ucrt=True` or `ucrt=False` to `oslex.split` if you know the target runtime's parsing behavior, or add `check=False` to suppress the error if unquoted metacharacters are intentional.
Upgrade
Version history
2.0.0latest on PyPI · released May 10, 2026
Audit
Dependencies
mslexoptionalProvides Windows-specific shell parsing and quoting functionality. Used conditionally on Windows platforms.
Agent activity
4 hits · last 30 days
node
4
Resources
oslex — pip install oslex · libregistry