msrest package

Submodules

msrest.authentication module

class msrest.authentication.ApiKeyCredentials(in_headers=None, in_query=None)[source]

Bases: msrest.authentication.Authentication

Represent the ApiKey feature of Swagger.

Dict should be dict[str, str] to be accepted by requests.

Parameters:
  • str] in_headers (dict[str,) – Headers part of the ApiKey
  • str] in_query (dict[str,) – ApiKey in the query as parameters.
signed_session()[source]

Create requests session with ApiKey.

Return type:requests.Session.
class msrest.authentication.Authentication[source]

Bases: object

Default, simple auth object. Doesn’t actually add any auth headers.

header = 'Authorization'
signed_session()[source]

Create requests session with any required auth headers applied.

Return type:requests.Session.
class msrest.authentication.BasicAuthentication(username, password)[source]

Bases: msrest.authentication.Authentication

Implmentation of Basic Authentication.

Parameters:
  • username (str) – Authentication username.
  • password (str) – Authentication password.
signed_session()[source]

Create requests session with any required auth headers applied.

Return type:requests.Session.
class msrest.authentication.BasicTokenAuthentication(token)[source]

Bases: msrest.authentication.Authentication

Simple Token Authentication. Does not adhere to OAuth, simply adds provided token as a header.

Parameters:token (dict) – Authentication token, must have ‘access_token’ key.
set_token()[source]

Should be used to define the self.token attribute.

In this implementation, does nothing since the token is statically provided at creation.

signed_session()[source]

Create requests session with any required auth headers applied.

Return type:requests.Session.
class msrest.authentication.CognitiveServicesCredentials(subscription_key)[source]

Bases: msrest.authentication.ApiKeyCredentials

Cognitive Services authentication.

Parameters:subscription_key (str) – The CS subscription key
class msrest.authentication.OAuthTokenAuthentication(client_id, token)[source]

Bases: msrest.authentication.BasicTokenAuthentication

OAuth Token Authentication. Requires that supplied token contains an expires_in field.

Parameters:
  • client_id (str) – Account Client ID.
  • token (dict) – OAuth2 token.
construct_auth()[source]

Format token header.

Return type:str.
refresh_session()[source]

Return updated session if token has expired, attempts to refresh using refresh token.

Return type:requests.Session.
signed_session()[source]

Create requests session with any required auth headers applied.

Return type:requests.Session.

msrest.configuration module

class msrest.configuration.Configuration(base_url, filepath=None)[source]

Bases: object

Client configuration.

Parameters:
  • baseurl (str) – REST API base URL.
  • filepath (str) – Path to existing config file (optional).
add_user_agent(value)[source]
load(filepath)[source]

Load configuration from existing file.

Parameters:filepath (str) – Path to existing config file.
Raises:ValueError if supplied config file is invalid.
Return type:None
save(filepath)[source]

Save current configuration to file.

Parameters:filepath (str) – Path to file where settings will be saved.
Raises:ValueError if supplied filepath cannot be written to.
Return type:None
user_agent
msrest.configuration.default_session_configuration_callback(session, global_config, local_config, **kwargs)[source]

Configuration callback if you need to change default session configuration.

Parameters:
  • session (requests.Session) – The session.
  • global_config (Configuration) – The global configuration.
  • local_config (dict) – The on-the-fly configuration passed on the call.
  • kwargs (dict) – The current computed values for session.request method.
Returns:

Must return kwargs, to be passed to session.request. If None is return, initial kwargs will be used.

Return type:

dict

msrest.exceptions module

exception msrest.exceptions.AuthenticationError(message, inner_exception=None, *args, **kwargs)[source]

Bases: msrest.exceptions.ClientException

Client request failed to authentication.

exception msrest.exceptions.ClientException(message, inner_exception=None, *args, **kwargs)[source]

Bases: Exception

Base exception for all Client Runtime exceptions.

exception msrest.exceptions.ClientRequestError(message, inner_exception=None, *args, **kwargs)[source]

Bases: msrest.exceptions.ClientException

Client request failed.

exception msrest.exceptions.DeserializationError(message, inner_exception=None, *args, **kwargs)[source]

Bases: msrest.exceptions.ClientException

Error raised during response deserialization.

exception msrest.exceptions.HttpOperationError(deserialize, response, resp_type=None, *args, **kwargs)[source]

Bases: msrest.exceptions.ClientException

Client request failed due to server-specified HTTP operation error. Attempts to deserialize response into specific error object.

Parameters:
  • deserialize (Deserializer) – Deserializer with data on custom error objects.
  • response (requests.Response) – Server response
  • resp_type (str) – Objects type to deserialize response.
  • args – Additional args to pass to exception object.
exception msrest.exceptions.SerializationError(message, inner_exception=None, *args, **kwargs)[source]

Bases: msrest.exceptions.ClientException

Error raised during request serialization.

exception msrest.exceptions.TokenExpiredError(message, inner_exception=None, *args, **kwargs)[source]

Bases: msrest.exceptions.ClientException

OAuth token expired, request failed.

exception msrest.exceptions.ValidationError(rule, target, value, *args, **kwargs)[source]

Bases: msrest.exceptions.ClientException

Request parameter validation failed.

msrest.exceptions.raise_with_traceback(exception, message='', *args, **kwargs)[source]

Raise exception with a specified traceback.

Parameters:
  • exception (Exception) – Error type to be raised.
  • message (str) – Message to include with error, empty by default.
  • args – Any additional args to be included with exception.

msrest.http_logger module

msrest.http_logger.log_request(adapter, request, *args, **kwargs)[source]

Log a client request.

Parameters:
  • adapter (ClientHTTPAdapter) – Adapter making the request.
  • request (requests.Request) – The request object.
msrest.http_logger.log_response(adapter, request, response, *args, **kwargs)[source]

Log a server response.

Parameters:
  • adapter (ClientHTTPAdapter) – Adapter making the request.
  • request (requests.Request) – The request object.
  • response (requests.Response) – The response object.

msrest.paging module

class msrest.paging.Paged(command, classes, raw_headers=None)[source]

Bases: collections.abc.Iterator

A container for paged REST responses.

Parameters:
  • response (requests.Response) – server response object.
  • command (callable) – Function to retrieve the next page of items.
  • classes (dict) – A dictionary of class dependencies for deserialization.
advance_page()[source]
get(url)[source]

Get an arbitrary page.

This resets the iterator and then fully consumes it to return the specific page only.

Parameters:url (str) – URL to arbitrary page results.
next()

Iterate through responses.

raw
reset()[source]

Reset iterator to first page.

msrest.pipeline module

class msrest.pipeline.ClientConnection[source]

Bases: object

Request connection configuration settings.

class msrest.pipeline.ClientProxies[source]

Bases: object

Proxy configuration settings. Proxies can also be configured using HTTP_PROXY and HTTPS_PROXY environment variables, in which case set use_env_settings to True.

add(protocol, proxy_url)[source]

Add proxy.

Parameters:
  • protocol (str) – Protocol for which proxy is to be applied. Can be ‘http’, ‘https’, etc. Can also include host.
  • proxy_url (str) – The proxy URL. Where basic auth is required, use the format: http://user:password@host
class msrest.pipeline.ClientRawResponse(output, response)[source]

Bases: object

Wrapper for response object. This allows for additional data to be gathereded from the response, for example deserialized headers. It also allows the raw response object to be passed back to the user.

Parameters:
  • output – Deserialized response object.
  • response – Raw response object.
add_headers(header_dict)[source]

Deserialize a specific header.

Parameters:header_dict (dict) – A dictionary containing the name of the header and the type to deserialize to.
class msrest.pipeline.ClientRedirectPolicy[source]

Bases: object

Redirect configuration settings.

check_redirect(resp, request)[source]

Whether redirect policy should be applied based on status code.

class msrest.pipeline.ClientRequest(method=None, url=None, headers=None, files=None, data=None, params=None, auth=None, cookies=None, hooks=None, json=None)[source]

Bases: requests.models.Request

Wrapper for requests.Request object.

add_content(data)[source]

Add a body to the request.

Parameters:data – Request body data, can be a json serializable object (e.g. dictionary) or a generator (e.g. file data).
add_header(header, value)[source]

Add a header to the single request.

Parameters:
  • header (str) – The header name.
  • value (str) – The header value.
add_headers(headers)[source]

Add multiple headers to the single request.

Parameters:headers (dict) – A dictionary of headers.
format_parameters(params)[source]

Format parameters into a valid query string. It’s assumed all parameters have already been quoted as valid URL strings.

Parameters:params (dict) – A dictionary of parameters.
class msrest.pipeline.ClientRetryPolicy[source]

Bases: object

Retry configuration settings. Container for retry policy object.

backoff_factor

Factor by which back-off delay is incementally increased.

max_backoff

Max retry back-off delay.

retries

Total number of allowed retries.

safe_codes = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 501, 505]

