skillfed

oslex

OS-independent wrapper for shlex and mslex

oslex v2.0.0 780.7K downloads/30d#5,082 on PyPI10
Permissive license Active released

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 oslex

uv

uv add oslex

poetry

poetry add oslex

Installing 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

License :: OSI Approved :: MIT LicenseOperating System :: MacOSOperating System :: Microsoft :: WindowsOperating System :: POSIXProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9

Tags

cross-platform shell argument quotingwindows posix command line parsingshlex mslex wrapperos-independent shell escapingplatform-agnostic command splitting
cross-platformshell-integrationsubprocess

More Utilities packages