Package √Root
import package_root # into your PYTHONPATH
Stop appending your package root path to your Python path by hand like this:
from os.path import abspath, dirname, join
sys.path.insert(1, abspath(join(dirname(__file__), '..')))
It's annoying and error prone. Let us do it for you. <3
import package_root
How does this witchcraft work you ask?
We 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].
Still confused? Let's say you have the following setup:
your_awesome_pacakge/
foo/
__init__.py
your_dope_module.py
bar/
__init__.py
baz.ipynb
baz.py
.no_init_at_this_level
If 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.
# baz.ipynb or baz.py
import package_root
import foo.your_dope_module # works!
Don't believe us? We have tests to prove it.
Important Notes
- You shouldn't have an
__init__.pyin your package root. - This is intended for Jupyter notebooks where relative imports don't work.
Installation
pip install package_root
Usage
import package_root # And nothing else
Contributing
Feel free to report bugs, but we won't accept feature requests since this package is intended to do one thing and do it well.
Metadata
Release files for package-root 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| package_root-1.0.0.tar.gz | 3.3 kB | Without provenance | Details for package_root-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| package_root-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for package_root-1.0.0-py3-none-any.whl |
Total release size: 6.5 kB
Release files / package_root-1.0.0.tar.gz
| Download URL | package_root-1.0.0.tar.gz |
|---|---|
| Size | 3.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
039ae957e8bd7d11b47f97d3ce393fa14ec7ffb016ef4687aa8a51415d2b8562
|
|
BLAKE2b-256 checksum How to use checksums |
69e6c9c3e91a300c6e7b4f649da6edbbdac6715d75c625fa43fddf23218025f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.14 CPython/3.10.3 Darwin/21.6.0
|
Release files / package_root-1.0.0-py3-none-any.whl
| Download URL | package_root-1.0.0-py3-none-any.whl |
|---|---|
| Size | 3.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
104ba2b8844aa843b2ed7a7f7eedaa22eaf8430e56f224c27b2f2fa0699b1457
|
|
BLAKE2b-256 checksum How to use checksums |
dd39f9a46a28d52a4ae25c602bb5b22b87558af7818370aaa50612f6195071ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.14 CPython/3.10.3 Darwin/21.6.0
|
Security for package-root 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.