msrest.serialization module

class msrest.serialization.Deserializer(classes=None)[source]

Bases: object

Response object model deserializer.

Parameters:classes (dict) – Class type dictionary for deserializing complex types.
JSON_MIMETYPES = ['application/json', 'text/json']
basic_types = {<class 'str'>: 'str', <class 'bool'>: 'bool', <class 'float'>: 'float', <class 'int'>: 'int'}
static deserialize_base64(attr)[source]

Deserialize base64 encoded string into string.

Parameters:attr (str) – response string to be deserialized.
Return type:bytearray
Raises:TypeError if string format invalid.
deserialize_basic(attr, data_type)[source]

Deserialize baisc builtin data type from string. Will attempt to convert to str, int, float and bool. This function will also accept ‘1’, ‘0’, ‘true’ and ‘false’ as valid bool values.

Parameters:
  • attr (str) – response string to be deserialized.
  • data_type (str) – deserialization data type.
Return type:

str, int, float or bool

Raises:

TypeError if string format is not valid.

static deserialize_bytearray(attr)[source]

Deserialize string into bytearray.

Parameters:attr (str) – response string to be deserialized.
Return type:bytearray
Raises:TypeError if string format invalid.
deserialize_data(data, data_type)[source]

Process data for deserialization according to data type.

