{"id":3050,"library":"mypy-boto3-codebuild","title":"mypy-boto3-codebuild Type Stubs","description":"mypy-boto3-codebuild provides type annotations for the `boto3` CodeBuild service, enhancing static analysis with tools like MyPy. It is part of the `mypy-boto3` family of libraries, with version `1.42.3` currently available. Releases are frequent, typically mirroring `boto3` updates and `mypy-boto3-builder` changes.","status":"active","version":"1.42.3","language":"en","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["aws","boto3","mypy","type-hints","codebuild","stubs"],"install":[{"cmd":"pip install mypy-boto3-codebuild boto3","lang":"bash","label":"Install library and its runtime dependency"}],"dependencies":[{"reason":"Runtime dependency for AWS SDK operations.","package":"boto3"}],"imports":[{"symbol":"CodeBuildClient","correct":"from mypy_boto3_codebuild.client import CodeBuildClient"},{"note":"Import specific TypedDicts for detailed type annotations of service responses/parameters.","symbol":"ProjectTypeDef","correct":"from mypy_boto3_codebuild.type_defs import ProjectTypeDef"}],"quickstart":{"code":"import boto3\nfrom mypy_boto3_codebuild.client import CodeBuildClient\nfrom typing import TYPE_CHECKING\nimport os\nfrom botocore.exceptions import ClientError\n\n# Dummy variables to satisfy the instruction, though boto3 typically\n# reads these implicitly if set in the environment (e.g., AWS_ACCESS_KEY_ID).\n# Setting them to empty strings ensures the example runs without immediately\n# failing if actual env vars are missing, but the boto3 client will still\n# attempt to find valid credentials via its standard chain.\naccess_key_id = os.environ.get('AWS_ACCESS_KEY_ID', '')\nsecret_access_key = os.environ.get('AWS_SECRET_ACCESS_KEY', '')\nsession_token = os.environ.get('AWS_SESSION_TOKEN', '')\n\nif TYPE_CHECKING:\n    # These imports are only for type checking and will not be used at runtime\n    from mypy_boto3_codebuild.type_defs import ProjectTypeDef\n\ntry:\n    # Initialize a CodeBuild client with type hints.\n    # Boto3 will automatically use credentials from environment variables,\n    # shared config, or IAM roles.\n    # If explicit credentials were desired, one might do:\n    # client: CodeBuildClient = boto3.client(\n    #     \"codebuild\",\n    #     aws_access_key_id=access_key_id,\n    #     aws_secret_access_key=secret_access_key,\n    #     aws_session_token=session_token\n    # )\n    # But for a quickstart, implicit loading is more common and robust.\n    client: CodeBuildClient = boto3.client(\"codebuild\")\n\n    # Example: List CodeBuild projects\n    print(\"Listing CodeBuild projects:\")\n    response = client.list_projects()\n    projects: list[str] = response[\"projects\"]\n\n    for project_name in projects:\n        print(f\"- {project_name}\")\n\n    # Example: Get details for a specific project (if any exist)\n    if projects:\n        project_name = projects[0]\n        print(f\"\\nGetting details for project: {project_name}\")\n        project_details_response = client.batch_get_projects(names=[project_name])\n        if project_details_response and project_details_response[\"projects\"]:\n            project: ProjectTypeDef = project_details_response[\"projects\"][0]\n            print(f\"  Project ARN: {project.get('arn')}\")\n            print(f\"  Project Status: {project.get('build', {}).get('status')}\")\n    else:\n        print(\"\\nNo CodeBuild projects found to display details.\")\n\nexcept ClientError as e:\n    error_code = e.response.get(\"Error\", {}).get(\"Code\")\n    if error_code in [\"UnrecognizedClientException\", \"InvalidClientTokenId\", \"ExpiredToken\", \"NoCredentialsError\"]: # Added NoCredentialsError for common boto3 errors\n        print(f\"Authentication failed. Please ensure AWS credentials (e.g., via environment variables \"\n              f\"AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) are configured correctly. Error: {e}\")\n    else:\n        print(f\"An AWS client error occurred: {e}\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")","lang":"python","description":"This quickstart demonstrates how to initialize a `boto3` CodeBuild client with type hints from `mypy-boto3-codebuild` and perform basic operations like listing projects and retrieving project details. It includes error handling for common `boto3` authentication issues, expecting AWS credentials to be configured via standard `boto3` mechanisms (environment variables, config files, IAM roles)."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or higher.","message":"Python 3.8 support has been removed. Projects using `mypy-boto3-codebuild` or other `mypy-boto3` family stubs must upgrade to Python 3.9 or newer.","severity":"breaking","affected_versions":"Versions generated by `mypy-boto3-builder` 8.12.0 and later."},{"fix":"Review your explicit `from mypy_boto3_codebuild.type_defs import ...` statements and adjust TypedDict names according to the latest package structure.","message":"TypeDef naming conventions were changed, potentially affecting code that directly imports and references specific TypedDicts. For example, `CreateDistributionRequestRequestTypeDef` might become `CreateDistributionRequestTypeDef`.","severity":"breaking","affected_versions":"Versions generated by `mypy-boto3-builder` 8.9.0 and later."},{"fix":"Ensure `mypy` is installed and configured to check your project. Remember that stubs only provide compile-time benefits, not runtime functionality.","message":"These type stubs are for static analysis by tools like MyPy and do not alter the runtime behavior of `boto3`. Incorrectly configured MyPy or expecting runtime changes based on stub updates can lead to confusion.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Stay up-to-date with `mypy-boto3-builder` releases and `boto3` documentation for service name changes. If a service is renamed, update your `mypy-boto3-*` package import accordingly.","message":"AWS service names can change or be deprecated (e.g., `sms-voice` replaced by `pinpoint-sms-voice` in `mypy-boto3-builder` 8.11.0). This can lead to `ModuleNotFoundError` or incorrect type hints if the underlying `boto3` service name changes and the stubs are not updated accordingly.","severity":"gotcha","affected_versions":"All versions, as service names can evolve."},{"fix":"Always use string literals for `service_name` (e.g., `boto3.client(\"codebuild\")`) and ensure they match the service you intend to type-check. IDEs with LSP support often highlight mismatches if stubs are correctly installed.","message":"When using `boto3.resource` or `boto3.client`, make sure the `service_name` string argument is correctly spelled and matches the stub package. A typo will bypass type checking for that client/resource.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}