A library that provides Bedrock models id
Project description
Bedrock Models
A Python library that provides AWS Bedrock Foundation Model IDs with autocomplete support and utility functions for cross-region inference.
Features
- Type-safe model IDs: Access all Bedrock model IDs as Python constants with full autocomplete support
- Cross-region inference: Automatically generate CRIS (Cross-Region Inference Service) prefixed model IDs
- Region validation: Check model availability across AWS regions
- Auto-updated: Model IDs are automatically updated weekly from AWS Bedrock API
Installation
pip install bedrock-models
Quick Start
from bedrock_models import Models, cris_model_id, is_model_available
# Get model ID with autocomplete
model = Models.ANTHROPIC_CLAUDE_3_5_SONNET_20241022
# Check availability
if is_model_available(model, "us-east-1"):
# Get the best CRIS ID (geo or global)
model_id = cris_model_id(model, region="us-east-1")
print(model_id) # us.anthropic.claude-3-5-sonnet-20241022-v2:0
See examples/ for more detailed usage examples.
Usage
Basic Model IDs
from bedrock_models import Models
# Access model IDs with autocomplete
model_id = Models.ANTHROPIC_CLAUDE_3_5_SONNET_20241022
# Returns: "anthropic.claude-3-5-sonnet-20241022-v2:0"
model_id = Models.AMAZON_NOVA_PRO
# Returns: "amazon.nova-pro-v1:0"
Cross-Region Inference (CRIS)
from bedrock_models import Models, cris_model_id
# Get CRIS model ID (automatically chooses geo or global based on availability)
cris_id = cris_model_id(
Models.ANTHROPIC_CLAUDE_3_5_SONNET_20241022,
region="us-east-1"
)
# Returns: "us.anthropic.claude-3-5-sonnet-20241022-v2:0" (geo CRIS if INFERENCE_PROFILE available)
# Or: "global.anthropic.claude-3-5-sonnet-20241022-v2:0" (if only GLOBAL available)
# Different region prefix (AP regions use "apac")
cris_id = cris_model_id(
Models.AMAZON_NOVA_PRO,
region="ap-south-1"
)
# Returns: "apac.amazon.nova-pro-v1:0"
# Auto-detect region from boto3 (if installed and configured)
import boto3
boto3.setup_default_session(region_name='us-west-2')
cris_id = cris_model_id(
Models.AMAZON_NOVA_PRO # region auto-detected from boto3
)
# Returns: "us.amazon.nova-pro-v1:0"
Check Model Availability
from bedrock_models import Models, is_model_available, get_available_regions
# Check if a model is available in a specific region
available = is_model_available(Models.AMAZON_NOVA_PRO, "us-west-2")
# Returns: True or False
# Auto-detect region from boto3 (if installed and configured)
available = is_model_available(Models.AMAZON_NOVA_PRO)
# Uses region from boto3 session
# Get all regions where a model is available
regions = get_available_regions(Models.ANTHROPIC_CLAUDE_3_5_SONNET_20241022)
# Returns: ['us-east-1', 'us-west-2', 'ap-south-1', ...]
Inference Profiles
from bedrock_models import (
Models,
cris_model_id,
global_model_id,
has_global_profile,
)
# Get CRIS model ID (automatically chooses geo or global based on availability)
model_id = cris_model_id(Models.ANTHROPIC_CLAUDE_3_5_SONNET_20241022, region="us-east-1")
# Returns: "us.anthropic.claude-3-5-sonnet-20241022-v2:0" (geo CRIS)
# Or: "global.anthropic.claude-3-5-sonnet-20241022-v2:0" (if only global available)
# Get global inference profile ID (if supported in region)
global_id = global_model_id(Models.AMAZON_NOVA_PRO, region="us-east-1")
# Returns: "global.amazon.nova-pro-v1:0"
# Raises ValueError if global profile not supported in region
# Check if a model has a global inference profile in a region
has_global = has_global_profile(
Models.ANTHROPIC_CLAUDE_3_5_SONNET_20241022,
"us-east-1"
)
# Returns: True or False
Development
Setup
# Install Poetry
curl -sSL https://install.python-poetry.org | python3 -
# Install dependencies
poetry install
# Run tests
poetry run pytest
Regenerate Model IDs
To update the model IDs from AWS Bedrock:
# Set AWS credentials
export AWS_ACCESS_KEY_ID=your_key
export AWS_SECRET_ACCESS_KEY=your_secret
# Generate model data from AWS
python utils/gen_model_enum.py
mv bedrock_models.json bedrock_models/
# Generate Python class
python utils/generate_model_class.py
# Run tests
poetry run pytest
GitHub Actions Setup
This repository uses GitHub Actions to automatically update model IDs and publish to PyPI.
Required Secrets
Configure these secrets in your GitHub repository settings (Settings → Secrets and variables → Actions):
- AWS_ACCESS_KEY_ID: AWS access key with Bedrock read permissions
- AWS_SECRET_ACCESS_KEY: AWS secret access key
- PYPI_TOKEN: PyPI API token for publishing packages
Required IAM Permissions
The AWS credentials need the following least-privilege IAM policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "BedrockReadOnly",
"Effect": "Allow",
"Action": [
"bedrock:ListFoundationModels",
"bedrock:GetInferenceProfile"
],
"Resource": "*"
},
{
"Sid": "EC2DescribeRegions",
"Effect": "Allow",
"Action": [
"ec2:DescribeRegions"
],
"Resource": "*"
}
]
}
bedrock:ListFoundationModels- List all available foundation models in each regionbedrock:GetInferenceProfile- Check for global inference profile availabilityec2:DescribeRegions- Discover all AWS regions to scan
Workflows
- publish.yml: Runs weekly (or manually) to scan AWS Bedrock, update model IDs, and publish to PyPI if changes are detected
- release.yml: Triggered on version tags (e.g.,
v0.2.0) to create releases
Manual Trigger
You can manually trigger the publish workflow:
- Go to Actions tab in GitHub
- Select "Generate Models and Publish to PyPI"
- Click "Run workflow"
License
MIT-0
Author
Massimiliano Angelino massi.ang@gmail.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bedrock_models-0.1.0.tar.gz.
File metadata
- Download URL: bedrock_models-0.1.0.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.3 Darwin/25.1.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a1b43c80bb191757693b64f167fac32cc784fa2c3ee1fac423af26b3ad32f90
|
|
| MD5 |
42329148b6a95b554a5e234a5ee7fbb7
|
|
| BLAKE2b-256 |
bb0d6553244a2d7cc0b2bfc1906ff9ae3b421dae78a99326a28d07a99cd82465
|
File details
Details for the file bedrock_models-0.1.0-py3-none-any.whl.
File metadata
- Download URL: bedrock_models-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.3 Darwin/25.1.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f663c910dc8f601aa8a9ad01dcf493b79055494ecd22f60b5c94d053e7e0357
|
|
| MD5 |
3e9b75bc5262833f5e07364cb63ce3d0
|
|
| BLAKE2b-256 |
ad5aa7b3f6da9fc4b90163c749f97487b3337c3ab8d59e3f4a93f3cee717a638
|