Parameters:
  • data (str) – The response string to be deserialized.
  • data_type (str) – The type to deserialize to.
Raises:

DeserializationError if deserialization fails.

Returns:

Deserialized object.

static deserialize_date(attr)[source]

Deserialize ISO-8601 formatted string into Date object.

Parameters:attr (str) – response string to be deserialized.
Return type:Date
Raises:DeserializationError if string format invalid.
static deserialize_decimal(attr)[source]

Deserialize string into Decimal object.

Parameters:attr (str) – response string to be deserialized.
Return type:Decimal
Raises:DeserializationError if string format invalid.
deserialize_dict(attr, dict_type)[source]

Deserialize a dictionary.

Parameters:
  • attr (dict/list) – Dictionary to be deserialized. Also accepts a list of key, value pairs.
  • dict_type (str) – The object type of the items in the dictionary.
Return type:

dict

static deserialize_duration(attr)[source]

Deserialize ISO-8601 formatted string into TimeDelta object.

Parameters:attr (str) – response string to be deserialized.
Return type:TimeDelta
Raises:DeserializationError if string format invalid.
static deserialize_enum(data, enum_obj)[source]

Deserialize string into enum object.

Parameters:
  • data (str) – response string to be deserialized.
  • enum_obj (Enum) – Enum object to deserialize to.
Return type:

Enum

Raises:

DeserializationError if string is not valid enum value.

static deserialize_iso(attr)[source]

Deserialize ISO-8601 formatted string into Datetime object.

Parameters:attr (str) – response string to be deserialized.
Return type:Datetime
Raises:DeserializationError if string format invalid.
deserialize_iter(attr, iter_type)[source]

Deserialize an iterable.

Parameters:
  • attr (list) – Iterable to be deserialized.
  • iter_type (str) – The type of object in the iterable.
Return type:

list

static deserialize_long(attr)[source]

Deserialize string into long (Py2) or int (Py3).

Parameters:attr (str) – response string to be deserialized.
Return type:long or int
Raises:ValueError if string format invalid.
deserialize_object(attr, **kwargs)[source]

Deserialize a generic object. This will be handled as a dictionary.

Parameters:attr (dict) – Dictionary to be deserialized.
Return type:dict
Raises:TypeError if non-builtin datatype encountered.
static deserialize_rfc(attr)[source]

Deserialize RFC-1123 formatted string into Datetime object.

Parameters:attr (str) – response string to be deserialized.
Return type:Datetime
Raises:DeserializationError if string format invalid.
static deserialize_unicode(data)[source]

Preserve unicode objects in Python 2, otherwise return data as a string.

Parameters:data (str) – response string to be deserialized.
Return type:str or unicode
static deserialize_unix(attr)[source]

Serialize Datetime object into IntTime format. This is represented as seconds.

Parameters:attr (int) – Object to be serialized.
Return type:Datetime
Raises:DeserializationError if format invalid
valid_date = re.compile('\\d{4}[-]\\d{2}[-]\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.?\\d*Z?[-+]?[\\d{2}]?:?[\\d{2}]?')
class msrest.serialization.Model(**kwargs)[source]

Bases: object

Mixin for all client request body/response body models to support serialization and deserialization.

as_dict(keep_readonly=True, key_transformer=<function attribute_transformer>)[source]

Return a dict that can be JSONify using json.dump.

Advanced usage might optionaly use a callback as parameter:

Key is the attribute name used in Python. Attr_desc is a dict of metadata. Currently contains ‘type’ with the msrest type and ‘key’ with the RestAPI encoded key. Value is the current value in this object.

The string returned will be used to serialize the key. If the return type is a list, this is considered hierarchical result dict.

See the three examples in this file:

  • attribute_transformer
  • full_restapi_key_transfomer
  • last_restapi_key_transformer
Parameters:key_transformer (function) – A key transformer function.
Returns:A dict JSON compatible object
Return type:dict
classmethod deserialize(data)[source]

Parse a dict using the RestAPI syntax and return a model.

Parameters:data (dict) – A dict using RestAPI structure
Returns:An instance of this model
Raises:DeserializationError if something went wrong
classmethod enable_additional_properties_sending()[source]
classmethod from_dict(data, key_extractors=None)[source]

Parse a dict using given key extractor return a model.

By default consider key extractors (rest_key_case_insensitive_extractor, attribute_key_case_insensitive_extractor and last_rest_key_case_insensitive_extractor)

