{"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":"en","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,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}