{"id":18605312,"url":"https://github.com/fny/python-package_root","last_synced_at":"2025-05-17T09:41:25.374Z","repository":{"id":59729386,"uuid":"538804801","full_name":"fny/python-package_root","owner":"fny","description":"import package_root # into your PYTHONPATH","archived":false,"fork":false,"pushed_at":"2022-09-20T04:13:17.000Z","size":34,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-23T00:05:53.977Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fny.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-09-20T04:12:18.000Z","updated_at":"2024-12-03T11:29:26.000Z","dependencies_parsed_at":"2022-09-20T23:41:15.815Z","dependency_job_id":null,"html_url":"https://github.com/fny/python-package_root","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fny%2Fpython-package_root","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fny%2Fpython-package_root/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fny%2Fpython-package_root/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fny%2Fpython-package_root/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fny","download_url":"https://codeload.github.com/fny/python-package_root/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254594969,"owners_count":22097464,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T02:20:50.305Z","updated_at":"2025-05-17T09:41:25.348Z","avatar_url":"https://github.com/fny.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Package √Root\n\n[![PyPI version](https://badge.fury.io/py/package_root.svg)](https://badge.fury.io/py/package_root)\n[![Test](https://github.com/fny/python-package_root/actions/workflows/test.yml/badge.svg)](https://github.com/fny/python-package_root/actions/workflows/test.yml)\n\n***import package_root # into your PYTHONPATH***\n\nStop appending your package root path to your Python path by hand like this:\n\n```python\nfrom os.path import abspath, dirname, join\nsys.path.insert(1, abspath(join(dirname(__file__), '..')))\n```\n\nIt's annoying and error prone. Let us do it for you. \u003c3\n\n```python\nimport package_root\n```\n\nHow does this witchcraft work you ask?\n\nWe detect the file that called `import package_root`. We search until we find a parent directory without an `__init__.py` file. That's your `package_root`. We make it `sys.path[1]` because friends don't let friends mess with [`sys.path[0]`](https://docs.python.org/3/library/sys.html#sys.path).\n\nStill confused? Let's say you have the following setup:\n\n```\nyour_awesome_pacakge/\n    foo/\n        __init__.py\n        your_dope_module.py\n        bar/\n            __init__.py\n            baz.ipynb\n            baz.py\n    .no_init_at_this_level\n```\n\nIf you're in `baz.ipynb` or `baz.py`, we'll append `your_awesome_package` to your path so you can import whatever you want from `your_awesome_package`.\n\n```python\n# baz.ipynb or baz.py\nimport package_root\nimport foo.your_dope_module # works!\n```\nDon't believe us? We have tests to prove it.\n\n## Important Notes\n\n - You shouldn't have an `__init__.py` in your package root.\n - This is intended for Jupyter notebooks where [relative imports don't work](https://stackoverflow.com/questions/34478398/import-local-function-from-a-module-housed-in-another-directory-with-relative-im).\n\n## Installation\n\n    pip install package_root\n\n## Usage\n\n```python\nimport package_root # And nothing else\n```\n\n## Contributing\n\nFeel free to report bugs, but we won't accept feature requests since this package is intended to [do one thing and do it well](https://en.wikipedia.org/wiki/Unix_philosophy).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffny%2Fpython-package_root","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffny%2Fpython-package_root","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffny%2Fpython-package_root/lists"}