Parameters:data (dict) – A dict using RestAPI structure
Returns:An instance of this model
Raises:DeserializationError if something went wrong
serialize(keep_readonly=False)[source]

Return the JSON that would be sent to azure from this model.

This is an alias to as_dict(full_restapi_key_transformer, keep_readonly=False).

Parameters:keep_readonly (bool) – If you want to serialize the readonly attributes
Returns:A dict JSON compatible object
Return type:dict
validate()[source]

Validate this model recursively and return a list of ValidationError.

Returns:A list of validation error
Return type:list
class msrest.serialization.Serializer(classes=None)[source]

Bases: object

Request object model serializer.

basic_types = {<class 'str'>: 'str', <class 'bool'>: 'bool', <class 'float'>: 'float', <class 'int'>: 'int'}
body(data, data_type, **kwargs)[source]

Serialize data intended for a request body.

Parameters:
  • data – The data to be serialized.
  • data_type (str) – The type to be serialized from.
Return type:

dict

Raises:

SerializationError if serialization fails.

Raises:

ValueError if data is None

days = {0: 'Mon', 1: 'Tue', 2: 'Wed', 3: 'Thu', 4: 'Fri', 5: 'Sat', 6: 'Sun'}
header(name, data, data_type, **kwargs)[source]

Serialize data intended for a request header.

Parameters:
  • data – The data to be serialized.
  • data_type (str) – The type to be serialized from.
Return type:

str

Raises:

TypeError if serialization fails.

Raises:

ValueError if data is None

months = {1: 'Jan', 2: 'Feb', 3: 'Mar', 4: 'Apr', 5: 'May', 6: 'Jun', 7: 'Jul', 8: 'Aug', 9: 'Sep', 10: 'Oct', 11: 'Nov', 12: 'Dec'}
query(name, data, data_type, **kwargs)[source]

Serialize data intended for a URL query.

Parameters:
  • data – The data to be serialized.
  • data_type (str) – The type to be serialized from.
Return type:

str

Raises:

TypeError if serialization fails.

Raises:

ValueError if data is None

static serialize_base64(attr, **kwargs)[source]

Serialize str into base-64 string.

Parameters:attr – Object to be serialized.
Return type:str
serialize_basic(data, data_type)[source]

Serialize basic builting data type. Serializes objects to str, int, float or bool.

Parameters:
  • data – Object to be serialized.
  • data_type (str) – Type of object in the iterable.
static serialize_bytearray(attr, **kwargs)[source]

Serialize bytearray into base-64 string.

Parameters:attr – Object to be serialized.
Return type:str
serialize_data(data, data_type, **kwargs)[source]

Serialize generic data according to supplied data type.

Parameters:
  • data – The data to be serialized.
  • data_type (str) – The type to be serialized from.
  • required (bool) – Whether it’s essential that the data not be empty or None
Raises:

AttributeError if required data is None.

Raises:

ValueError if data is None

Raises:

SerializationError if serialization fails.

static serialize_date(attr, **kwargs)[source]

Serialize Date object into ISO-8601 formatted string.

Parameters:attr (Date) – Object to be serialized.
Return type:str
static serialize_decimal(attr, **kwargs)[source]

Serialize Decimal object to float.

Parameters:attr – Object to be serialized.
Return type:float
serialize_dict(attr, dict_type, **kwargs)[source]

Serialize a dictionary of objects.

Parameters:
  • attr (dict) – Object to be serialized.
  • dict_type (str) – Type of object in the dictionary.
  • required (bool) – Whether the objects in the dictionary must not be None or empty.
Return type:

dict

static serialize_duration(attr, **kwargs)[source]

Serialize TimeDelta object into ISO-8601 formatted string.

Parameters:attr (TimeDelta) – Object to be serialized.
Return type:str
static serialize_enum(attr, enum_obj=None)[source]
static serialize_iso(attr, **kwargs)[source]

Serialize Datetime object into ISO-8601 formatted string.

Parameters:attr (Datetime) – Object to be serialized.
Return type:str
Raises:SerializationError if format invalid.
serialize_iter(data, iter_type, div=None, **kwargs)[source]

Serialize iterable.

Parameters:
  • attr (list) – Object to be serialized.
  • iter_type (str) – Type of object in the iterable.
  • required (bool) – Whether the objects in the iterable must not be None or empty.
  • div (str) – If set, this str will be used to combine the elements in the iterable into a combined string. Default is ‘None’.
Return type:

list, str

static serialize_long(attr, **kwargs)[source]

Serialize long (Py2) or int (Py3).

Parameters:attr – Object to be serialized.
Return type:int/long
serialize_object(attr, **kwargs)[source]

Serialize a generic object. This will be handled as a dictionary. If object passed in is not a basic type (str, int, float, dict, list) it will simply be cast to str.

Parameters:attr (dict) – Object to be serialized.
Return type:dict or str
static serialize_rfc(attr, **kwargs)[source]

