Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/heynemann/importer
Importer is a library to do dynamic importing of modules in python
https://github.com/heynemann/importer
Last synced: about 1 month ago
JSON representation
Importer is a library to do dynamic importing of modules in python
- Host: GitHub
- URL: https://github.com/heynemann/importer
- Owner: heynemann
- License: mit
- Created: 2016-12-29T00:16:50.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2016-12-29T01:34:32.000Z (almost 8 years ago)
- Last Synced: 2024-09-29T06:09:02.102Z (2 months ago)
- Language: Python
- Size: 8.79 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- starred-awesome - importer - Importer is a library to do dynamic importing of modules in python (Python)
README
# importer
Importer is a library to do dynamic importing of modules in python.
## Installing
```
$ pip install importer-lib
```## Usage
```
from importer import Importer# sets importer.module_a to the sys module
importer.import_item('module_a', 'sys')# sets importer.module_b to the importer.core module
importer.import_item('module_b', 'importer.core')# sets importer.module_c to the Importer class
importer.import_item('module_c', 'importer.core', class_name='Importer')# Multiple Imports
# sets importer.modules to the specified modules
importer.import_item('modules', ('importer.core', 'os', 'sys', 'preggy'))# sets importer.handlers to the the specified class in all modules
# this is very useful for modules that have the
# same class like request handlers (Handler class)
importer.import_item(
'handlers', (
'module.handlers.healthcheck',
'module.handlers.index',
'module.handlers.login',
), class_name='Handler'
)# Loading all modules
# You can also specify several modules to load at once# this is the same as all the calls above combined
importer.load(
{'key': 'module_a', 'module_names': 'sys'},
{'key': 'module_b', 'module_names': 'importer.core'},
{'key': 'module_c', 'module_names': 'importer.core', 'class_name': 'Importer'},
{'key': 'modules', 'module_names': ('importer.core', 'os', 'sys', 'preggy')},
{'key': 'classes', 'module_names': (
'module.handlers.healthcheck',
'module.handlers.index',
'module.handlers.login',
), 'class_name': 'Handler'},
)