Readme
This library is the same as the Django utils module loader, but without needing Django as dependency. It is used to load modules/classes based on their dotted string path.
Install
pip install inuits-module-loader
Usage
from inuits_module_loader import import_string
import_string("dotted.path.to.your.module.or.class")
Example
This example will dynamically load classes in the extensions/resources folder that extend the default classes in the application. Default class: resources.your_file_name.YourClassName
Class in extensions folder: extensions.resources.your_file_name.YourClassName
It is recommended to name the extension file and class the same as the default class, and import the default class with an alias in your extension class.
Extended class
from resources.your_file_name.YourClassName import YourClassName as DefaultYourClassName
class YourClassName(DefaultYourClassName):
def do_something(self):
return True
App
from inuits_module_loader import import_string
import logging
logger = logging.getLogger(__name__)
# This function will try to load your class from the extension folder and fall back to the default class if there is no extension available for that class.
def load_resource(resource: str):
try:
logger.info(f"Loading {resource} extension.")
return import_string(f"extensions.resources.{resource}")
except ModuleNotFoundError:
logger.info(f"No {resource} extension found, loading core {resource}")
return import_string(f"resources.{resource}")
except ImportError as error:
logger.info(f"{error}, loading core {resource}")
return import_string(f"resources.{resource}")
# If you name your extended file and class the same as the default file and class you can easily add or remove classes from the extensions folder without adding additional code in the app.
your_class = load_resource("your_file_name.YourClassName")()
Metadata
Release files for inuits-module-loader 1.0.3
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 |
|---|---|---|---|---|
| inuits_module_loader-1.0.3.tar.gz | 9.3 kB | Without provenance | Details for inuits_module_loader-1.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| inuits_module_loader-1.0.3-py3-none-any.whl | Python 3 | none | any | Details for inuits_module_loader-1.0.3-py3-none-any.whl |
Total release size: 19.2 kB
Release files / inuits_module_loader-1.0.3.tar.gz
| Download URL | inuits_module_loader-1.0.3.tar.gz |
|---|---|
| Size | 9.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
16a6e024be44aefe19963d27192907065f457ffd27d4f56b35f2b748cda59afc
|
|
BLAKE2b-256 checksum How to use checksums |
8faab2c476ccefdaa742154dd055da61ee38f6fe7e09accfe1124af090cea823
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.8.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2
|
Release files / inuits_module_loader-1.0.3-py3-none-any.whl
| Download URL | inuits_module_loader-1.0.3-py3-none-any.whl |
|---|---|
| Size | 9.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7ec06db50c91eaf43a0c830b8c2894ab96ef70c1abc60737968ae6f086980389
|
|
BLAKE2b-256 checksum How to use checksums |
b967d8933d254823dfaa0365b51a3e7544dced8a512365403aafd9bc8651244c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.8.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2
|
Security for inuits-module-loader 1.0.3
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.