Serialize Datetime object into RFC-1123 formatted string.

Parameters:attr (Datetime) – Object to be serialized.
Return type:str
Raises:TypeError if format invalid.
serialize_unicode(data)[source]

Special handling for serializing unicode strings in Py2. Encode to UTF-8 if unicode, otherwise handle as a str.

Parameters:data – Object to be serialized.
Return type:str
static serialize_unix(attr, **kwargs)[source]

Serialize Datetime object into IntTime format. This is represented as seconds.

Parameters:attr (Datetime) – Object to be serialized.
Return type:int
Raises:SerializationError if format invalid
url(name, data, data_type, **kwargs)[source]

Serialize data intended for a URL path.

Parameters:
  • data – The data to be serialized.
  • data_type (str) – The type to be serialized from.
Return type:

str

Raises:

TypeError if serialization fails.

Raises:

ValueError if data is None

classmethod validate(data, name, **kwargs)[source]

Validate that a piece of data meets certain conditions

validation = {'multiple': <function Serializer.<lambda>>, 'max_length': <function Serializer.<lambda>>, 'maximum_ex': <function Serializer.<lambda>>, 'minimum': <function Serializer.<lambda>>, 'max_items': <function Serializer.<lambda>>, 'unique': <function Serializer.<lambda>>, 'minimum_ex': <function Serializer.<lambda>>, 'min_items': <function Serializer.<lambda>>, 'min_length': <function Serializer.<lambda>>, 'pattern': <function Serializer.<lambda>>, 'maximum': <function Serializer.<lambda>>}
class msrest.serialization.UTC[source]

Bases: datetime.tzinfo

Time Zone info for handling UTC

dst(dt)[source]

No daylight saving for UTC.

tzname(dt)[source]

Timestamp representation.

utcoffset(dt)[source]

UTF offset for UTC is 0.

msrest.serialization.attribute_key_case_insensitive_extractor(attr, _, data)[source]
msrest.serialization.attribute_key_extractor(attr, _, data)[source]
msrest.serialization.attribute_transformer(key, attr_desc, value)[source]

A key transfomer that returns the Python attribute.

Parameters:
  • key (str) – The attribute name
  • attr_desc (dict) – The attribute metadata
  • value (object) – The value
Returns:

A key using attribute name

msrest.serialization.full_restapi_key_transformer(key, attr_desc, value)[source]

A key transfomer that returns the full RestAPI key path.

Parameters:
  • _ (str) – The attribute name
  • attr_desc (dict) – The attribute metadata
  • value (object) – The value
Returns:

A list of keys using RestAPI syntax.

msrest.serialization.last_rest_key_case_insensitive_extractor(attr, attr_desc, data)[source]
msrest.serialization.last_rest_key_extractor(attr, attr_desc, data)[source]
msrest.serialization.last_restapi_key_transformer(key, attr_desc, value)[source]

A key transfomer that returns the last RestAPI key.

Parameters:
  • _ (str) – The attribute name
  • attr_desc (dict) – The attribute metadata
  • value (object) – The value
Returns:

The last RestAPI key.

msrest.serialization.rest_key_case_insensitive_extractor(attr, attr_desc, data)[source]
msrest.serialization.rest_key_extractor(attr, attr_desc, data)[source]

msrest.service_client module

class msrest.service_client.ServiceClient(creds, config)[source]

Bases: object

REST Service Client. Maintains client pipeline and handles all requests and responses.

Parameters:
add_header(header, value)[source]

Add a persistent header - this header will be applied to all requests sent during the current client session.

Parameters:
  • header (str) – The header name.
  • value (str) – The header value.
delete(url=None, params=None)[source]

Create a DELETE request object.

Parameters:
  • url (str) – The request URL.
  • params (dict) – Request URL parameters.
format_url(url, **kwargs)[source]

Format request URL with the client base URL, unless the supplied URL is already absolute.

Parameters:url (str) – The request URL to be formatted if necessary.
get(url=None, params=None)[source]

Create a GET request object.

Parameters:
  • url (str) – The request URL.
  • params (dict) – Request URL parameters.
head(url=None, params=None)[source]

Create a HEAD request object.

Parameters:
  • url (str) – The request URL.
  • params (dict) – Request URL parameters.
merge(url=None, params=None)[source]

Create a MERGE request object.

Parameters:
  • url (str) – The request URL.
  • params (dict) – Request URL parameters.
patch(url=None, params=None)[source]

Create a PATCH request object.

Parameters:
  • url (str) – The request URL.
  • params (dict) – Request URL parameters.
post(url=None, params=None)[source]

Create a POST request object.

Parameters:
  • url (str) – The request URL.
  • params (dict) – Request URL parameters.
put(url=None, params=None)[source]

Create a PUT request object.

Parameters:
  • url (str) – The request URL.
  • params (dict) – Request URL parameters.
send(request, headers=None, content=None, stream=True, **config)[source]

