{"id":4240,"library":"rope","title":"Rope","description":"Rope is an advanced, open-source Python refactoring library. It provides extensive APIs for performing various code transformations like renaming, extracting methods, and moving elements. Actively maintained, it sees regular updates with recent releases like 1.14.0, and supports modern Python versions.","status":"active","version":"1.14.0","language":"en","source_language":"en","source_url":"https://github.com/python-rope/rope","tags":["refactoring","code analysis","IDE tooling","AST"],"install":[{"cmd":"pip install rope","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"Used to manage the codebase and its files for refactoring operations.","symbol":"Project","correct":"from rope.base.project import Project"},{"note":"Represents a Python file within a Rope project. `Resource` is the base class for files and folders.","symbol":"File","correct":"from rope.base.resources import File"},{"note":"One of many refactoring classes provided by Rope.","symbol":"Rename","correct":"from rope.refactor.rename import Rename"}],"quickstart":{"code":"import os\nimport tempfile\nimport shutil\nfrom pathlib import Path\nfrom rope.base.project import Project\nfrom rope.base.resources import File\nfrom rope.refactor.rename import Rename\n\n# Create a temporary directory and a dummy Python file\ntemp_dir = Path(tempfile.mkdtemp())\nfile_path = temp_dir / \"my_module.py\"\nfile_path.write_text(\"\"\"\ndef greet():\n    old_name = \"World\"\n    print(f\"Hello, {old_name}!\")\n\"\"\")\n\nproject = Project(temp_dir)\nresource = project.get_resource(file_path.name)\n\n# Find the start offset of 'old_name'\n# In '    old_name = \"World\"', 'old_name' starts at index 5\noffset = file_path.read_text().find('old_name = \"World\"') + 4\n\n# Perform rename refactoring\nchanges = Rename(project, resource, offset).get_changes('new_name')\n\n# Apply the changes to the project files\nproject.do(changes)\n\n# Verify the change\nprint(file_path.read_text())\n\n# Clean up\nproject.close()\nshutil.rmtree(temp_dir)","lang":"python","description":"This example demonstrates how to initialize a Rope project, load a Python file, and perform a simple variable renaming refactoring. It creates a temporary file and directory, renames a variable 'old_name' to 'new_name', applies the changes, and then cleans up. The `Project` object manages the codebase, `Resource` objects represent files, and specific refactoring classes (like `Rename`) perform transformations."},"warnings":[{"fix":"Upgrade to Python 3.8+ or use older Rope versions for Python 2 projects.","message":"Rope versions 1.0.0 and above no longer support Python 2. Users requiring Python 2 compatibility must use 0.x.x releases or the `python2` branch.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Be aware of the `.ropeproject` folder for project setup and consider configuring `ropefolder=None` if not desired, or adding it to version control ignore files.","message":"By default, Rope creates a `.ropeproject` folder in the project root to store configuration and data (e.g., history, object information). This folder can be configured or disabled via the `ropefolder` parameter in the `Project` constructor.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If needed, explicitly configure `python_path` in `config.py` or through the `Project` constructor to include paths to relevant external modules.","message":"As of version 1.12.0, Rope no longer includes `site-packages` in its default search tree for modules. This might affect auto-import suggestions or object inference for packages not explicitly within the defined project source folders.","severity":"gotcha","affected_versions":">=1.12.0"},{"fix":"Ensure new names for refactored symbols are not Python keywords.","message":"Version 1.13.0 introduced validation to prevent renaming a symbol to a Python keyword. While a safety enhancement, this changes previous behavior that might have allowed such renames (which would lead to syntax errors).","severity":"gotcha","affected_versions":">=1.13.0"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}