networkx 2.8.2 Pypi GitHub Homepage
Other Docs
ParametersReturns
lazy_import(fullname)

We often see the following pattern:

def myfunc():
    import scipy as sp
    sp.argmin(...)
    ....

This is to prevent a library, in this case scipy , from being imported at function definition time, since that can be slow.

This function provides a proxy module that, upon access, imports the actual module. So the idiom equivalent to the above example is:

sp = lazy.load("scipy")

def myfunc():
    sp.argmin(...)
    ....

The initial import time is fast because the actual import is delayed until the first attribute is requested. The overall import time may decrease as well for users that don't make use of large portions of the library.

Parameters

fullname : str

The full name of the package or subpackage to import. For example:

sp = lazy.load('scipy')  # import scipy as sp
spla = lazy.load('scipy.linalg')  # import scipy.linalg as spla

Returns

pm : importlib.util._LazyModule

Proxy module. Can be used like any regularly imported module. Actual loading of the module occurs upon first attribute request.

Return a lazily imported proxy for a module or library.

Examples

See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/lazy_imports.py#103
type: <class 'function'>
Commit: