{"library":"rootpath","title":"rootpath","description":"The `rootpath` library for Python offers automatic detection of a project's or package's root directory. It identifies the root by searching for common files and folders like `.git` or `requirements.txt` in parent directories. This is particularly useful for resolving Python's module import challenges by optionally adding the detected root path to `sys.path`. The current version is 0.1.1, and the library appears to be in a maintenance mode with its last PyPI update in 2019.","language":"python","status":"maintenance","last_verified":"Thu Apr 16","install":{"commands":["pip install rootpath"],"cli":null},"imports":["import rootpath\nroot_dir = rootpath.detect()","import rootpath\nrootpath.append_to_sys_path()"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nimport rootpath\n\n# Example project structure for demonstration:\n# /tmp/my_project/\n# ├── .git (or requirements.txt, setup.py, etc.)\n# └── src/\n#     └── my_module.py\n\n# Simulate running from a submodule (e.g., /tmp/my_project/src/my_module.py)\n# In a real scenario, you'd run this from within your project directory.\n\n# Detect the project root from the current file's location\n# It will traverse up until it finds a common project marker.\nproject_root = rootpath.detect()\nprint(f\"Detected project root: {project_root}\")\n\n# Optionally, add the project root to sys.path for simplified imports\nrootpath.append_to_sys_path(project_root)\nprint(f\"sys.path now includes: {project_root}\")\n\n# You can also override the detection pattern\n# For example, if your root is marked by a specific file 'my_custom_root.txt'\n# custom_root = rootpath.detect(pattern='my_custom_root.txt')\n# print(f\"Detected custom root: {custom_root}\")\n","lang":"python","description":"This quickstart demonstrates how to use `rootpath.detect()` to find the project's root directory and `rootpath.append_to_sys_path()` to add it to `sys.path`, enabling simpler absolute imports within your project.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}