Skip to main content

Parent Import

Unfortunately, importing from parent directory is problematic in Python.

This package makes it easier to import from parent directory.

Install

pip install parent_import

Example Usage:

file structure:

project_name/
    dir1/
        importer.py
    dir2/
        dir3/
            module_to_import.py

module_to_import.py:

print("Module Imported")
def method1():
    print("Hello World")

importer.py:

from parent_import import parentdir

module = parentdir.dir2.dir3.module_to_import
# Output: "Module Imported"

module.method1()
# Output: "Hello World"

Note: Accesing parent of parent is also possible as follows:

from parent_import import parentdir

module = parentdir.parentdir.another_dir.module_to_import

Another Usage - Import From Parent Directory:

from parent_import import add_ancestor_dir_to_path

add_ancestor_dir_to_path(level=1)

import dir2.dir3.module_to_import

Another Usage - Import From Parent of Parent Directory:

from parent_import import add_ancestor_dir_to_path

add_ancestor_dir_to_path(level=2)

import another_dir.module_to_import

TODO

  • Get rid of sys.path.insert(0, self.dir_path) statements in order to speed up module search. (possible?)
  • Override or extend import statement to use the Pythonic syntax for importing from parent directory. (possible?)

Metadata

Release files for parent-import 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for parent-import 0.0.1
File Size Uploaded Provenance Actions
parent_import-0.0.1.tar.gz 2.2 kB Without provenance Details for parent_import-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for parent-import 0.0.1
File Interpreter ABI Platform Actions
parent_import-0.0.1-py3-none-any.whl Python 3 none any Details for parent_import-0.0.1-py3-none-any.whl

Total release size: 5.5 kB

Release files / parent_import-0.0.1.tar.gz

Download URL parent_import-0.0.1.tar.gz
Size 2.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7fba8da2a9b902baf435f74901b66428b1fda35602cdda12424131a710155195
BLAKE2b-256 checksum
How to use checksums
9659ebdf2eb731975131b3c39bcc6e0049f300540e0802ac7e65b11ce80f0c92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.0

Release files / parent_import-0.0.1-py3-none-any.whl

Download URL parent_import-0.0.1-py3-none-any.whl
Size 3.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7778d8614f2aac0099186d8c7801e6ae26bfe6af19573aba02648f5205ad5350
BLAKE2b-256 checksum
How to use checksums
b3d2c0a607f1f98f55547c2c8bd7e96b52070123db287f001148caa63b7e2632
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.0

Security for parent-import 0.0.1

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.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page