Prepare and send request object according to configuration.

Parameters:
  • request (ClientRequest) – The request object to be sent.
  • headers (dict) – Any headers to add to the request.
  • content – Any body data to add to the request.
  • stream (bool) – Is the session in stream mode. True by default for compat.
  • config – Any specific config overrides
send_formdata(request, headers=None, content=None, stream=True, **config)[source]

Send data as a multipart form-data request. We only deal with file-like objects or strings at this point. The requests is not yet streamed.

Parameters:
  • request (ClientRequest) – The request object to be sent.
  • headers (dict) – Any headers to add to the request.
  • content (dict) – Dictionary of the fields of the formdata.
  • stream (bool) – Is the session in stream mode. True by default for compat.
  • config – Any specific config overrides.
stream_download(data, callback)[source]

Generator for streaming request body data.

Parameters:
  • data – A response object to be streamed.
  • callback – Custom callback for monitoring progress.
stream_upload(data, callback)[source]

Generator for streaming request body data.

Parameters:
  • data – A file-like object to be streamed.
  • callback – Custom callback for monitoring progress.

msrest.version module

Module contents

class msrest.ServiceClient(creds, config)[source]

Bases: object

REST Service Client. Maintains client pipeline and handles all requests and responses.

Parameters:
add_header(header, value)[source]

Add a persistent header - this header will be applied to all requests sent during the current client session.

Parameters:
  • header (str) – The header name.
  • value (str) – The header value.
delete(url=None, params=None)[source]

Create a DELETE request object.

Parameters:
  • url (str) – The request URL.
  • params (dict) – Request URL parameters.
format_url(url, **kwargs)[source]

Format request URL with the client base URL, unless the supplied URL is already absolute.

Parameters:url (str) – The request URL to be formatted if necessary.
get(url=None, params=None)[source]

Create a GET request object.

Parameters:
  • url (str) – The request URL.
  • params (dict) – Request URL parameters.
head(url=None, params=None)[source]

Create a HEAD request object.

Parameters:
  • url (str) – The request URL.
  • params (dict) – Request URL parameters.
merge(url=None, params=None)[source]

Create a MERGE request object.

Parameters:
  • url (str) – The request URL.
  • params (dict) – Request URL parameters.
patch(url=None, params=None)[source]

Create a PATCH request object.

Parameters:
  • url (str) – The request URL.
  • params (dict) – Request URL parameters.
post(url=None, params=None)[source]

Create a POST request object.

Parameters:
  • url (str) – The request URL.
  • params (dict) – Request URL parameters.
put(url=None, params=None)[source]

Create a PUT request object.

Parameters:
  • url (str) – The request URL.
  • params (dict) – Request URL parameters.
send(request, headers=None, content=None, stream=True, **config)[source]

Prepare and send request object according to configuration.

Parameters:
  • request (ClientRequest) – The request object to be sent.
  • headers (dict) – Any headers to add to the request.
  • content – Any body data to add to the request.
  • stream (bool) – Is the session in stream mode. True by default for compat.
  • config – Any specific config overrides
send_formdata(request, headers=None, content=None, stream=True, **config)[source]

Send data as a multipart form-data request. We only deal with file-like objects or strings at this point. The requests is not yet streamed.

Parameters:
  • request (ClientRequest) – The request object to be sent.
  • headers (dict) – Any headers to add to the request.
  • content (dict) – Dictionary of the fields of the formdata.
  • stream (bool) – Is the session in stream mode. True by default for compat.
  • config – Any specific config overrides.
stream_download(data, callback)[source]

Generator for streaming request body data.

Parameters:
  • data – A response object to be streamed.
  • callback – Custom callback for monitoring progress.
stream_upload(data, callback)[source]

Generator for streaming request body data.

Parameters:
  • data – A file-like object to be streamed.
  • callback – Custom callback for monitoring progress.
class msrest.Serializer(classes=None)[source]

Bases: object

Request object model serializer.

basic_types = {<class 'str'>: 'str', <class 'bool'>: 'bool', <class 'float'>: 'float', <class 'int'>: 'int'}
body(data, data_type, **kwargs)[source]

Serialize data intended for a request body.

Parameters:
  • data – The data to be serialized.
  • data_type (str) – The type to be serialized from.
Return type:

dict

Raises:

SerializationError if serialization fails.

Raises:

ValueError if data is None

days = {0: 'Mon', 1: 'Tue', 2: 'Wed', 3: 'Thu', 4: 'Fri', 5: 'Sat', 6: 'Sun'}
header(name, data, data_type, **kwargs)[source]

Serialize data intended for a request header.

Parameters:
  • data – The data to be serialized.
  • data_type (str) – The type to be serialized from.
Return type:

str

Raises:

TypeError if serialization fails.

Raises:

ValueError if data is None

