{"id":5834,"library":"absolufy-imports","title":"absolufy-imports","description":"A Python tool and pre-commit hook designed to automatically convert relative imports to absolute imports within a codebase. While functional, its author has indicated it is superseded by the more comprehensive `reorder-python-imports` library. Its current version is `0.3.1`, last released in January 2022.","status":"deprecated","version":"0.3.1","language":"en","source_language":"en","source_url":"https://github.com/MarcoGorelli/absolufy-imports","tags":["imports","code quality","refactoring","pre-commit","linter"],"install":[{"cmd":"pip install absolufy-imports","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[],"quickstart":{"code":"# Example file: mypackage/myfile.py\n# from . import __version__\n# from .submodule import some_function\n\n# To convert relative imports in a file:\n# Create a dummy file for demonstration\nwith open('mypackage/myfile.py', 'w') as f:\n    f.write('from . import __version__\\n')\n    f.write('from .submodule import some_function\\n')\n\nimport os\nimport subprocess\n\n# Run absolufy-imports on the file\nprint('Before conversion:')\nwith open('mypackage/myfile.py', 'r') as f:\n    print(f.read())\n\n# Assuming 'mypackage' is at the root for absolute imports\n# The tool modifies the file in place\nsubprocess.run(['absolufy-imports', 'mypackage/myfile.py'], check=True)\n\nprint('\\nAfter conversion:')\nwith open('mypackage/myfile.py', 'r') as f:\n    print(f.read())\n\n# Clean up dummy file and directory\nos.remove('mypackage/myfile.py')\nos.rmdir('mypackage')","lang":"python","description":"To use `absolufy-imports` via the command line, simply point it to the file(s) you wish to modify. It will perform the conversion in place."},"warnings":[{"fix":"Consider migrating to `reorder-python-imports` for broader import management capabilities.","message":"The author of `absolufy-imports` states that it is superseded by `reorder-python-imports` (also by the same author) and recommends using the latter instead. `absolufy-imports` is functional but is not actively maintained for new features.","severity":"deprecated","affected_versions":"0.3.1 and earlier"},{"fix":"For a project with a `src` directory, use `absolufy-imports --application-directories .:src` or configure your pre-commit hook accordingly.","message":"When using `absolufy-imports` (especially with a pre-commit hook), ensure you configure `--application-directories` correctly if your project uses non-standard layouts (e.g., a `src` directory). This helps the tool correctly identify the root of your package for absolute import resolution.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Commit your changes before running `absolufy-imports` or verify changes using a diff tool afterward. Using it as a pre-commit hook helps manage this within your workflow.","message":"This tool modifies files in-place. Always ensure you have appropriate version control or backups before running it across your codebase to prevent unintended changes.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}