or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

client-configuration.mdconnection-management.mdconnection-types.mdiam-policy-management.mdindex.mdresource-path-helpers.md

client-configuration.mddocs/

0

# Client Configuration

1

2

Configuration options for BigQuery Connection API clients including credentials, transport selection, retry policies, timeouts, and metadata handling. The library provides both synchronous and asynchronous clients with flexible configuration options.

3

4

## Capabilities

5

6

### Synchronous Client

7

8

The `ConnectionServiceClient` provides synchronous operations for connection management.

9

10

```python { .api }

11

class ConnectionServiceClient:

12

"""Manages connections to external data source connections and credentials."""

13

14

def __init__(

15

self,

16

*,

17

credentials: Optional[ga_credentials.Credentials] = None,

18

transport: Optional[Union[str, ConnectionServiceTransport, Callable]] = None,

19

client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None,

20

client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,

21

) -> None:

22

"""

23

Initialize the Connection Service client.

24

25

Parameters:

26

- credentials: The authorization credentials to attach to requests

27

- transport: The transport to use for communication with the service

28

- client_options: Custom options for the client

29

- client_info: Client information used to generate the user-agent string

30

"""

31

```

32

33

**Usage Examples:**

34

35

```python

36

from google.cloud.bigquery_connection import ConnectionServiceClient

37

from google.oauth2 import service_account

38

from google.api_core import client_options

39

40

# Default initialization (uses Application Default Credentials)

41

client = ConnectionServiceClient()

42

43

# With explicit service account credentials

44

credentials = service_account.Credentials.from_service_account_file(

45

"/path/to/service-account-key.json"

46

)

47

client = ConnectionServiceClient(credentials=credentials)

48

49

# With custom client options

50

options = client_options.ClientOptions(

51

api_endpoint="custom-bigqueryconnection.googleapis.com"

52

)

53

client = ConnectionServiceClient(client_options=options)

54

55

# With specific transport

56

client = ConnectionServiceClient(transport="grpc")

57

client = ConnectionServiceClient(transport="rest")

58

```

59

60

### Asynchronous Client

61

62

The `ConnectionServiceAsyncClient` provides asynchronous operations for connection management.

63

64

```python { .api }

65

class ConnectionServiceAsyncClient:

66

"""Manages connections to external data source connections and credentials asynchronously."""

67

68

def __init__(

69

self,

70

*,

71

credentials: Optional[ga_credentials.Credentials] = None,

72

transport: Optional[Union[str, ConnectionServiceTransport, Callable]] = "grpc_asyncio",

73

client_options: Optional[client_options_lib.ClientOptions] = None,

74

client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,

75

) -> None:

76

"""

77

Initialize the Connection Service async client.

78

79

Parameters:

80

- credentials: The authorization credentials to attach to requests

81

- transport: The transport to use (defaults to "grpc_asyncio")

82

- client_options: Custom options for the client

83

- client_info: Client information used to generate the user-agent string

84

"""

85

```

86

87

**Usage Examples:**

88

89

```python

90

import asyncio

91

from google.cloud.bigquery_connection import ConnectionServiceAsyncClient

92

93

async def main():

94

# Default async initialization

95

async_client = ConnectionServiceAsyncClient()

96

97

# List connections asynchronously

98

parent = "projects/my-project/locations/us-central1"

99

connections = async_client.list_connections(parent=parent)

100

101

async for connection in connections:

102

print(f"Connection: {connection.friendly_name}")

103

104

# Clean up

105

await async_client.transport.close()

106

107

# Run async code

108

asyncio.run(main())

109

```

110

111

### Factory Methods

112

113

Both client classes provide factory methods for convenient initialization from service account files.

114

115

```python { .api }

116

@classmethod

117

def from_service_account_info(

118

cls,

119

info: dict,

120

*args,

121

**kwargs

122

) -> "ConnectionServiceClient":

123

"""

124

Creates a client instance from parsed service account info.

125

126

Parameters:

127

- info: Service account info in JSON format

128

- args: Additional arguments to pass to the constructor

129

- kwargs: Additional keyword arguments to pass to the constructor

130

131

Returns:

132

ConnectionServiceClient: The constructed client

133

"""

134

135

@classmethod

136

def from_service_account_file(

137

cls,

138

filename: str,

139

*args,

140

**kwargs

141

) -> "ConnectionServiceClient":

142

"""

143

Creates a client instance from a service account JSON file.

144

145

Parameters:

146

- filename: Path to the service account JSON file

147

- args: Additional arguments to pass to the constructor

148

- kwargs: Additional keyword arguments to pass to the constructor

149

150

Returns:

151

ConnectionServiceClient: The constructed client

152

"""

153

154

# Alias for from_service_account_file

155

from_service_account_json = from_service_account_file

156

```