months = {1: 'Jan', 2: 'Feb', 3: 'Mar', 4: 'Apr', 5: 'May', 6: 'Jun', 7: 'Jul', 8: 'Aug', 9: 'Sep', 10: 'Oct', 11: 'Nov', 12: 'Dec'}
query(name, data, data_type, **kwargs)[source]

Serialize data intended for a URL query.

Parameters:
  • data – The data to be serialized.
  • data_type (str) – The type to be serialized from.
Return type:

str

Raises:

TypeError if serialization fails.

Raises:

ValueError if data is None

static serialize_base64(attr, **kwargs)[source]

Serialize str into base-64 string.

Parameters:attr – Object to be serialized.
Return type:str
serialize_basic(data, data_type)[source]

Serialize basic builting data type. Serializes objects to str, int, float or bool.

Parameters:
  • data – Object to be serialized.
  • data_type (str) – Type of object in the iterable.
static serialize_bytearray(attr, **kwargs)[source]

Serialize bytearray into base-64 string.

Parameters:attr – Object to be serialized.
Return type:str
serialize_data(data, data_type, **kwargs)[source]

Serialize generic data according to supplied data type.

Parameters:
  • data – The data to be serialized.
  • data_type (str) – The type to be serialized from.
  • required (bool) – Whether it’s essential that the data not be empty or None
Raises:

AttributeError if required data is None.

Raises:

ValueError if data is None

Raises:

SerializationError if serialization fails.

static serialize_date(attr, **kwargs)[source]

Serialize Date object into ISO-8601 formatted string.

Parameters:attr (Date) – Object to be serialized.
Return type:str
static serialize_decimal(attr, **kwargs)[source]

Serialize Decimal object to float.

Parameters:attr – Object to be serialized.
Return type:float
serialize_dict(attr, dict_type, **kwargs)[source]

Serialize a dictionary of objects.

Parameters:
  • attr (dict) – Object to be serialized.
  • dict_type (str) – Type of object in the dictionary.
  • required (bool) – Whether the objects in the dictionary must not be None or empty.
Return type:

dict

static serialize_duration(attr, **kwargs)[source]

Serialize TimeDelta object into ISO-8601 formatted string.

Parameters:attr (TimeDelta) – Object to be serialized.
Return type:str
static serialize_enum(attr, enum_obj=None)[source]
static serialize_iso(attr, **kwargs)[source]

Serialize Datetime object into ISO-8601 formatted string.

Parameters:attr (Datetime) – Object to be serialized.
Return type:str
Raises:SerializationError if format invalid.
serialize_iter(data, iter_type, div=None, **kwargs)[source]

Serialize iterable.

Parameters:
  • attr (list) – Object to be serialized.
  • iter_type (str) – Type of object in the iterable.
  • required (bool) – Whether the objects in the iterable must not be None or empty.
  • div (str) – If set, this str will be used to combine the elements in the iterable into a combined string. Default is ‘None’.
Return type:

list, str

static serialize_long(attr, **kwargs)[source]

Serialize long (Py2) or int (Py3).

Parameters:attr – Object to be serialized.
Return type:int/long
serialize_object(attr, **kwargs)[source]

Serialize a generic object. This will be handled as a dictionary. If object passed in is not a basic type (str, int, float, dict, list) it will simply be cast to str.

Parameters:attr (dict) – Object to be serialized.
Return type:dict or str
static serialize_rfc(attr, **kwargs)[source]

Serialize Datetime object into RFC-1123 formatted string.

Parameters:attr (Datetime) – Object to be serialized.
Return type:str
Raises:TypeError if format invalid.
serialize_unicode(data)[source]

Special handling for serializing unicode strings in Py2. Encode to UTF-8 if unicode, otherwise handle as a str.

Parameters:data – Object to be serialized.
Return type:str
static serialize_unix(attr, **kwargs)[source]

Serialize Datetime object into IntTime format. This is represented as seconds.

Parameters:attr (Datetime) – Object to be serialized.
Return type:int
Raises:SerializationError if format invalid
url(name, data, data_type, **kwargs)[source]

Serialize data intended for a URL path.

Parameters:
  • data – The data to be serialized.
  • data_type (str) – The type to be serialized from.
Return type:

str

Raises:

TypeError if serialization fails.

Raises:

ValueError if data is None

classmethod validate(data, name, **kwargs)[source]

Validate that a piece of data meets certain conditions

validation = {'multiple': <function Serializer.<lambda>>, 'max_length': <function Serializer.<lambda>>, 'maximum_ex': <function Serializer.<lambda>>, 'minimum': <function Serializer.<lambda>>, 'max_items': <function Serializer.<lambda>>, 'unique': <function Serializer.<lambda>>, 'minimum_ex': <function Serializer.<lambda>>, 'min_items': <function Serializer.<lambda>>, 'min_length': <function Serializer.<lambda>>, 'pattern': <function Serializer.<lambda>>, 'maximum': <function Serializer.<lambda>>}
class msrest.Deserializer(classes=None)[source]

