Google API client core library providing common helpers, utilities, and components for Python client libraries
—
URI template expansion and validation for Google API resource paths, supporting variable substitution and path parameter extraction for RESTful API endpoints.
def expand(tmpl, *args, **kwargs):
"""
Expand a path template with variables.
Args:
tmpl (str): Path template with {variable} placeholders
*args: Positional arguments for template variables
**kwargs: Named arguments for template variables
Returns:
str: Expanded path with variables substituted
"""
def validate(tmpl, path):
"""
Validate that a path matches a template pattern.
Args:
tmpl (str): Path template pattern
path (str): Path to validate
Returns:
dict: Extracted variables if path matches, raises ValueError if not
"""def get_field(request, field):
"""
Get field value from request dict or protobuf Message.
Args:
request: Request dict or protobuf Message
field (str): Field path (e.g., "user.name" for nested fields)
Returns:
Any: Field value
"""
def delete_field(request, field):
"""
Delete field from request dict or protobuf Message.
Args:
request: Request dict or protobuf Message
field (str): Field path to delete
"""
def transcode(http_options, message=None, **request_kwargs):
"""
Transcode gRPC request to HTTP format.
Args:
http_options: HTTP binding configuration
message: gRPC request message
**request_kwargs: Additional request parameters
Returns:
dict: HTTP request components (method, uri, body)
"""from google.api_core import path_template
# Expand template with named parameters
template = "projects/{project}/instances/{instance}/databases/{database}"
path = path_template.expand(template,
project="my-project",
instance="my-instance",
database="my-db")
print(path) # "projects/my-project/instances/my-instance/databases/my-db"
# Validate and extract parameters
extracted = path_template.validate(template, path)
print(extracted) # {"project": "my-project", "instance": "my-instance", "database": "my-db"}Install with Tessl CLI
npx tessl i tessl/pypi-google-api-core