157

158

**Usage Examples:**

159

160

```python

161

# From service account file

162

client = ConnectionServiceClient.from_service_account_file(

163

"/path/to/service-account-key.json"

164

)

165

166

# From service account info dict

167

import json

168

with open("/path/to/service-account-key.json") as f:

169

service_account_info = json.load(f)

170

171

client = ConnectionServiceClient.from_service_account_info(

172

service_account_info

173

)

174

175

# With additional client options

176

client = ConnectionServiceClient.from_service_account_file(

177

"/path/to/service-account-key.json",

178

client_options={"api_endpoint": "custom-endpoint.googleapis.com"}

179

)

180

```

181

182

### Transport Configuration

183

184

Configure the underlying transport layer for communication with the BigQuery Connection API.

185

186

```python { .api }

187

@classmethod

188

def get_transport_class(

189

cls,

190

label: Optional[str] = None,

191

) -> Type[ConnectionServiceTransport]:

192

"""

193

Returns an appropriate transport class.

194

195

Parameters:

196

- label: The name of the desired transport ("grpc", "grpc_asyncio", "rest")

197

198

Returns:

199

Type[ConnectionServiceTransport]: The transport class

200

"""

201

```

202

203

**Available Transport Options:**

204

205

- **grpc**: Synchronous gRPC transport (default for sync client)

206

- **grpc_asyncio**: Asynchronous gRPC transport (default for async client)

207

- **rest**: HTTP/REST transport

208

209

**Usage Examples:**

210

211

```python

212

# Explicitly specify transport

213

client = ConnectionServiceClient(transport="grpc")

214

client = ConnectionServiceClient(transport="rest")

215

216

# Get transport class

217

transport_class = ConnectionServiceClient.get_transport_class("grpc")

218

custom_transport = transport_class(credentials=credentials)

219

client = ConnectionServiceClient(transport=custom_transport)

220

221

# For async client

222

async_client = ConnectionServiceAsyncClient(transport="grpc_asyncio")

223

```

224

225

### Client Options

226

227

Customize client behavior using `ClientOptions`.

228

229

```python { .api }

230

from google.api_core import client_options as client_options_lib

231

232

class ClientOptions:

233

"""Options for configuring the client."""

234

api_endpoint: str # API endpoint to use

235

client_cert_source: Callable # Client certificate source

236

client_encrypted_cert_source: Callable # Encrypted client certificate source

237

quota_project_id: str # Project ID for quota and billing

238

credentials_file: str # Path to credentials file

239

scopes: List[str] # OAuth2 scopes for authentication

240

default_scopes: List[str] # Default OAuth2 scopes

241

```

242

243

**Usage Examples:**

244

245

```python

246

from google.api_core import client_options

247

248

# Custom API endpoint

249

options = client_options.ClientOptions(

250

api_endpoint="custom-bigqueryconnection.googleapis.com"

251

)

252

client = ConnectionServiceClient(client_options=options)

253

254

# Quota project ID

255

options = client_options.ClientOptions(

256

quota_project_id="my-billing-project"

257

)

258

client = ConnectionServiceClient(client_options=options)

259

260

# Multiple options

261

options = client_options.ClientOptions(

262

api_endpoint="custom-endpoint.googleapis.com",

263

quota_project_id="my-billing-project"

264

)

265

client = ConnectionServiceClient(client_options=options)

266

267

# From dictionary

268

options_dict = {

269

"api_endpoint": "custom-endpoint.googleapis.com",

270

"quota_project_id": "my-billing-project"

271

}

272

client = ConnectionServiceClient(client_options=options_dict)

273

```

274

275

### Request Configuration

276

277

Configure individual request behavior using retry, timeout, and metadata parameters.

278

279

```python { .api }

280

from google.api_core import retry as retries

281

from google.api_core import gapic_v1

282

from typing import Union, Sequence, Tuple

283

284

OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None]

285

286

# All client methods support these parameters:

287

# - retry: OptionalRetry = gapic_v1.method.DEFAULT

288

# - timeout: Union[float, object] = gapic_v1.method.DEFAULT

289

# - metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()

290

```

291

292

**Usage Examples:**

293

294

