{"library":"smithy-aws-core","title":"Smithy AWS Core","type":"library","description":"Smithy AWS Core provides foundational components for building AWS service clients using the Smithy framework in Python. It encapsulates AWS-specific logic for concerns like authentication (signing requests), endpoint resolution, and HTTP transport. Currently at version 0.5.0, it is part of the broader smithy-python ecosystem, meaning API adjustments are expected as it approaches a 1.0 stable release.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install smithy-aws-core"],"cli":null},"imports":["from smithy_aws_core.config import AwsUserConfig","from smithy_aws_core.signing import AwsSigner","from smithy_aws_core.http import AwsHttpClient","from smithy_aws_core.endpoint import AwsEndpointResolver"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/smithy-lang/smithy-python","docs":null,"changelog":"https://github.com/smithy-lang/smithy-python/blob/develop/packages/smithy-aws-core/CHANGELOG.md","pypi":"https://pypi.org/project/smithy-aws-core/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import asyncio\nimport os\nimport datetime\nfrom smithy_aws_core.config import AwsUserConfig\nfrom smithy_aws_core.signing import AwsSigner\nfrom smithy_python.types import Credentials, UnresolvedUrl\nfrom smithy_python.http import HttpRequest\n\nasync def main():\n    # In a real application, consider using aiobotocore.session.get_session()\n    # for robust credential discovery. For this quickstart, we use environment variables.\n    aws_access_key_id = os.environ.get(\"AWS_ACCESS_KEY_ID\", \"AKIAIOSFODNN7EXAMPLE\")\n    aws_secret_access_key = os.environ.get(\"AWS_SECRET_ACCESS_KEY\", \"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY\")\n    aws_session_token = os.environ.get(\"AWS_SESSION_TOKEN\", None)\n\n    if aws_access_key_id == \"AKIAIOSFODNN7EXAMPLE\" or aws_secret_access_key == \"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY\":\n        print(\"Warning: Using dummy AWS credentials. Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables for real usage.\")\n\n    credentials = Credentials(\n        access_key_id=aws_access_key_id,\n        secret_access_key=aws_secret_access_key,\n        token=aws_session_token\n    )\n\n    config = AwsUserConfig(\n        region=\"us-east-1\",\n        credentials=credentials,\n        endpoint_url=UnresolvedUrl(\"https://s3.us-east-1.amazonaws.com\") # Example S3 endpoint\n    )\n    print(f\"\\nCreated AWS User Config for region: {config.region}\")\n\n    # Demonstrate an AWS Signer\n    signer = AwsSigner(service_id=\"s3\", config=config) # 's3' is the service ID for S3\n    print(f\"Created AWS Signer for service: {signer.service_id}\")\n\n    # Prepare a dummy HTTP request to be signed\n    request = HttpRequest(\n        method=\"GET\",\n        url=\"https://s3.us-east-1.amazonaws.com/my-bucket\", # Example URL, typically resolved by client\n        headers={\n            \"Host\": \"s3.us-east-1.amazonaws.com\",\n            \"User-Agent\": \"smithy-python-quickstart/1.0\"\n        },\n        body=b\"\"\n    )\n\n    # Sign the request\n    # Note: The 'url' in HttpRequest must be a concrete string, not UnresolvedUrl, for signing.\n    # In a real client, endpoint resolution would convert UnresolvedUrl to a string.\n    signed_request = await signer.sign(request, credentials, datetime.datetime.now(datetime.timezone.utc))\n\n    print(f\"\\n--- Signed Request Details ---\")\n    print(f\"Method: {signed_request.method}\")\n    print(f\"URL: {signed_request.url}\")\n    print(f\"Headers: {signed_request.headers}\")\n    if 'Authorization' in signed_request.headers:\n        print(f\"Authorization header present (truncated): {signed_request.headers['Authorization'][:50]}...\")\n    else:\n        print(\"Authorization header NOT found.\")\n\nasyncio.run(main())\n","lang":"python","description":"This quickstart demonstrates how to initialize core Smithy AWS components like `AwsUserConfig` for regional and credential settings, and how to use `AwsSigner` to sign a basic HTTP request, which is a fundamental step in interacting with AWS services. It uses environment variables for AWS credentials.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}