mypy-boto3-sagemaker-featurestore-runtime Stubs
mypy-boto3-sagemaker-featurestore-runtime provides `mypy` compatible type annotations for `boto3`'s SageMaker Feature Store Runtime service. It helps developers catch type-related errors for `boto3` usage at static analysis time. The library is part of the `mypy-boto3` family, generated by `mypy-boto3-builder`, and its versioning is tied to `boto3`/`botocore` releases, with frequent updates.
Warnings
- breaking Beginning with `mypy-boto3-builder` version 8.12.0 (which generates `mypy-boto3-*` packages, including this one, corresponding to `boto3` versions around 1.34.x and above), support for Python 3.8 has been removed. Projects using these stubs must upgrade to Python 3.9 or newer.
- breaking Stubs generated by `mypy-boto3-builder` version 8.12.0+ are now PEP 561 compliant, changing the package structure to include the `py.typed` marker. While largely transparent, this *may* affect custom `mypy` configurations or build systems that rely on specific stub discovery paths (e.g., if you manually managed `MYPYPATH`).
- gotcha `mypy-boto3-sagemaker-featurestore-runtime` provides type hints for `boto3`, but it is not a runtime library itself. Do not `import mypy_boto3_sagemaker_featurestore-runtime` in your application code for runtime execution. Its purpose is solely for static analysis tools like `mypy`.
- gotcha These stubs are a complement to `boto3`. You must still install `boto3` itself for your application to run. The `mypy-boto3-sagemaker-featurestore-runtime` package does not bundle or install `boto3` for you.
- breaking In `mypy-boto3-builder` version 8.9.0+, some `TypedDict` argument types for API calls (e.g., `CreateDistributionRequestRequestTypeDef` from CloudFront) were shortened to `CreateDistributionRequestTypeDef`. Additionally, conflicting `TypedDict` `Extra` postfixes moved to the end (e.g., `CreateDistributionExtraRequestTypeDef` became `CreateDistributionRequestExtraTypeDef`). While this specific service may not be heavily impacted, it's a breaking change for the `mypy-boto3` ecosystem.
Install
-
pip install mypy-boto3-sagemaker-featurestore-runtime -
pip install boto3 mypy
Imports
- SagemakerFeatureStoreRuntimeClient
from mypy_boto3_sagemaker_featurestore_runtime.client import SagemakerFeatureStoreRuntimeClient
- GetRecordRequestRequestTypeDef
from mypy_boto3_sagemaker_featurestore_runtime.type_defs import GetRecordRequestRequestTypeDef
- GetRecordResponseTypeDef
from mypy_boto3_sagemaker_featurestore_runtime.type_defs import GetRecordResponseTypeDef
Quickstart
import boto3
from mypy_boto3_sagemaker_featurestore_runtime.client import SagemakerFeatureStoreRuntimeClient
from mypy_boto3_sagemaker_featurestore_runtime.type_defs import GetRecordRequestRequestTypeDef, GetRecordResponseTypeDef
import os
def get_feature_store_record(
feature_group_name: str,
record_identifier_value_as_string: str
) -> GetRecordResponseTypeDef:
"""Fetches a record from SageMaker Feature Store with type hints."""
# boto3.client returns an untyped client by default.
# The type hint on 'client' variable applies the stubs.
client: SagemakerFeatureStoreRuntimeClient = boto3.client(
"sagemaker-featurestore-runtime",
region_name=os.environ.get("AWS_REGION", "us-east-1")
)
request_params: GetRecordRequestRequestTypeDef = {
"FeatureGroupName": feature_group_name,
"RecordIdentifierValueAsString": record_identifier_value_as_string,
"FeatureNames": ["example_feature_name"]
}
response: GetRecordResponseTypeDef = client.get_record(**request_params)
return response
# Example usage (ensure AWS credentials are set up)
if __name__ == "__main__":
try:
# Use environment variables for sensitive or dynamic values
# For a runnable example, provide dummy values if env vars are not set
example_feature_group_name = os.environ.get("SAGE_FEATURE_GROUP_NAME", "my-test-feature-group")
example_record_id = os.environ.get("SAGE_RECORD_ID", "12345")
if not os.environ.get("AWS_ACCESS_KEY_ID") or not os.environ.get("AWS_SECRET_ACCESS_KEY"):
print("WARNING: AWS credentials not found in environment. Example might fail at runtime.")
print("Please set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.")
print(f"Attempting to get record for Feature Group: {example_feature_group_name}, Record ID: {example_record_id}")
# This call is type-checked by mypy thanks to the stubs
record_data = get_feature_store_record(example_feature_group_name, example_record_id)
print("Successfully retrieved record (type-checked):")
if "Record" in record_data:
for feature in record_data["Record"]:
print(f" {feature['FeatureName']}: {feature['ValueAsString']}")
else:
print("Record key not found in response, or response is empty.")
except Exception as e:
print(f"An error occurred: {e}")
print("Ensure AWS credentials are configured and the feature group/record exist/are accessible.")