Lazy initialization creates a service client only when first accessed, then reuses that instance on later accesses. In an SDK, this keeps unused services from creating clients or opening connections. section 2.5.2
A property-based service client follows this sequence:
- Initialize each client field to None; on property access, import and construct the client if it does not yet exist, then store and return it. section 2.5.2
- The constructed client connects to the gateway using a secure gRPC channel and identifies its target service in request metadata. section 2.5.2
- Creating only accessed clients avoids opening channels for unused services, reducing startup time, memory use, network overhead, and connection-pool pressure. section 2.5.2 section 2.6
Listing 2.18 Property-based lazy initialization of service clients
@property #A
def sessions(self): #A
if self._sessions is None: #B
from .clients.sessions
➥import SessionClient #C
self._sessions = SessionClient(self) #C
return self._sessions #DThe sessions property checks for an existing client, constructs and caches one on first access, then returns it. section 2.5.2











