{"id":534,"library":"msrest","title":"msrest","description":"msrest is the Python client runtime library for AutoRest-generated Python SDKs, primarily used within the Azure SDK ecosystem. It provides functionalities for serialization, deserialization, and HTTP communication, enabling Python clients to interact with REST APIs defined by Swagger/OpenAPI specifications. The current version is 0.7.1, with the latest release being June 2022. The library is now deprecated and will not receive further updates, with its functionalities moved to `azure-identity` and `azure-core`, or vendored directly into SDKs.","status":"deprecated","version":"0.7.1","language":"python","source_language":"en","source_url":"https://github.com/Azure/msrest-for-python","tags":["azure","rest","swagger","codegen","client-runtime","serialization","deserialization","http-client"],"install":[{"cmd":"pip install msrest","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Used internally for HTTP requests.","package":"requests","optional":false},{"reason":"Required for ISO 8601 date/time parsing and formatting during serialization/deserialization.","package":"isodate","optional":false},{"reason":"Required since 0.7.0; common HTTP pipeline components and exception types (e.g., SerializationError, DeserializationError) were moved here.","package":"azure-core","optional":false}],"imports":[{"note":"Core client for making REST calls.","symbol":"ServiceClient","correct":"from msrest import ServiceClient"},{"note":"Used to convert Python objects to API-compatible formats.","symbol":"Serializer","correct":"from msrest.serialization import Serializer"},{"note":"Used to convert API responses into Python objects.","symbol":"Deserializer","correct":"from msrest.serialization import Deserializer"},{"note":"Common exception for HTTP operation failures.","symbol":"HttpOperationError","correct":"from msrest.exceptions import HttpOperationError"},{"note":"Moved to `azure.core.exceptions` in msrest 0.7.0.","wrong":"from msrest.exceptions import SerializationError","symbol":"SerializationError","correct":"from azure.core.exceptions import SerializationError"},{"note":"Moved to `azure.core.exceptions` in msrest 0.7.0.","wrong":"from msrest.exceptions import DeserializationError","symbol":"DeserializationError","correct":"from azure.core.exceptions import DeserializationError"}],"quickstart":{"code":"import json\nimport datetime\nimport isodate # Needed for deserialized datetime object type checking\nfrom msrest.serialization import Serializer, Deserializer\n\n# Define a simple model schema for demonstration\nmodels = {\n    'MyModel': {\n        'type': 'object',\n        'properties': {\n            'id': {'type': 'integer', 'format': 'int32'},\n            'name': {'type': 'string'},\n            'created_at': {'type': 'string', 'format': 'date-time'}\n        },\n        'required': ['id', 'name']\n    }\n}\n\n# Initialize Serializer and Deserializer with defined models\nserializer = Serializer(models)\ndeserializer = Deserializer(models)\n\n# Create a Python object to be serialized\nclass MyModel:\n    def __init__(self, id, name, created_at=None):\n        self.id = id\n        self.name = name\n        self.created_at = created_at\n\ninstance_to_serialize = MyModel(\n    id=1,\n    name='Example Item',\n    created_at=datetime.datetime.now(datetime.timezone.utc)\n)\n\n# Serialize the object to a format suitable for a REST API call\n# The 'MyModel' string refers to the schema key defined in 'models'\nserialized_data = serializer.body(instance_to_serialize, 'MyModel')\nprint(\"Serialized data:\", json.dumps(serialized_data, indent=2))\n\n# Simulate a raw JSON response from a REST API\nraw_json_response = {\n    \"id\": 2,\n    \"name\": \"Another Example\",\n    \"created_at\": \"2023-10-27T10:30:00Z\"\n}\n\n# Deserialize the raw JSON response into a Python object\ndeserialized_instance = deserializer(MyModel, raw_json_response)\nprint(f\"\\nDeserialized name: {deserialized_instance.name}\")\nprint(f\"Deserialized created_at: {deserialized_instance.created_at}\")\nprint(f\"Type of deserialized created_at: {type(deserialized_instance.created_at)}\")\n","lang":"python","description":"This example demonstrates how to use `msrest.serialization.Serializer` and `msrest.serialization.Deserializer` to convert Python objects to and from JSON structures based on a defined model schema. It shows how to initialize these components, serialize an object with a datetime field, and then deserialize a mock API response back into a Python object."},"warnings":[{"fix":"For new projects or migrations, prefer using `azure-identity` for authentication and `azure-core` for common client infrastructure. For serialization, rely on the specific SDK's vendored logic or custom serializers where `msrest` is not a direct dependency.","message":"The `msrest` library is officially deprecated and no longer receives updates. Its functionalities have been moved to `azure-identity` for authentication and `azure-core` or are vendored directly into newer Azure SDKs. It will soon be archived.","severity":"deprecated","affected_versions":">=0.7.1"},{"fix":"Update import statements for these exceptions from `from msrest.exceptions import ...` to `from azure.core.exceptions import ...`.","message":"In `msrest` version 0.7.0, `SerializationError` and `DeserializationError` classes were moved from `msrest.exceptions` to `azure.core.exceptions`.","severity":"breaking","affected_versions":">=0.7.0"},{"fix":"Always use timezone-aware `datetime` objects (e.g., `datetime.datetime.now(datetime.timezone.utc)`). Ensure incoming datetime strings from APIs are in a standard format (ISO 8601 is preferred). If custom formats are necessary, manual pre-processing might be needed.","message":"DateTime objects, especially timezone-naive ones, can cause serialization or deserialization issues. `msrest` expects RFC1123 or ISO 8601 formatted strings and prefers timezone-aware datetime objects for serialization.","severity":"gotcha","affected_versions":"<0.7.0 (bug fixes in 0.6.20/0.6.21 for certain datetime types), all versions (general handling)"},{"fix":"Consolidate SDK versions where possible. If conflicts arise, consider upgrading to SDK versions that explicitly remove `msrest` as a dependency or align `msrest` versions across your project. In some cases, using `pip install --no-deps` for `msrest` and managing its core dependencies might be a workaround, but is not recommended.","message":"Mixing different versions of Azure SDKs that have varying `msrest` dependencies can lead to `pip` dependency resolution conflicts. Some newer SDKs have removed `msrest` as a direct dependency or require specific versions.","severity":"gotcha","affected_versions":"All versions, especially when used in complex dependency trees"},{"fix":"When calling `serializer.body(data, data_type)`, ensure that `data_type` is either the actual Python class object (e.g., `MyModel`) or a string representation (e.g., `'MyModel'`) only if the `msrest.serialization.Deserializer` or `Serializer` instance has been explicitly initialized with a `_models` dictionary that maps the string name to the corresponding class (e.g., `serializer = Deserializer(models={'MyModel': MyModel})`). If the intent is to serialize XML, ensure `is_xml=True` is passed as a keyword argument.","message":"msrest.serialization.body can raise `TypeError: issubclass() arg 1 must be a class` if the `data_type` argument is not a valid class object or a string name that the serializer can resolve to a class via its known models. This often happens if the serializer's `_models` dictionary is not correctly populated or if an unresolvable string is passed. Additionally, it might encounter `KeyError: 'is_xml'` if an internal XML serialization path is triggered without the necessary `is_xml` keyword argument.","severity":"breaking","affected_versions":"all versions"},{"fix":"Ensure that any string `data_type` passed to `serializer.body` (or similar methods) corresponds to a class that has been correctly registered with the `msrest.serialization.Serializer` instance. If `data_type` is intended to be a Python class directly, pass the class object itself, not its name as a string. As `msrest` is deprecated, for new projects or migrations, prefer using `azure-identity` for authentication and `azure-core` for common client infrastructure, relying on specific SDK's vendored logic for serialization.","message":"`msrest.serialization.Serializer.body` can fail with `TypeError: issubclass() arg 1 must be a class` when the `data_type` argument (if a string) does not correctly resolve to a registered model class. This indicates an issue with how models are defined or added to the serializer's `_models` collection, or a potential incompatibility/edge case in `msrest`'s internal type resolution logic, especially with newer Python versions (e.g., Python 3.13) where `msrest` is no longer actively maintained.","severity":"breaking","affected_versions":"All versions, particularly when used in newer Python environments (e.g., Python 3.13) or with improperly registered models."}],"env_vars":null,"last_verified":"2026-05-12T14:44:36.607Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"Install 'msrest' using pip: `pip install msrest` or `pip install 'azure-mgmt-resourcegraph'` (or the specific Azure SDK package requiring it) to ensure all dependencies are met.","cause":"This error occurs when the 'msrest' package is not installed in the Python environment, or when a dependent package (like older Azure SDKs or Ansible collections) fails to correctly install it as a dependency.","error":"ModuleNotFoundError: No module named 'msrest'"},{"fix":"Install 'msrestazure' using pip: `pip install msrestazure`.","cause":"This error indicates that the 'msrestazure' package, often used for Azure-specific authentication and resource management functionalities with AutoRest-generated clients, is missing from the Python environment.","error":"ModuleNotFoundError: No module named 'msrestazure'"},{"fix":"Inspect the raw HTTP response content to understand its structure. Compare it against the expected model definition in the SDK. If the API has changed, update the SDK version or adjust your code to handle the new response format. If the issue persists, manually deserialize the problematic part or consider using `azure-core`'s updated serialization.","cause":"These errors typically occur during deserialization when the actual data received from a REST API does not match the expected data model or schema defined for the Python client. This can be due to API changes, incorrect data types, or malformed JSON/XML responses.","error":"msrest.exceptions.DeserializationError: Unable to deserialize to object: type, KeyError: 'key: int; value: str' OR AttributeError: 'str' object has no attribute 'get' (or '_attribute_map')"},{"fix":"Replace `msrest.authentication.BasicTokenAuthentication` with credentials from the `azure-identity` library, such as `DefaultAzureCredential` or `ManagedIdentityCredential`, which provide the `get_token` method. Wrap the `azure-identity` credential if the client still explicitly expects a `msrest.authentication` object using a compatibility wrapper.","cause":"This error arises when code expects an authentication object to have a `get_token` method (common in newer Azure SDKs that use `azure-identity`), but is instead provided with an older `msrest.authentication.BasicTokenAuthentication` object, which lacks this method. This is a common symptom during migration from older `msrest`-based authentication to `azure-identity`.","error":"AttributeError: 'BasicTokenAuthentication' object has no attribute 'get_token'"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":0,"quickstart_tag":"stale","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.38,"mem_mb":18,"disk_size":"25.5M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.83,"mem_mb":18,"disk_size":"26M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.8,"mem_mb":19.4,"disk_size":"28.0M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.02,"mem_mb":19.4,"disk_size":"29M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.49,"mem_mb":19.5,"disk_size":"19.7M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.02,"mem_mb":19.5,"disk_size":"20M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.21,"mem_mb":19.9,"disk_size":"19.3M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.4,"mem_mb":19.9,"disk_size":"20M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.24,"mem_mb":17.4,"disk_size":"24.7M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.05,"mem_mb":17.4,"disk_size":"25M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}}