Skip to main content

This package makes it easier to import from parent directory.

Project description

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?)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

parent_import-0.0.1.tar.gz (2.2 kB view details)

Uploaded Source

Built Distribution

parent_import-0.0.1-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file parent_import-0.0.1.tar.gz.

File metadata

  • Download URL: parent_import-0.0.1.tar.gz
  • Upload date:
  • Size: 2.2 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for parent_import-0.0.1.tar.gz
Algorithm Hash digest
SHA256 7fba8da2a9b902baf435f74901b66428b1fda35602cdda12424131a710155195
MD5 b863905d497bb860d87512ee52a967f1
BLAKE2b-256 9659ebdf2eb731975131b3c39bcc6e0049f300540e0802ac7e65b11ce80f0c92

See more details on using hashes here.

File details

Details for the file parent_import-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: parent_import-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for parent_import-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7778d8614f2aac0099186d8c7801e6ae26bfe6af19573aba02648f5205ad5350
MD5 e2c45ca2c1c5a0cf45f991c6569d21a5
BLAKE2b-256 b3d2c0a607f1f98f55547c2c8bd7e96b52070123db287f001148caa63b7e2632

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page