{"id":3128,"library":"mypy-boto3-rekognition","title":"Type Annotations for boto3 Rekognition","description":"This library provides comprehensive type annotations for the `boto3` AWS Rekognition service, generated by `mypy-boto3-builder`. It enhances developer experience by enabling static type checking, autocompletion, and improved error detection for `boto3` users working with Rekognition, ensuring type safety in AWS SDK interactions. The current version is 1.42.3 and it is actively maintained through regular updates from the `mypy-boto3-builder` project.","status":"active","version":"1.42.3","language":"en","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["aws","boto3","rekognition","type-hints","mypy","stubs","python"],"install":[{"cmd":"pip install mypy-boto3-rekognition","lang":"bash","label":"Standalone installation"},{"cmd":"pip install 'boto3-stubs[rekognition]'","lang":"bash","label":"Install as part of boto3-stubs meta-package"}],"dependencies":[{"reason":"Provides the underlying AWS SDK for Python. This library offers type hints for boto3, but boto3 itself must be installed separately for runtime functionality.","package":"boto3","optional":false},{"reason":"May be required for full typing compatibility on older Python versions, though typically less critical for Python 3.9+ environments.","package":"typing-extensions","optional":true}],"imports":[{"symbol":"RekognitionClient","correct":"from mypy_boto3_rekognition.client import RekognitionClient"},{"note":"Type definitions (TypedDicts) for API responses and request parameters.","symbol":"DetectLabelsResponseTypeDef","correct":"from mypy_boto3_rekognition.type_defs import DetectLabelsResponseTypeDef"},{"note":"Literals for string-based enum values used in API calls.","symbol":"AttributeType","correct":"from mypy_boto3_rekognition.literals import AttributeType"},{"note":"Type hints for waiters, used to pause execution until a resource enters a desired state.","symbol":"ProjectVersionRunningWaiter","correct":"from mypy_boto3_rekognition.waiter import ProjectVersionRunningWaiter"},{"note":"Type hints for paginators, used to iterate through large result sets.","symbol":"DetectFacesPaginator","correct":"from mypy_boto3_rekognition.paginator import DetectFacesPaginator"}],"quickstart":{"code":"import boto3\nfrom mypy_boto3_rekognition.client import RekognitionClient\nfrom mypy_boto3_rekognition.type_defs import DetectLabelsResponseTypeDef\nimport os\n\n# Configure AWS region from environment variable or default\naws_region = os.environ.get(\"AWS_REGION\", \"us-east-1\")\n\n# Create a Rekognition client with type hints\n# boto3 will automatically pick up credentials from environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)\n# or ~/.aws/credentials, or IAM roles.\nrekognition_client: RekognitionClient = boto3.client(\"rekognition\", region_name=aws_region)\n\n# Example: Detect labels in an image from an S3 bucket\ntry:\n    # Replace with your S3 bucket and object key for testing\n    s3_bucket_name = os.environ.get(\"REKOGNITION_TEST_BUCKET\", \"your-rekognition-test-bucket\")\n    s3_object_key = os.environ.get(\"REKOGNITION_TEST_OBJECT_KEY\", \"your-image.jpg\")\n\n    if s3_bucket_name == \"your-rekognition-test-bucket\" or s3_object_key == \"your-image.jpg\":\n        print(\"Please set REKOGNITION_TEST_BUCKET and REKOGNITION_TEST_OBJECT_KEY environment variables or replace placeholders.\")\n    else:\n        response: DetectLabelsResponseTypeDef = rekognition_client.detect_labels(\n            Image={\n                'S3Object': {\n                    'Bucket': s3_bucket_name,\n                    'Name': s3_object_key,\n                }\n            },\n            MaxLabels=10,\n            MinConfidence=75\n        )\n\n        print(f\"Detected labels in s3://{s3_bucket_name}/{s3_object_key}:\")\n        for label in response.get(\"Labels\", []):\n            print(f\"  {label['Name']} (Confidence: {label['Confidence']:.2f}%)\")\n\nexcept rekognition_client.exceptions.InvalidImageFormatException:\n    print(\"Error: Image format not supported by Rekognition.\")\nexcept rekognition_client.exceptions.ClientError as e:\n    print(f\"AWS Client Error: {e}\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")","lang":"python","description":"This quickstart demonstrates how to initialize a Rekognition client with type annotations and use it to detect labels in an image stored in an S3 bucket. It shows explicit type hints for the client object and the response, leveraging the benefits of static type checking. Ensure `boto3` is installed and AWS credentials are configured for the example to run."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or newer.","message":"Support for Python 3.8 was removed in `mypy-boto3-builder` version 8.12.0. Consequently, `mypy-boto3-rekognition` versions 1.42.3 and newer require Python 3.9 or higher.","severity":"breaking","affected_versions":">=1.42.3"},{"fix":"Update your code to use the new, shorter TypeDef names for request and response parameters.","message":"TypeDef naming conventions changed in `mypy-boto3-builder` 8.9.0. Specifically, argument TypeDefs were shortened (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`) and conflicting `Extra` postfixes were moved (e.g., `CreateDistributionExtraRequestTypeDef` became `CreateDistributionRequestExtraTypeDef`).","severity":"breaking","affected_versions":">=1.39.0 (corresponding to builder 8.9.0)"},{"fix":"Ensure `boto3` is installed alongside `mypy-boto3-rekognition`.","message":"This library provides *only* type hints (stubs). It does not include the functional `boto3` library itself. You must install `boto3` separately (`pip install boto3`) for your code to run.","severity":"gotcha","affected_versions":"All"},{"fix":"Keep `mypy-boto3-rekognition` and `boto3` versions synchronized. For example, `pip install 'boto3==1.42.3' 'mypy-boto3-rekognition==1.42.3'`.","message":"The `mypy-boto3` packages are designed to be version-matched with the `boto3` library. Using `mypy-boto3-rekognition` 1.42.3 implies you should be using `boto3` version 1.42.3. Mismatched versions can lead to incorrect or missing type hints.","severity":"gotcha","affected_versions":"All"},{"fix":"Consider `pip install boto3-stubs-lite[rekognition]` for PyCharm, or configure PyCharm to use an external type checker.","message":"Users of PyCharm might experience slow performance with `mypy-boto3` due to issues with Literal overloads (PyCharm issue PY-40997). In such cases, it's recommended to either use `boto3-stubs-lite` (if explicit type annotations are acceptable) or disable PyCharm's internal type checker and rely on external tools like `mypy` or `pyright`.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}