Skip to content
Open
54 changes: 40 additions & 14 deletions packages/google-api-core/google/api_core/gapic_v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,44 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from google.api_core.gapic_v1 import client_info
from google.api_core.gapic_v1 import config
from google.api_core.gapic_v1 import config_async
from google.api_core.gapic_v1 import method
from google.api_core.gapic_v1 import method_async
from google.api_core.gapic_v1 import routing_header
import importlib.util
from typing import Set

__all__ = [
"client_info",
"config",
"config_async",
"method",
"method_async",
"routing_header",
]
_has_grpc = importlib.util.find_spec("grpc") is not None

# PEP 0810: Explicit Lazy Imports
# Python 3.15+ natively intercepts and defers these imports.
# Developers can disable this behavior and force eager imports.
# For more information, see:
# https://docs.python.org/3.15/library/sys.html#sys.set_lazy_imports_filter
# Older Python versions safely ignore this variable.
__lazy_modules__: Set[str] = {
"google.api_core.gapic_v1.client_info",
"google.api_core.gapic_v1.routing_header",
}
__all__ = ["client_info", "routing_header"]

if _has_grpc:
__lazy_modules__.update(
{
"google.api_core.gapic_v1.config",
"google.api_core.gapic_v1.config_async",
"google.api_core.gapic_v1.method",
"google.api_core.gapic_v1.method_async",
}
)

from google.api_core.gapic_v1 import ( # noqa: E402
client_info,
routing_header,
)

if _has_grpc:
from google.api_core.gapic_v1 import ( # noqa: F401
config,
config_async,
method,
method_async,
)

__all__.extend(["config", "config_async", "method", "method_async"])
Loading