or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

authentication.mdconfiguration.mdexceptions.mdindex.mdpaging.mdpipeline.mdpolling.mdserialization.mdservice-client.md
tile.json

tessl/pypi-msrest

AutoRest swagger generator Python client runtime for REST API clients with serialization, authentication, and request handling.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/msrest@0.7.x

To install, run

npx @tessl/cli install tessl/pypi-msrest@0.7.0

index.mddocs/

MSRest

Microsoft AutoRest Swagger generator Python client runtime that provides comprehensive support for building REST API clients from OpenAPI/Swagger specifications. It offers serialization and deserialization capabilities, authentication mechanisms, paging support for large result sets, long-running operation (LRO) polling with retry strategies, and comprehensive error handling with configurable HTTP pipelines.

Package Information

  • Package Name: msrest
  • Language: Python
  • Installation: pip install msrest

Core Imports

from msrest import ServiceClient, Configuration
from msrest import Serializer, Deserializer

For authentication:

from msrest.authentication import BasicAuthentication, ApiKeyCredentials

For version information:

from msrest import __version__
print(__version__)  # "0.7.1"

# Alternative access
import msrest
print(msrest.__version__)  # "0.7.1"

Basic Usage

from msrest import ServiceClient, Configuration
from msrest.authentication import BasicAuthentication

# Configure client
config = Configuration(base_url='https://api.example.com')
auth = BasicAuthentication('username', 'password')
config.credentials = auth

# Create service client
with ServiceClient(None, config) as client:
    # Create and send HTTP request
    request = client.get('/users')
    response = client.send(request)
    
    # Process response
    print(response.status_code)
    print(response.text)

Architecture

MSRest implements a layered architecture designed for maximum reusability across Azure SDK clients and other REST API consumers:

  • Service Client Layer: High-level client interface with HTTP verb methods (GET, POST, etc.)
  • Pipeline System: Configurable request/response processing with policies for authentication, logging, and custom behavior
  • Universal HTTP Layer: Abstraction over HTTP libraries (requests, aiohttp) enabling both sync and async operations
  • Serialization Layer: Handles conversion between Python objects and REST API formats (JSON/XML)
  • Authentication Layer: Pluggable authentication mechanisms supporting OAuth, API keys, basic auth, and custom schemes

This design enables easy customization while maintaining compatibility across different API requirements and provides built-in support for Azure service patterns like long-running operations and result paging.

Capabilities

Service Client

Core REST client functionality providing HTTP request creation, pipeline processing, URL formatting, streaming support, and context management for session lifecycle.

class ServiceClient:
    def __init__(self, creds, config: Configuration): ...
    def get(self, url: str, params=None, headers=None, content=None, form_content=None): ...
    def post(self, url: str, params=None, headers=None, content=None, form_content=None): ...
    def put(self, url: str, params=None, headers=None, content=None, form_content=None): ...
    def delete(self, url: str, params=None, headers=None, content=None, form_content=None): ...
    def send(self, request, headers=None, content=None, **kwargs): ...

Service Client

Configuration

Client configuration management including base URL settings, authentication credentials, HTTP policies, pipeline configuration, and connection parameters.

class Configuration:
    def __init__(self, base_url: str, filepath=None): ...
    def add_user_agent(self, value: str): ...
    @property
    def user_agent(self) -> str: ...
    @property
    def enable_http_logger(self) -> bool: ...

Configuration

Authentication

Comprehensive authentication system supporting multiple authentication schemes including Basic, Bearer token, OAuth2, API keys, Kerberos, and Azure service-specific credentials.

class Authentication:
    def signed_session(self, session=None): ...

class BasicAuthentication(Authentication):
    def __init__(self, username: str, password: str): ...

class ApiKeyCredentials(Authentication):
    def __init__(self, in_headers=None, in_query=None): ...

Authentication

Serialization

Robust serialization and deserialization system supporting complex data types, XML/JSON formats, date/time handling, custom model classes, and comprehensive validation.

class Serializer:
    def __init__(self, classes=None): ...
    def body(self, data, data_type: str, **kwargs): ...
    def url(self, name: str, data, data_type: str, **kwargs) -> str: ...
    def query(self, name: str, data, data_type: str, **kwargs) -> str: ...

class Deserializer:
    def __init__(self, classes=None): ...
    def __call__(self, target_obj: str, response_data, content_type=None): ...

Serialization

Paging

Iterator-based paging support for REST APIs that return large result sets, providing automatic page traversal, reset capability, and raw response access.

class Paged:
    def __init__(self, command, classes, raw_headers=None, **kwargs): ...
    def advance_page(self): ...
    def reset(self): ...
    def get(self, url: str): ...
    @property
    def raw(self): ...

Paging

Long-Running Operations

Polling system for long-running operations with configurable retry strategies, timeout handling, and completion detection for Azure ARM and other async API patterns.

class LROPoller:
    def result(self, timeout=None): ...
    def wait(self, timeout=None): ...
    def done(self) -> bool: ...
    def add_done_callback(self, func): ...

class PollingMethod:
    def initialize(self, client, initial_response, deserialization_callback): ...
    def run(self) -> bool: ...

Long-Running Operations

Pipeline System

Configurable HTTP request/response pipeline with policy-based architecture supporting custom middleware, authentication injection, logging, and retry logic.

class Pipeline:
    def __init__(self, policies=None, sender=None): ...
    def run(self, request, **kwargs): ...

class HTTPPolicy:
    def send(self, request, **kwargs): ...

class SansIOHTTPPolicy:
    def on_request(self, request, **kwargs): ...
    def on_response(self, request, response, **kwargs): ...

Pipeline System

Exception Handling

Comprehensive error handling with specialized exception types for validation errors, HTTP operation failures, authentication issues, and client request problems.

class ClientException(Exception): ...
class ValidationError(ClientException): ...
class HttpOperationError(ClientException): ...
class AuthenticationError(ClientException): ...
class TokenExpiredError(ClientException): ...

Exception Handling

Types

Core type definitions used across the MSRest API.

class SDKClient:
    def __init__(self, creds, config: Configuration): ...
    def close(self): ...

# Model class from msrest.serialization
class Model:
    def validate(self): ...
    def serialize(self, keep_readonly=False, **kwargs): ...
    def as_dict(self, keep_readonly=True, key_transformer=None, **kwargs): ...
    @classmethod
    def deserialize(cls, data, content_type=None): ...
    @classmethod
    def from_dict(cls, data, key_extractors=None, content_type=None): ...

# Version information
__version__: str  # Package version string (e.g., "0.7.1")
msrest_version: str  # Alias for __version__