{"id":2134,"library":"mypy-boto3-xray","title":"mypy-boto3-xray","description":"mypy-boto3-xray provides type annotations (stubs) for the `boto3` AWS SDK specifically for the XRay service. It enables static type checking with tools like MyPy, improving code quality and catching errors early when working with AWS XRay. The current version is 1.42.3, which is built with `mypy-boto3-builder` version 8.12.0, and new versions are released frequently to keep pace with `boto3` updates.","status":"active","version":"1.42.3","language":"en","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["mypy","boto3","aws","type-hints","xray","stubs"],"install":[{"cmd":"pip install boto3 mypy-boto3-xray","lang":"bash","label":"Install boto3 and stubs"}],"dependencies":[{"reason":"This package provides type stubs for boto3; boto3 itself must be installed to run the code.","package":"boto3","optional":false}],"imports":[{"symbol":"XRayClient","correct":"from mypy_boto3_xray.client import XRayClient"},{"symbol":"GetTraceSummariesResponseTypeDef","correct":"from mypy_boto3_xray.type_defs import GetTraceSummariesResponseTypeDef"}],"quickstart":{"code":"import boto3\nfrom mypy_boto3_xray.client import XRayClient\nfrom mypy_boto3_xray.type_defs import GetTraceSummariesResponseTypeDef\nfrom datetime import datetime, timedelta\n\n# mypy-boto3-xray provides type hints for boto3, \n# so boto3 itself must be installed and used.\nclient: XRayClient = boto3.client(\"xray\")\n\nend_time = datetime.now()\nstart_time = end_time - timedelta(hours=1)\n\ntry:\n    response: GetTraceSummariesResponseTypeDef = client.get_trace_summaries(\n        StartTime=start_time,\n        EndTime=end_time,\n        SamplingStrategy={\n            \"StrategyName\": \"PartialScan\",\n            \"Value\": 5.0\n        }\n    )\n\n    print(f\"Traces found: {len(response.get('TraceSummaries', []))}\")\n    if response.get('TraceSummaries'):\n        for trace in response['TraceSummaries']:\n            print(f\"  Trace ID: {trace['Id']}, Duration: {trace.get('Duration')}\")\nexcept client.exceptions.InvalidRequestException as e:\n    print(f\"Error fetching traces: {e}. Check your AWS region and permissions.\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")","lang":"python","description":"Demonstrates how to use `mypy-boto3-xray` to add type hints to a `boto3` XRay client, allowing static analysis to verify method calls and response structures."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or a later version. If you must use Python 3.8, pin to an older `mypy-boto3-xray` version (e.g., `<1.42.0`).","message":"Starting with `mypy-boto3-builder` 8.12.0 (which generated `mypy-boto3-xray` 1.42.x), support for Python 3.8 has been removed across all packages. Ensure your project uses Python 3.9 or newer.","severity":"breaking","affected_versions":">=1.42.0"},{"fix":"Always install `boto3` alongside `mypy-boto3-xray` in your project dependencies.","message":"`mypy-boto3-xray` provides *only type stubs* for static analysis. It does not include the `boto3` runtime itself. You must explicitly install `boto3` (e.g., `pip install boto3`) for your code to execute.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure your type checker (e.g., MyPy) is up-to-date and correctly configured to resolve PEP 561-compliant stub packages. Most standard setups should work without modification.","message":"Starting with `mypy-boto3-builder` 8.12.0, all packages (including `mypy-boto3-xray`) migrated to PEP 561 namespace packages. While this is primarily an internal change, it might affect custom build systems or type checker configurations that rely on specific package structures.","severity":"breaking","affected_versions":">=1.42.0"},{"fix":"If upgrading from very old versions, review your code for TypeDef imports and adjust names according to the new conventions as indicated by your type checker.","message":"In `mypy-boto3-builder` 8.9.0, there were breaking changes to TypeDef naming conventions (e.g., `CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`). While not specific to XRay, be aware that similar changes could occur for other services.","severity":"breaking","affected_versions":">=1.40.0"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}