{"id":1575,"library":"mypy-boto3-secretsmanager","title":"mypy-boto3-secretsmanager Type Stubs","description":"mypy-boto3-secretsmanager provides type annotations (stub files) for the boto3 AWS Secrets Manager service, enhancing static analysis and IDE autocompletion for Python projects. It is part of the larger `mypy-boto3` family, generated by `mypy-boto3-builder`. The package version (currently 1.42.8) typically aligns with the underlying `boto3` and `botocore` versions it provides stubs for. New versions are released frequently, reflecting updates in AWS services and `boto3` itself.","status":"active","version":"1.42.8","language":"en","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["boto3","aws","typing","mypy","secretsmanager","type-stubs","static-analysis"],"install":[{"cmd":"pip install mypy-boto3-secretsmanager boto3","lang":"bash","label":"Install with boto3"}],"dependencies":[{"reason":"Provides the actual AWS SDK runtime functionality; these stubs are for type-checking it.","package":"boto3"}],"imports":[{"symbol":"SecretsManagerClient","correct":"from mypy_boto3_secretsmanager import SecretsManagerClient"},{"note":"Type definitions are typically in the `type_defs` submodule and follow a `*TypeDef` naming convention, not direct imports from the top-level package or `*Response`.","wrong":"from mypy_boto3_secretsmanager import GetSecretValueResponse","symbol":"GetSecretValueResponseTypeDef","correct":"from mypy_boto3_secretsmanager.type_defs import GetSecretValueResponseTypeDef"}],"quickstart":{"code":"import boto3\nimport os\n\nfrom mypy_boto3_secretsmanager import SecretsManagerClient\nfrom mypy_boto3_secretsmanager.type_defs import GetSecretValueResponseTypeDef\n\n\ndef get_secret_value_typed(secret_id: str) -> str:\n    client: SecretsManagerClient = boto3.client(\"secretsmanager\")\n    try:\n        response: GetSecretValueResponseTypeDef = client.get_secret_value(SecretId=secret_id)\n        secret_string = response.get(\"SecretString\")\n        if secret_string is None:\n            raise ValueError(f\"Secret '{secret_id}' has no SecretString.\")\n        return secret_string\n    except client.exceptions.ResourceNotFoundException:\n        print(f\"Secret '{secret_id}' not found.\")\n        return \"\"\n    except Exception as e:\n        print(f\"Error retrieving secret '{secret_id}': {e}\")\n        return \"\"\n\n\nif __name__ == \"__main__\":\n    # Replace with a real secret ID or use an environment variable\n    # Ensure AWS credentials are configured (e.g., via AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION env vars or ~/.aws/credentials)\n    test_secret_id = os.environ.get('TEST_SECRET_ID', 'my-test-secret-id-nonexistent')\n    print(f\"Attempting to retrieve secret: {test_secret_id}\")\n    secret = get_secret_value_typed(test_secret_id)\n    if secret:\n        print(f\"Retrieved secret (first 10 chars): {secret[:10]}...\")\n    else:\n        print(\"Secret retrieval failed or secret not found.\")\n","lang":"python","description":"This example demonstrates how to use the type stubs for AWS Secrets Manager. It initializes a `SecretsManagerClient` and calls `get_secret_value`, with full type hinting for the client and the response dictionary. This allows static type checkers like Mypy to validate your code and provides rich autocompletion in IDEs."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or higher.","message":"As of `mypy-boto3-builder` version 8.12.0 (which generates these stubs), Python 3.8 is no longer supported. Packages built with this builder (including `mypy-boto3-secretsmanager` 1.x.x versions) require Python 3.9 or newer.","severity":"breaking","affected_versions":"mypy-boto3-secretsmanager >= 1.42.x (and generally any version built with builder 8.12.0+)"},{"fix":"Install `mypy-boto3-secretsmanager` and `boto3` with compatible versions. Often, installing both at the same time will resolve compatibility by pulling the latest matching `mypy-boto3` stubs.","message":"Type stubs are designed to match specific `boto3` and `botocore` versions. Mismatched versions between `boto3` (or `botocore`) and `mypy-boto3-secretsmanager` can lead to inaccurate type hints or Mypy errors. Always try to keep them aligned.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consult the specific service's documentation or use IDE autocompletion to find the correct `TypeDef` names after upgrading. Often, removing redundant `Request` or `Extra` suffixes might be the solution.","message":"For stubs generated by `mypy-boto3-builder` version 8.9.0 and later, some `TypeDef` names for method arguments and responses might have changed, primarily to shorten names or resolve conflicts (e.g., `CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`).","severity":"breaking","affected_versions":"mypy-boto3-secretsmanager >= 1.x.x (built with builder 8.9.0+)"},{"fix":"Prefer installing individual service packages (e.g., `pip install mypy-boto3-secretsmanager`) over the single, large `mypy-boto3` package.","message":"The monolithic `mypy-boto3` package (which included all service stubs) is now considered a legacy product. While it still exists, the recommended approach for modern `mypy-boto3-builder` versions is to install specific service packages like `mypy-boto3-secretsmanager` to reduce dependencies and improve build times.","severity":"deprecated","affected_versions":"All versions (affects installation strategy)"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}