Google Cloud Service Usage API client library for managing Google Cloud services programmatically
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
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.
pip install google-cloud-service-usagefrom google.cloud import service_usageImport specific clients:
from google.cloud.service_usage import ServiceUsageClient, ServiceUsageAsyncClientImport types and request/response classes:
from google.cloud.service_usage import (
Service,
State,
EnableServiceRequest,
ListServicesRequest,
BatchEnableServicesRequest
)Import retry and timeout types:
from google.api_core import gapic_v1
from google.api_core import retry as retries
from typing import Union, Optional, Sequence, Tuple
OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None]from google.cloud import service_usage
# Initialize client
client = service_usage.ServiceUsageClient()
# List all services for a project
project_name = "projects/my-project-id"
request = service_usage.ListServicesRequest(parent=project_name)
services = client.list_services(request=request)
for service in services:
print(f"Service: {service.name}")
print(f"State: {service.state}")
# Enable a service
service_name = f"{project_name}/services/storage.googleapis.com"
enable_request = service_usage.EnableServiceRequest(name=service_name)
operation = client.enable_service(request=enable_request)
# Wait for operation to complete
result = operation.result()
print(f"Service enabled: {result.service.name}")
# Get specific service information
get_request = service_usage.GetServiceRequest(name=service_name)
service = client.get_service(request=get_request)
print(f"Service config: {service.config.title}")The library follows Google's standard client library patterns:
Core service lifecycle operations including enabling, disabling, and batch operations for managing Google Cloud services within projects.
def enable_service(request: EnableServiceRequest, **kwargs) -> Operation[EnableServiceResponse, OperationMetadata]: ...
def disable_service(request: DisableServiceRequest, **kwargs) -> Operation[DisableServiceResponse, OperationMetadata]: ...
def batch_enable_services(request: BatchEnableServicesRequest, **kwargs) -> Operation[BatchEnableServicesResponse, OperationMetadata]: ...Query and discovery operations for listing services, retrieving service configurations, and batch information retrieval.
def get_service(request: GetServiceRequest, **kwargs) -> Service: ...
def list_services(request: ListServicesRequest, **kwargs) -> ListServicesPager: ...
def batch_get_services(request: BatchGetServicesRequest, **kwargs) -> BatchGetServicesResponse: ...Async versions of all service management and discovery operations for non-blocking I/O in async applications.
async def enable_service(request: EnableServiceRequest, **kwargs) -> AsyncOperation[EnableServiceResponse, OperationMetadata]: ...
async def list_services(request: ListServicesRequest, **kwargs) -> ListServicesAsyncPager: ...Operations for managing and monitoring long-running service management tasks.
def list_operations(request: ListOperationsRequest, **kwargs) -> ListOperationsPager: ...
def get_operation(request: GetOperationRequest, **kwargs) -> Operation: ...class State(Enum):
"""Service enablement state."""
STATE_UNSPECIFIED = 0
DISABLED = 1
ENABLED = 2
class Service:
"""A Google Cloud service that is available for use."""
name: str
parent: str
config: ServiceConfig
state: State
class ServiceConfig:
"""Configuration and metadata for a service."""
name: str
title: str
documentation: Documentation
quota: Quota
authentication: Authentication
usage: Usage
endpoints: List[Endpoint]
apis: List[Api]
monitored_resources: List[MonitoredResourceDescriptor]
monitoring: Monitoring
class OperationMetadata:
"""Metadata for long-running operations."""
resource_names: List[str]
# Additional imported types from Google API
from google.api import documentation_pb2, quota_pb2, auth_pb2, usage_pb2, endpoint_pb2, monitored_resource_pb2, monitoring_pb2
from google.protobuf import api_pb2
Documentation = documentation_pb2.Documentation
Quota = quota_pb2.Quota
Authentication = auth_pb2.Authentication
Usage = usage_pb2.Usage
Endpoint = endpoint_pb2.Endpoint
MonitoredResourceDescriptor = monitored_resource_pb2.MonitoredResourceDescriptor
Monitoring = monitoring_pb2.Monitoring
Api = api_pb2.Api