{"id":2732,"library":"python-editor","title":"Python Editor","description":"python-editor is a Python library that provides a programmatic interface to the system's default text editor, usually determined by the `$EDITOR` environment variable. It allows applications to open an editor, optionally pre-fill it with content, and capture the user's input upon closing. The current version is 1.0.4, with the last release dating back to January 2019, indicating a slow or inactive release cadence.","status":"maintenance","version":"1.0.4","language":"en","source_language":"en","source_url":"https://github.com/fmoo/python-editor","tags":["utility","editor","cli","environment-variable"],"install":[{"cmd":"pip install python-editor","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"note":"The primary functionality is exposed via the top-level `editor` module.","symbol":"editor","correct":"import editor"}],"quickstart":{"code":"import editor\nimport os\n\ndef main():\n    # Example 1: Open an editor to capture a commit message\n    initial_text = b\"# Enter your commit message above this line\\n\\n\"\n    try:\n        commit_msg = editor.editor(contents=initial_text)\n        if commit_msg.strip():\n            print(f\"Captured commit message:\\n{commit_msg.decode('utf-8')}\")\n        else:\n            print(\"No commit message entered.\")\n\n    except Exception as e:\n        print(f\"An error occurred: {e}\")\n\n    # Example 2: Open an existing file for editing\n    # For demonstration, create a dummy file\n    dummy_filename = 'example.txt'\n    with open(dummy_filename, 'w') as f:\n        f.write('This is some initial text.\\n')\n    \n    print(f\"\\nOpening {dummy_filename} for editing...\")\n    try:\n        # Note: editor.editor(filename='...') will save changes in place\n        # No return value needed if editing in place\n        editor.editor(filename=dummy_filename)\n        print(f\"Finished editing {dummy_filename}.\")\n        with open(dummy_filename, 'r') as f:\n            print(f\"Final content of {dummy_filename}:\\n{f.read()}\")\n    except Exception as e:\n        print(f\"An error occurred while editing file: {e}\")\n    finally:\n        if os.path.exists(dummy_filename):\n            os.remove(dummy_filename)\n\nif __name__ == '__main__':\n    main()","lang":"python","description":"This quickstart demonstrates how to use `python-editor` to both capture user input via a temporary file and to edit an existing file. The `editor.editor()` function opens the configured editor and returns the edited content for temporary files, or saves changes directly to a specified file."},"warnings":[{"fix":"Ensure the `$EDITOR` environment variable is set to a valid editor on your system, or that a common editor like `vim` or `nano` is installed and accessible in the system's PATH.","message":"The library relies on the `$EDITOR` environment variable to determine which text editor to open. If `$EDITOR` is not set, it will attempt to use a predefined list of common editors (e.g., `vim`, `emacs`, `nano`). If none are found, the call to `editor.editor()` will fail.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Encode your string content to bytes before passing it to `editor.editor()` (e.g., `\"Your text\".encode('utf-8')`).","message":"When providing initial content to the editor using the `contents` argument in Python 3, the value must be a `bytes` object, not a `str`. Passing a string will result in a `TypeError`.","severity":"gotcha","affected_versions":"Python 3.x"},{"fix":"For basic functionality, it remains usable. For long-term projects or those requiring active support, consider if this maintenance status is acceptable. No direct fix is available, as it depends on upstream activity.","message":"The project `python-editor` has not seen updates since January 2019. While its core functionality is simple and may remain stable, this indicates a lack of active maintenance, which could mean no new features, bug fixes for modern edge cases, or compatibility updates for future Python versions.","severity":"deprecated","affected_versions":"1.0.4 and potentially future Python versions"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}