AutoRest swagger generator Python client runtime for REST API clients with serialization, authentication, and request handling.
npx @tessl/cli install tessl/pypi-msrest@0.7.0Microsoft 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.
pip install msrestfrom msrest import ServiceClient, Configuration
from msrest import Serializer, DeserializerFor authentication:
from msrest.authentication import BasicAuthentication, ApiKeyCredentialsFor version information:
from msrest import __version__
print(__version__) # "0.7.1"
# Alternative access
import msrest
print(msrest.__version__) # "0.7.1"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)MSRest implements a layered architecture designed for maximum reusability across Azure SDK clients and other REST API consumers:
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.
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): ...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: ...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): ...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): ...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): ...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: ...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): ...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): ...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__