CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-google-cloud-shell

Google Cloud Shell API client library for programmatic environment management.

Pending
Overview
Eval results
Files

clients.mddocs/

Client Management

Client initialization, configuration, and lifecycle management for both synchronous and asynchronous Google Cloud Shell API operations.

Capabilities

Synchronous Client

Main client class for synchronous operations with Google Cloud Shell environments.

class CloudShellServiceClient:
    """API for interacting with Google Cloud Shell environments."""
    
    def __init__(
        self,
        *,
        credentials: Optional[ga_credentials.Credentials] = None,
        transport: Optional[Union[str, CloudShellServiceTransport, Callable[..., CloudShellServiceTransport]]] = None,
        client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None,
        client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
    ) -> None:
        """
        Initialize the Cloud Shell Service client.
        
        Args:
            credentials: The authorization credentials to attach to requests
            transport: The transport to use for API calls. Options: "grpc", "rest", or transport instance
            client_options: Client options for configuring the client
            client_info: gRPC client info used to create user-agent string
        """

Factory Methods

Create client instances from service account credentials.

@classmethod
def from_service_account_info(
    cls, 
    info: dict, 
    *args, 
    **kwargs
) -> CloudShellServiceClient:
    """
    Create client instance from service account info dictionary.
    
    Args:
        info: Service account info in Google format
        *args: Additional arguments to pass to constructor
        **kwargs: Additional keyword arguments to pass to constructor
        
    Returns:
        CloudShellServiceClient instance
    """

@classmethod
def from_service_account_file(
    cls, 
    filename: str, 
    *args, 
    **kwargs
) -> CloudShellServiceClient:
    """
    Create client instance from service account JSON file.
    
    Args:
        filename: Path to service account JSON file
        *args: Additional arguments to pass to constructor
        **kwargs: Additional keyword arguments to pass to constructor
        
    Returns:
        CloudShellServiceClient instance
    """

from_service_account_json = from_service_account_file  # Alias for compatibility

Properties

Access client configuration and transport information.

@property
def transport(self) -> CloudShellServiceTransport:
    """Returns the transport used by the client instance."""

@property
def api_endpoint(self) -> str:
    """Return the API endpoint used by the client instance."""

@property
def universe_domain(self) -> str:
    """Return the universe domain used by the client instance."""

Context Manager Support

Use client as context manager for automatic resource cleanup.

def __enter__(self) -> "CloudShellServiceClient":
    """Enter context manager."""

def __exit__(self, type, value, traceback) -> None:
    """Exit context manager."""

Asynchronous Client

Async version of the Cloud Shell client for non-blocking operations.

class CloudShellServiceAsyncClient:
    """Async API for interacting with Google Cloud Shell environments."""
    
    def __init__(
        self,
        *,
        credentials: Optional[ga_credentials.Credentials] = None,
        transport: Optional[Union[str, CloudShellServiceTransport, Callable[..., CloudShellServiceTransport]]] = "grpc_asyncio",
        client_options: Optional[ClientOptions] = None,
        client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
    ) -> None:
        """
        Initialize the async Cloud Shell Service client.
        
        Args:
            credentials: The authorization credentials to attach to requests
            transport: The transport to use for API calls. Default: "grpc_asyncio"
            client_options: Client options for configuring the client
            client_info: gRPC client info used to create user-agent string
        """

Async Context Manager Support

Use async client as async context manager for automatic resource cleanup.

async def __aenter__(self) -> "CloudShellServiceAsyncClient":
    """Enter async context manager."""

async def __aexit__(self, exc_type, exc, tb) -> None:
    """Exit async context manager."""

Resource Path Helpers

Static methods for constructing and parsing Google Cloud resource paths.

Environment Paths

@staticmethod
def environment_path(user: str, environment: str) -> str:
    """
    Returns fully-qualified environment string.
    
    Args:
        user: User email or "me" for current user
        environment: Environment ID (e.g., "default")
        
    Returns:
        Resource path: users/{user}/environments/{environment}
    """

@staticmethod
def parse_environment_path(path: str) -> Dict[str, str]:
    """
    Parses environment path into component segments.
    
    Args:
        path: Environment resource path
        
    Returns:
        Dictionary with 'user' and 'environment' keys
    """

Common Resource Paths

Helper methods for other Google Cloud resource types.

@staticmethod
def common_billing_account_path(billing_account: str) -> str:
    """Returns fully-qualified billing account string."""

@staticmethod
def parse_common_billing_account_path(path: str) -> Dict[str, str]:
    """Parse billing account path into component segments."""

@staticmethod
def common_folder_path(folder: str) -> str:
    """Returns fully-qualified folder string."""

@staticmethod
def parse_common_folder_path(path: str) -> Dict[str, str]:
    """Parse folder path into component segments."""

@staticmethod
def common_organization_path(organization: str) -> str:
    """Returns fully-qualified organization string."""

@staticmethod
def parse_common_organization_path(path: str) -> Dict[str, str]:
    """Parse organization path into component segments."""

@staticmethod
def common_project_path(project: str) -> str:
    """Returns fully-qualified project string."""

@staticmethod
def parse_common_project_path(path: str) -> Dict[str, str]:
    """Parse project path into component segments."""

@staticmethod
def common_location_path(project: str, location: str) -> str:
    """Returns fully-qualified location string."""

@staticmethod
def parse_common_location_path(path: str) -> Dict[str, str]:
    """Parse location path into component segments."""

Usage Examples

Basic Client Initialization

from google.cloud.shell import CloudShellServiceClient

# Use default credentials
client = CloudShellServiceClient()

# Use specific service account
client = CloudShellServiceClient.from_service_account_file(
    "path/to/service-account.json"
)

# Use custom transport
client = CloudShellServiceClient(transport="rest")

Context Manager Usage

from google.cloud.shell import CloudShellServiceClient

# Automatic cleanup
with CloudShellServiceClient() as client:
    environment = client.get_environment(
        name="users/me/environments/default"
    )
    print(f"Environment state: {environment.state}")

Async Client Usage

import asyncio
from google.cloud.shell import CloudShellServiceAsyncClient

async def main():
    async with CloudShellServiceAsyncClient() as client:
        environment = await client.get_environment(
            name="users/me/environments/default"
        )
        print(f"Environment state: {environment.state}")

asyncio.run(main())

Resource Path Construction

from google.cloud.shell import CloudShellServiceClient

# Build environment path
env_path = CloudShellServiceClient.environment_path(
    user="me", 
    environment="default"
)
print(env_path)  # users/me/environments/default

# Parse environment path
components = CloudShellServiceClient.parse_environment_path(env_path)
print(components)  # {'user': 'me', 'environment': 'default'}

Constants

DEFAULT_ENDPOINT = "cloudshell.googleapis.com"
DEFAULT_MTLS_ENDPOINT = "cloudshell.mtls.googleapis.com"

Transport Options

  • "grpc" - gRPC transport (default for synchronous client)
  • "grpc_asyncio" - AsyncIO gRPC transport (default for asynchronous client)
  • "rest" - REST transport

Install with Tessl CLI

npx tessl i tessl/pypi-google-cloud-shell

docs

clients.md

environments.md

index.md

ssh-keys.md

tile.json