importing
Class info¶
🛈 DocStrings¶
Utilities for importing callables and classes from dotted paths.
get_module_source
¶
Get source code from a module or package.
Source code in src/llmling/utils/importing.py
get_pyobject_members
¶
get_pyobject_members(
obj: type | ModuleType | Any, *, include_imported: bool = False
) -> Iterator[tuple[str, Callable[..., Any]]]
Get callable members defined in a Python object.
Works with modules, classes, and instances. Only returns public callable members (functions, methods, etc.) that are defined in the object's module unless include_imported is True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
type | ModuleType | Any
|
Any Python object to inspect (module, class, instance) |
required |
include_imported
|
bool
|
Whether to include imported/inherited callables |
False
|
Yields:
| Type | Description |
|---|---|
tuple[str, Callable[..., Any]]
|
Tuples of (name, callable) for each public callable |
Example
class MyClass: ... def method(self): pass ... def _private(self): pass for name, func in get_pyobject_members(MyClass()): ... print(name) method
import my_module for name, func in get_pyobject_members(my_module): ... print(name) public_function
Source code in src/llmling/utils/importing.py
import_callable
¶
Import a callable from a dotted path.
Supports both dot and colon notation: - Dot notation: module.submodule.Class.method - Colon notation: module.submodule:Class.method
Examples:
>>> import_callable("os.path.join")
>>> import_callable("llmling.testing:processors.failing_processor")
>>> import_callable("builtins.str.upper")
>>> import_callable("sqlalchemy.orm:Session.query")
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Import path using dots and/or colon |
required |
Returns:
| Type | Description |
|---|---|
Callable[..., Any]
|
Imported callable |
Raises:
| Type | Description |
|---|---|
ValueError
|
If path cannot be imported or result isn't callable |
Source code in src/llmling/utils/importing.py
import_class
¶
Import a class from a dotted path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Dot-separated path to the class |
required |
Returns:
| Type | Description |
|---|---|
type
|
The imported class |
Raises:
| Type | Description |
|---|---|
ValueError
|
If path is invalid or doesn't point to a class |