Install & Compatibility
Where this runs
tested against v1.0.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.566s · 18.8MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.5s · import 0.456s · 19MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
edit
✓ from editor import edit
✗ from editor import edit
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.
import editor
import os
def main():
# Example 1: Open an editor to capture a commit message
initial_text = b"# Enter your commit message above this line\n\n"
try:
commit_msg = editor.editor(contents=initial_text)
if commit_msg.strip():
print(f"Captured commit message:\n{commit_msg.decode('utf-8')}")
else:
print("No commit message entered.")
except Exception as e:
print(f"An error occurred: {e}")
# Example 2: Open an existing file for editing
# For demonstration, create a dummy file
dummy_filename = 'example.txt'
with open(dummy_filename, 'w') as f:
f.write('This is some initial text.\n')
print(f"\nOpening {dummy_filename} for editing...")
try:
# Note: editor.editor(filename='...') will save changes in place
# No return value needed if editing in place
editor.editor(filename=dummy_filename)
print(f"Finished editing {dummy_filename}.")
with open(dummy_filename, 'r') as f:
print(f"Final content of {dummy_filename}:\n{f.read()}")
except Exception as e:
print(f"An error occurred while editing file: {e}")
finally:
if os.path.exists(dummy_filename):
os.remove(dummy_filename)
if __name__ == '__main__':
main()
Debug
Known issues
gotchaThe 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.fixEnsure 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.
affects: All versions
gotchaWhen 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`.fixEncode your string content to bytes before passing it to `editor.editor()` (e.g., `"Your text".encode('utf-8')`). affects: Python 3.x
deprecatedThe 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.fixFor 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.
affects: 1.0.4 and potentially future Python versions
Upgrade
Version history
1.0.4latest on PyPI · released Feb 1, 2019
Audit
Dependencies
No dependency data recorded yet.