```python

295

from google.api_core import retry as retries

296

import time

297

298

# Custom retry configuration

299

retry_config = retries.Retry(

300

initial=1.0, # Initial delay in seconds

301

maximum=60.0, # Maximum delay in seconds

302

multiplier=2.0, # Delay multiplier

303

predicate=retries.if_transient_error, # Retry on transient errors

304

deadline=300.0 # Total deadline in seconds

305

)

306

307

# Use custom retry

308

connection = client.get_connection(

309

name="projects/my-project/locations/us-central1/connections/my-conn",

310

retry=retry_config

311

)

312

313

# Custom timeout (30 seconds)

314

connection = client.get_connection(

315

name="projects/my-project/locations/us-central1/connections/my-conn",

316

timeout=30.0

317

)

318

319

# Custom metadata

320

metadata = [

321

("x-custom-header", "custom-value"),

322

("x-request-id", "req-12345")

323

]

324

325

connection = client.get_connection(

326

name="projects/my-project/locations/us-central1/connections/my-conn",

327

metadata=metadata

328

)

329

330

# Disable retry

331

connection = client.get_connection(

332

name="projects/my-project/locations/us-central1/connections/my-conn",

333

retry=None

334

)

335

```

336

337

### Context Manager Support

338

339

Both client classes support context manager protocols for automatic resource cleanup.

340

341

```python { .api }

342

class ConnectionServiceClient:

343

def __enter__(self) -> "ConnectionServiceClient":

344

"""Enter context manager."""

345

return self

346

347

def __exit__(self, type, value, traceback) -> None:

348

"""Exit context manager and clean up resources."""

349

350

class ConnectionServiceAsyncClient:

351

async def __aenter__(self) -> "ConnectionServiceAsyncClient":

352

"""Enter async context manager."""

353

return self

354

355

async def __aexit__(self, exc_type, exc, tb) -> None:

356

"""Exit async context manager and clean up resources."""

357

```

358

359

**Usage Examples:**

360

361

```python

362

# Synchronous context manager

363

with ConnectionServiceClient() as client:

364

connections = client.list_connections(

365

parent="projects/my-project/locations/us-central1"

366

)

367

for connection in connections:

368

print(connection.friendly_name)

369

# Client automatically cleaned up

370

371

# Asynchronous context manager

372

async def async_example():

373

async with ConnectionServiceAsyncClient() as async_client:

374

connections = async_client.list_connections(

375

parent="projects/my-project/locations/us-central1"

376

)

377

async for connection in connections:

378

print(connection.friendly_name)

379

# Async client automatically cleaned up

380

```

381

382

### Client Properties

383

384

Access client configuration and service information.

385

386

```python { .api }

387

class ConnectionServiceClient:

388

@property

389

def transport(self) -> ConnectionServiceTransport:

390

"""The transport used by the client instance."""

391

392

@property

393

def api_endpoint(self) -> str:

394

"""The API endpoint for the service."""

395

396

@property

397

def universe_domain(self) -> str:

398

"""The universe domain used by the client instance."""

399

400

class ConnectionServiceAsyncClient:

401

@property

402

def transport(self) -> ConnectionServiceTransport:

403

"""The transport used by the client instance."""

404

405

@property

406

def api_endpoint(self) -> str:

407

"""The API endpoint for the service."""

408

409

@property

410

def universe_domain(self) -> str:

411

"""The universe domain used by the client instance."""

412

```

413

414

**Usage Examples:**

415

416

```python

417

client = ConnectionServiceClient()

418

419

print(f"API Endpoint: {client.api_endpoint}")

420

print(f"Universe Domain: {client.universe_domain}")

421

print(f"Transport Type: {type(client.transport).__name__}")

422

423

# Check transport configuration

424

if hasattr(client.transport, '_credentials'):

425

print("Using custom credentials")

426

else:

427

print("Using default credentials")

428

```

429

430

## Types

431

432

### Core Configuration Types

433

434

```python { .api }

435

from google.auth import credentials as ga_credentials

436

from google.api_core import client_options as client_options_lib

437

from google.api_core import gapic_v1

438

439

# Credential types

440

Credentials = ga_credentials.Credentials

441

442

# Client configuration

443

ClientOptions = client_options_lib.ClientOptions

444

ClientInfo = gapic_v1.client_info.ClientInfo

445

446

# Transport types

447

ConnectionServiceTransport = Any # Base transport class

448

ConnectionServiceGrpcTransport = Any # gRPC transport

449

ConnectionServiceGrpcAsyncIOTransport = Any # Async gRPC transport

450

ConnectionServiceRestTransport = Any # REST transport

451

452

# Request configuration types

453

OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None]

454

```

455

456

### Default Configuration

457

458

```python { .api }

459

# Default values used by the client

460

DEFAULT_ENDPOINT = "bigqueryconnection.googleapis.com"

461

DEFAULT_MTLS_ENDPOINT = "bigqueryconnection.mtls.googleapis.com"

462

DEFAULT_UNIVERSE = "googleapis.com"

463

464

# Default client info

465

DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

466

gapic_version=package_version.__version__

467

)

468

```