Bases: object

Response object model deserializer.

Parameters:classes (dict) – Class type dictionary for deserializing complex types.
JSON_MIMETYPES = ['application/json', 'text/json']
basic_types = {<class 'str'>: 'str', <class 'bool'>: 'bool', <class 'float'>: 'float', <class 'int'>: 'int'}
static deserialize_base64(attr)[source]

Deserialize base64 encoded string into string.

Parameters:attr (str) – response string to be deserialized.
Return type:bytearray
Raises:TypeError if string format invalid.
deserialize_basic(attr, data_type)[source]

Deserialize baisc builtin data type from string. Will attempt to convert to str, int, float and bool. This function will also accept ‘1’, ‘0’, ‘true’ and ‘false’ as valid bool values.

Parameters:
  • attr (str) – response string to be deserialized.
  • data_type (str) – deserialization data type.
Return type:

str, int, float or bool

Raises:

TypeError if string format is not valid.

static deserialize_bytearray(attr)[source]

Deserialize string into bytearray.

Parameters:attr (str) – response string to be deserialized.
Return type:bytearray
Raises:TypeError if string format invalid.
deserialize_data(data, data_type)[source]

Process data for deserialization according to data type.

Parameters:
  • data (str) – The response string to be deserialized.
  • data_type (str) – The type to deserialize to.
Raises:

DeserializationError if deserialization fails.

Returns:

Deserialized object.

static deserialize_date(attr)[source]

Deserialize ISO-8601 formatted string into Date object.

Parameters:attr (str) – response string to be deserialized.
Return type:Date
Raises:DeserializationError if string format invalid.
static deserialize_decimal(attr)[source]

Deserialize string into Decimal object.

Parameters:attr (str) – response string to be deserialized.
Return type:Decimal
Raises:DeserializationError if string format invalid.
deserialize_dict(attr, dict_type)[source]

Deserialize a dictionary.

Parameters:
  • attr (dict/list) – Dictionary to be deserialized. Also accepts a list of key, value pairs.
  • dict_type (str) – The object type of the items in the dictionary.
Return type:

dict

static deserialize_duration(attr)[source]

Deserialize ISO-8601 formatted string into TimeDelta object.

Parameters:attr (str) – response string to be deserialized.
Return type:TimeDelta
Raises:DeserializationError if string format invalid.
static deserialize_enum(data, enum_obj)[source]

Deserialize string into enum object.

Parameters:
  • data (str) – response string to be deserialized.
  • enum_obj (Enum) – Enum object to deserialize to.
Return type:

Enum

Raises:

DeserializationError if string is not valid enum value.

static deserialize_iso(attr)[source]

Deserialize ISO-8601 formatted string into Datetime object.

Parameters:attr (str) – response string to be deserialized.
Return type:Datetime
Raises:DeserializationError if string format invalid.
deserialize_iter(attr, iter_type)[source]

Deserialize an iterable.

Parameters:
  • attr (list) – Iterable to be deserialized.
  • iter_type (str) – The type of object in the iterable.
Return type:

list

static deserialize_long(attr)[source]

Deserialize string into long (Py2) or int (Py3).

Parameters:attr (str) – response string to be deserialized.
Return type:long or int
Raises:ValueError if string format invalid.
deserialize_object(attr, **kwargs)[source]

Deserialize a generic object. This will be handled as a dictionary.

Parameters:attr (dict) – Dictionary to be deserialized.
Return type:dict
Raises:TypeError if non-builtin datatype encountered.
static deserialize_rfc(attr)[source]

Deserialize RFC-1123 formatted string into Datetime object.

Parameters:attr (str) – response string to be deserialized.
Return type:Datetime
Raises:DeserializationError if string format invalid.
static deserialize_unicode(data)[source]

Preserve unicode objects in Python 2, otherwise return data as a string.

Parameters:data (str) – response string to be deserialized.
Return type:str or unicode
static deserialize_unix(attr)[source]

Serialize Datetime object into IntTime format. This is represented as seconds.

Parameters:attr (int) – Object to be serialized.
Return type:Datetime
Raises:DeserializationError if format invalid
valid_date = re.compile('\\d{4}[-]\\d{2}[-]\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.?\\d*Z?[-+]?[\\d{2}]?:?[\\d{2}]?')
class msrest.Configuration(base_url, filepath=None)[source]

Bases: object

Client configuration.

Parameters:
  • baseurl (str) – REST API base URL.
  • filepath (str) – Path to existing config file (optional).
add_user_agent(value)[source]
load(filepath)[source]

Load configuration from existing file.

Parameters:filepath (str) – Path to existing config file.
Raises:ValueError if supplied config file is invalid.
Return type:None
save(filepath)[source]

Save current configuration to file.

Parameters:filepath (str) – Path to file where settings will be saved.
Raises:ValueError if supplied filepath cannot be written to.
Return type:None
user_agent