{"id":7835,"library":"unify","title":"unify - Python Quote Formatter","description":"Unify is a Python command-line tool designed to standardize string literal quoting within Python source files. It modifies strings to consistently use either single or double quotes where possible, configurable by the user. The current version is 0.5, released on August 7, 2019, and its release cadence is infrequent as it's a mature, focused utility.","status":"active","version":"0.5","language":"en","source_language":"en","source_url":"https://github.com/myint/unify","tags":["code formatting","linting","developer tools","string quotes"],"install":[{"cmd":"pip install unify","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"note":"The `unify` library is primarily a command-line interface (CLI) tool. There is no commonly exposed programmatic API for direct string manipulation in the way `black` or `isort` might offer. Interaction is typically via `subprocess`.","wrong":"from unify import unify_string","symbol":"unify (CLI)","correct":"import subprocess\nsubprocess.run(['unify', '--help'])"}],"quickstart":{"code":"import subprocess\nimport os\n\n# Create a dummy Python file for demonstration\nfile_content = \"\"\"x = \\\"abc\\\"\ny = 'hello'\nz = \\\"world\\\"\"\"\"\nwith open('example.py', 'w') as f:\n    f.write(file_content)\n\nprint('Original content of example.py:')\nwith open('example.py', 'r') as f:\n    print(f.read())\n\n# Run unify to enforce single quotes in-place\ntry:\n    # Using --quote ' to enforce single quotes\n    result = subprocess.run(['unify', '--in-place', '--quote', \"'\", 'example.py'], capture_output=True, text=True, check=True)\n    print('\\nUnify output:', result.stdout)\n    if result.stderr:\n        print('Unify errors:', result.stderr)\n\n    print('\\nContent of example.py after unify (single quotes):')\n    with open('example.py', 'r') as f:\n        print(f.read())\n\n    # Run unify again to enforce double quotes in-place\n    result = subprocess.run(['unify', '--in-place', '--quote', '\"', 'example.py'], capture_output=True, text=True, check=True)\n    print('\\nUnify output:', result.stdout)\n    if result.stderr:\n        print('Unify errors:', result.stderr)\n\n    print('\\nContent of example.py after unify (double quotes):')\n    with open('example.py', 'r') as f:\n        print(f.read())\n\nexcept subprocess.CalledProcessError as e:\n    print(f\"Error running unify: {e.stderr}\")\nexcept FileNotFoundError:\n    print(\"Error: 'unify' command not found. Make sure it's installed and in your PATH.\")\nfinally:\n    # Clean up the dummy file\n    if os.path.exists('example.py'):\n        os.remove('example.py')\n    print('\\nCleaned up example.py')","lang":"python","description":"This quickstart demonstrates how to use the `unify` CLI tool programmatically via Python's `subprocess` module to standardize string quotes in a file. It first creates a sample Python file, applies `unify` to enforce single quotes, then reapplies it to enforce double quotes, and finally cleans up the temporary file."},"warnings":[{"fix":"Use `subprocess.run()` to interact with the `unify` command-line tool from Python scripts.","message":"The `unify` library is primarily a command-line tool. While you can invoke it from Python using `subprocess`, it does not offer a direct, high-level Python API for manipulating strings or files in memory, unlike some other formatting tools.","severity":"gotcha","affected_versions":"0.1 - 0.5"},{"fix":"Always commit your code to version control (e.g., Git) before running `unify --in-place`, or use a separate script to create backups of files before processing them. Consider using `unify` without `--in-place` and reviewing the output before applying.","message":"When using the `--in-place` flag, `unify` modifies files directly without creating backups. Accidental or unintended changes can lead to data loss if not managed carefully.","severity":"breaking","affected_versions":"0.1 - 0.5"},{"fix":"Verify the PyPI page (pypi.org/project/unify) and GitHub repository (github.com/myint/unify) to confirm you are working with the correct project.","message":"Due to its generic name, `unify` can be confused with other Python packages such as `unifyai`, `unifi`, `unificontrol`, `python-unifi-client`, or `unifi-python-api`. Ensure you are installing and using `myint/unify` if your intention is string quote unification.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure `unify` is installed via `pip install unify` and that your Python environment's script directory is included in your system's PATH. If using a virtual environment, activate it before running `unify`.","cause":"The `unify` executable is not in your system's PATH, or the package was not installed correctly.","error":"unify: command not found"},{"fix":"Review the Python file being processed for unclosed or improperly escaped string literals. `unify` attempts to fix quote consistency but relies on valid Python syntax otherwise. Use a linter (e.g., Flake8, Pylint) to catch basic syntax errors before running `unify`.","cause":"This error occurs in your Python code, not necessarily from `unify` itself, but can happen if `unify` processes a file that already has unclosed or incorrectly escaped string literals, or if you manually try to construct a string that `unify` would otherwise fix.","error":"SyntaxError: EOL while scanning string literal"},{"fix":"If you intend to use the `unify` CLI tool, ensure it's installed via `pip install unify` and then invoke it using `subprocess.run(['unify', ...])`. If you genuinely need a Python library for programmatic string quote unification, you might need to look for alternatives or wrap the `unify` CLI tool yourself.","cause":"This error occurs if you try to `import unify` in Python without the `unify` package being installed in your environment, or if you're trying to import it as a library when its primary interface is the command line.","error":"ModuleNotFoundError: No module named 'unify'"}]}