ml_switcheroo.discovery.inspector¶

Inspection Engine for Python Packages.

This module provides the ApiInspector, a hybrid static-dynamic analysis tool designed to extract API signatures (functions, classes, and attributes) from Python packages.

It employs a two-stage strategy:

  1. Static Analysis (Griffe): Attempts to parse the source code first. This is safer and preserves comments/docstrings better, but fails on compiled modules (C-Extensions).

  2. Runtime Introspection (Inspect): Falls back to importing the module and inspecting live objects. This is required for frameworks like PyTorch, TensorFlow, and MLX which rely heavily on compiled bindings.

Memory Safety: Includes recursion safeguards (visited set tracking) to prevent infinite loops or memory explosion when traversing circular references in large libraries like PyTorch.

Classes¶

ApiInspector

A robust inspector for discovering API surfaces of installed libraries.

Module Contents¶

class ml_switcheroo.discovery.inspector.ApiInspector¶

A robust inspector for discovering API surfaces of installed libraries.

_package_cache¶

Cache of statically parsed Griffe trees.

Type:

Dict[str, griffe.Object]

inspect(package_name: str) → Dict[str, Any]¶

Scans a package and returns a flat catalog of its public API.

Parameters:

package_name – The importable name of the package.

Returns:

Dict mapping ‘fully.qualified.name’ -> {metadata_dict}.