or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

async-operations.mdindex.mdoperations-management.mdservice-discovery.mdservice-management.md
tile.json

tessl/pypi-google-cloud-service-usage

Google Cloud Service Usage API client library for managing Google Cloud services programmatically

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/google-cloud-service-usage@1.13.x

To install, run

npx @tessl/cli install tessl/pypi-google-cloud-service-usage@1.13.0

index.mddocs/

Google Cloud Service Usage

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.

Package Information

  • Package Name: google-cloud-service-usage
  • Language: Python
  • Installation: pip install google-cloud-service-usage

Core Imports

from google.cloud import service_usage

Import specific clients:

from google.cloud.service_usage import ServiceUsageClient, ServiceUsageAsyncClient

Import 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]

Basic Usage

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}")

Architecture

The library follows Google's standard client library patterns:

  • Client Classes: ServiceUsageClient (sync) and ServiceUsageAsyncClient (async) provide the main API interface
  • Transport Layer: Supports gRPC, async gRPC, and REST transports for different deployment scenarios
  • Request/Response Types: Strongly-typed message classes for all API operations
  • Resource Types: Service, ServiceConfig, and OperationMetadata represent core domain objects
  • Pagination: Built-in pager classes for handling large result sets
  • Authentication: Integrates with Google Cloud authentication and service accounts
  • Error Handling: Uses google.api_core.exceptions for consistent error handling
  • Retry Logic: Automatic retries with configurable policies for transient failures

Capabilities

Service Management Operations

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]: ...

Service Management

Service Discovery and Information

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: ...

Service Discovery

Asynchronous Client Operations

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: ...

Async Operations

Long-Running Operations Management

Operations for managing and monitoring long-running service management tasks.

def list_operations(request: ListOperationsRequest, **kwargs) -> ListOperationsPager: ...
def get_operation(request: GetOperationRequest, **kwargs) -> Operation: ...

Operations Management

Types

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