Skip to main content

Import Python modules from any file system path.

Project description

PyPI  

pathimp

Import Python modules from any file system path.

Installation

pip3 install pathimp

Usage

import pathimp

pathimp.import_module(
    name='my_module',              # Name of the module directory or file.
    path='../path/to/parent/dir',  # Path or list of paths to search.
    notfound='error')              # Raise 'error' or 'ignore' when not found.

import my_module

Details

After calling pathimp.import_module(), the module is available in sys.modules and can be imported normally by later code. The function also returns the module, allowing to use it directly without further import:

import pathimp
my_module = pathimp.import_module('my_module', '../path/to/parent/dir')

If the module is not found as a directory or file under the provided path, a ModuleNotFoundError is raied. The exception can be disable by passing the notfound='ignore' argument:

pathimp.import_module('my_module', '../path/to/parent/dir', notfound='ignore')

Whether the import succeeded can still be found out by looking at the return value, which is either the module instance or False if the module was not found.

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

pathimp-1.0.0.tar.gz (2.0 kB view details)

Uploaded Source

File details

Details for the file pathimp-1.0.0.tar.gz.

File metadata

  • Download URL: pathimp-1.0.0.tar.gz
  • Upload date:
  • Size: 2.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.7

File hashes

Hashes for pathimp-1.0.0.tar.gz
Algorithm Hash digest
SHA256 709fc9afab83cf304d1829ac9ffb0e3dbf415aeabfea7220a4247b2c47d2cf9f
MD5 01d439e05527858294ae05b191f67dc6
BLAKE2b-256 e7b8952c7225f93ae9115d20465f949bcbf3077ca73341cd0e6e2155dbf8febe

See more details on using hashes here.

Supported by

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