{"id":6759,"library":"oslex","title":"OS-independent wrapper for shlex and mslex","description":"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.","status":"active","version":"0.1.3","language":"python","source_language":"en","source_url":"https://github.com/petamas/oslex","tags":["shell","quote","split","join","shlex","mslex","cross-platform","os-independent","command-line"],"install":[{"cmd":"pip install oslex","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Provides Windows-specific shell parsing and quoting functionality. Used conditionally on Windows platforms.","package":"mslex","optional":true}],"imports":[{"note":"The library provides functions directly under the `oslex` module, such as `oslex.quote`, `oslex.split`, and `oslex.join`.","symbol":"oslex","correct":"import oslex"}],"quickstart":{"code":"import oslex\nimport os\n\n# Example: Safely quote a string for the shell\ncommand_part = \"foo; rm -rf /\"\nquoted_command = oslex.quote(command_part)\nprint(f\"Original: '{command_part}'\\nQuoted: '{quoted_command}'\")\n\n# Example: Split a shell command into arguments\nshell_command = 'python -m pip install \"oslex>=0.1.3\" --upgrade'\nargs = oslex.split(shell_command)\nprint(f\"\\nShell command: '{shell_command}'\\nSplit args: {args}\")\n\n# Example: Join arguments into a shell command\nargs_to_join = [os.environ.get('PYTHON_EXECUTABLE', 'python'), '-c', 'print(\"Hello World\")']\njoined_command = oslex.join(args_to_join)\nprint(f\"\\nArguments: {args_to_join}\\nJoined command: '{joined_command}'\")","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade to `oslex` version 0.1.3 or later using `pip install oslex --upgrade`.","message":"Prior 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.","severity":"gotcha","affected_versions":"<0.1.3"},{"fix":"Review both MIT and Apache 2.0 licenses to ensure compatibility with your project's licensing requirements.","message":"While `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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Thoroughly test `oslex.quote()`, `oslex.split()`, and `oslex.join()` with representative commands on both Windows and POSIX environments to ensure desired behavior.","message":"The `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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'0.1.3':68 '2023':75 'achiev':44 'call':48 'command':89 'command-lin':88 'compat':41 'cross':83 'cross-platform':82 'current':65 'forward':47 'function':26,29 'independ':3,14,87 'join':79 'juli':74 'last':71 'librari':52,61 'line':90 'main':21 'mslex':8,19,60,81 'os':2,13,86 'os-independ':1,12,85 'oslex':9 'platform':42,84 'posix':40,56 'posix-compat':39 'provid':25 'purpos':22 'quot':77 'releas':72 'shell':76 'shlex':6,17,54,80 'shlex.join':34 'shlex.quote':31 'shlex.split':32 'similar':27 'split':78 'standard':51 'system':57 'version':66 'window':37,63 'wrapper':4,15","created_at":"2026-04-15T18:41:45.289809+00:00","updated_at":"2026-04-16T17:49:18.781569+00:00","problems":[{"fix":"Install the library using pip: `pip install oslex`","cause":"The 'oslex' library is not installed in the Python environment.","error":"ModuleNotFoundError: No module named 'oslex'"},{"fix":"Install 'mslex' specifically for Windows: `pip install mslex`","cause":"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.","error":"ModuleNotFoundError: No module named 'mslex'"},{"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.","cause":"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.","error":"mslex.MSLexError: Inconsistent quoting detected"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"2.0.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/petamas/oslex","docs":null,"changelog":null,"pypi":"https://pypi.org/project/oslex/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["http-networking"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}