GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • google-api-core
  • Authentication
  • Client Information Helpers
  • Client Options
  • Exceptions
  • Futures
  • Helpers
  • Identity and Access Management
  • Long-Running Operations
  • Long-Running Operations Client
  • Page Iterators
  • Path Templates
  • Retry
  • Timeout

This view

  • Original page
  • New address

GeezerVison is showing googleapis.dev — Path Templates — google-api-core documentation

As of January 1, 2020 this library no longer supports Python 2 on the latest released version. Library versions released prior to that date will continue to be available. For more information please visit Python 2 support on Google Cloud.

Path Templates¶

Expand and validate URL path templates.

This module provides the expand() and validate() functions for interacting with Google-style URL path templates which are commonly used in Google APIs for resource names.

google.api_core.path_template.delete_field(request, field)[source]¶

Delete the value of a field from a given dictionary.

Parameters
  • request (dict | Message) – A dictionary object or a Message.

  • field (str) – The key to the request in dot notation.

google.api_core.path_template.expand(tmpl, *args, **kwargs)[source]¶

Expand a path template with the given variables.

>>> expand('users/*/messages/*', 'me', '123')
users/me/messages/123
>>> expand('/v1/{name=shelves/*/books/*}', name='shelves/1/books/3')
/v1/shelves/1/books/3
Parameters
  • tmpl (str) – The path template.

  • args – The positional variables for the path.

  • kwargs – The named variables for the path.

Returns

The expanded path

Return type

str

Raises

ValueError – If a positional or named variable is required by the template but not specified or if an unexpected template expression is encountered.

google.api_core.path_template.get_field(request, field, encode=False)[source]¶

Get the value of a field from a given dictionary.

Parameters
  • request (dict | Message) – A dictionary or a Message object.

  • field (str) – The key to the request in dot notation.

  • encode (bool) – Whether to percent-encode the field value. If enabled, will encode all characters except [-_.~/0-9a-zA-Z] for URI path variable parts per https://github.com/googleapis/googleapis/blob/master/google/api/http.proto#L44-L312. Defaults to False.

Returns

The value of the field.

google.api_core.path_template.transcode(http_options, message=None, **request_kwargs)[source]¶

Transcodes a grpc request pattern into a proper HTTP request following the rules outlined here, https://github.com/googleapis/googleapis/blob/master/google/api/http.proto#L44-L312

Args:
http_options (list(dict)): A list of dicts which consist of these keys,

‘method’ (str): The http method ‘uri’ (str): The path template ‘body’ (str): The body field name (optional) (This is a simplified representation of the proto option google.api.http)

message (Message) : A request object (optional) request_kwargs (dict) : A dict representing the request object

Returns:
dict: The transcoded request with these keys,

‘method’ (str) : The http method ‘uri’ (str) : The expanded uri ‘body’ (dict | Message) : A dict or a Message representing the body (optional) ‘query_params’ (dict | Message) : A dict or Message mapping query parameter variables and values

Raises:

ValueError: If the request does not match the given template.

google.api_core.path_template.validate(tmpl, path)[source]¶

Validate a path against the path template.

>>> validate('users/*/messages/*', 'users/me/messages/123')
True
>>> validate('users/*/messages/*', 'users/me/drafts/123')
False
>>> validate('/v1/{name=shelves/*/books/*}', /v1/shelves/1/books/3)
True
>>> validate('/v1/{name=shelves/*/books/*}', /v1/shelves/1/tapes/3)
False
Parameters
  • tmpl (str) – The path template.

  • path (str) – The expanded path.

Returns

True if the path matches.

Return type

bool

©2019, Google. | Powered by Sphinx 4.5.0 & Alabaster 0.7.16 | Page source
Fork me on GitHub
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.