Google Cloud Service Usage API client library for managing Google Cloud services programmatically
npx @tessl/cli install tessl/pypi-google-cloud-service-usage@1.13.00
# Google Cloud Service Usage
1
2
Google Cloud Service Usage API client library for Python that enables programmatic management of Google Cloud services within projects. This library provides comprehensive functionality to enable/disable services, query service configurations, and manage service enablement across Google Cloud projects.
3
4
## Package Information
5
6
- **Package Name**: google-cloud-service-usage
7
- **Language**: Python
8
- **Installation**: `pip install google-cloud-service-usage`
9
10
## Core Imports
11
12
```python
13
from google.cloud import service_usage
14
```
15
16
Import specific clients:
17
18
```python
19
from google.cloud.service_usage import ServiceUsageClient, ServiceUsageAsyncClient
20
```
21
22
Import types and request/response classes:
23
24
```python
25
from google.cloud.service_usage import (
26
Service,
27
State,
28
EnableServiceRequest,
29
ListServicesRequest,
30
BatchEnableServicesRequest
31
)
32
```
33
34
Import retry and timeout types:
35
36
```python
37
from google.api_core import gapic_v1
38
from google.api_core import retry as retries
39
from typing import Union, Optional, Sequence, Tuple
40
41
OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None]
42
```
43
44
## Basic Usage
45
46
```python
47
from google.cloud import service_usage
48
49
# Initialize client
50
client = service_usage.ServiceUsageClient()
51
52
# List all services for a project
53
project_name = "projects/my-project-id"
54
request = service_usage.ListServicesRequest(parent=project_name)
55
services = client.list_services(request=request)
56
57
for service in services:
58
print(f"Service: {service.name}")
59
print(f"State: {service.state}")
60
61
# Enable a service
62
service_name = f"{project_name}/services/storage.googleapis.com"
63
enable_request = service_usage.EnableServiceRequest(name=service_name)
64
operation = client.enable_service(request=enable_request)
65
66
# Wait for operation to complete
67
result = operation.result()
68
print(f"Service enabled: {result.service.name}")
69
70
# Get specific service information
71
get_request = service_usage.GetServiceRequest(name=service_name)
72
service = client.get_service(request=get_request)
73
print(f"Service config: {service.config.title}")
74
```
75
76
## Architecture
77
78
The library follows Google's standard client library patterns:
79
80
- **Client Classes**: ServiceUsageClient (sync) and ServiceUsageAsyncClient (async) provide the main API interface
81
- **Transport Layer**: Supports gRPC, async gRPC, and REST transports for different deployment scenarios
82
- **Request/Response Types**: Strongly-typed message classes for all API operations
83
- **Resource Types**: Service, ServiceConfig, and OperationMetadata represent core domain objects
84
- **Pagination**: Built-in pager classes for handling large result sets
85
- **Authentication**: Integrates with Google Cloud authentication and service accounts
86
- **Error Handling**: Uses google.api_core.exceptions for consistent error handling
87
- **Retry Logic**: Automatic retries with configurable policies for transient failures
88
89
## Capabilities
90
91
### Service Management Operations
92
93
Core service lifecycle operations including enabling, disabling, and batch operations for managing Google Cloud services within projects.
94
95
```python { .api }
96
def enable_service(request: EnableServiceRequest, **kwargs) -> Operation[EnableServiceResponse, OperationMetadata]: ...
97
def disable_service(request: DisableServiceRequest, **kwargs) -> Operation[DisableServiceResponse, OperationMetadata]: ...
98
def batch_enable_services(request: BatchEnableServicesRequest, **kwargs) -> Operation[BatchEnableServicesResponse, OperationMetadata]: ...
99
```
100
101
[Service Management](./service-management.md)
102
103
### Service Discovery and Information
104
105
Query and discovery operations for listing services, retrieving service configurations, and batch information retrieval.
106
107
```python { .api }
108
def get_service(request: GetServiceRequest, **kwargs) -> Service: ...
109
def list_services(request: ListServicesRequest, **kwargs) -> ListServicesPager: ...
110
def batch_get_services(request: BatchGetServicesRequest, **kwargs) -> BatchGetServicesResponse: ...
111
```
112
113
[Service Discovery](./service-discovery.md)
114
115
### Asynchronous Client Operations
116
117
Async versions of all service management and discovery operations for non-blocking I/O in async applications.
118
119
```python { .api }
120
async def enable_service(request: EnableServiceRequest, **kwargs) -> AsyncOperation[EnableServiceResponse, OperationMetadata]: ...
121
async def list_services(request: ListServicesRequest, **kwargs) -> ListServicesAsyncPager: ...
122
```
123
124
[Async Operations](./async-operations.md)
125
126
### Long-Running Operations Management
127
128
Operations for managing and monitoring long-running service management tasks.
129
130
```python { .api }
131
def list_operations(request: ListOperationsRequest, **kwargs) -> ListOperationsPager: ...
132
def get_operation(request: GetOperationRequest, **kwargs) -> Operation: ...
133
```
134
135
[Operations Management](./operations-management.md)
136
137
## Types
138
139
```python { .api }
140
class State(Enum):
141
"""Service enablement state."""
142
STATE_UNSPECIFIED = 0
143
DISABLED = 1
144
ENABLED = 2
145
146
class Service:
147
"""A Google Cloud service that is available for use."""
148
name: str
149
parent: str
150
config: ServiceConfig
151
state: State
152
153
class ServiceConfig:
154
"""Configuration and metadata for a service."""
155
name: str
156
title: str
157
documentation: Documentation
158
quota: Quota
159
authentication: Authentication
160
usage: Usage
161
endpoints: List[Endpoint]
162
apis: List[Api]
163
monitored_resources: List[MonitoredResourceDescriptor]
164
monitoring: Monitoring
165
166
class OperationMetadata:
167
"""Metadata for long-running operations."""
168
resource_names: List[str]
169
170
# Additional imported types from Google API
171
from google.api import documentation_pb2, quota_pb2, auth_pb2, usage_pb2, endpoint_pb2, monitored_resource_pb2, monitoring_pb2
172
from google.protobuf import api_pb2
173
174
Documentation = documentation_pb2.Documentation
175
Quota = quota_pb2.Quota
176
Authentication = auth_pb2.Authentication
177
Usage = usage_pb2.Usage
178
Endpoint = endpoint_pb2.Endpoint
179
MonitoredResourceDescriptor = monitored_resource_pb2.MonitoredResourceDescriptor
180
Monitoring = monitoring_pb2.Monitoring
181
Api = api_pb2.Api
182
```