Low-level, data-driven core of boto 3 providing foundational AWS service access.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Central session management providing configuration, credentials, and service client creation. Sessions serve as the primary entry point to botocore and handle AWS profile management, credential resolution, and service discovery.
Create and configure botocore sessions for AWS service access.
def get_session(env_vars: dict = None) -> Session:
"""
Create a new botocore session.
Args:
env_vars: Custom environment variables mapping
Returns:
Session: Configured botocore session
"""Primary interface for botocore functionality, managing configuration and service clients.
class Session:
def __init__(
self,
session_vars: dict = None,
event_hooks: HierarchicalEmitter = None,
include_builtin_handlers: bool = True,
profile: str = None
):
"""
Initialize a botocore session.
Args:
session_vars: Session variable overrides
event_hooks: Custom event emitter
include_builtin_handlers: Include default event handlers
profile: AWS profile name to use
"""Manage AWS profiles and configuration settings.
class Session:
@property
def available_profiles(self) -> List[str]:
"""List of available AWS configuration profiles."""
@property
def profile(self) -> str:
"""Current AWS profile name."""
def get_config_variable(
self,
logical_name: str,
methods: List[str] = None
) -> Any:
"""
Retrieve configuration variable value.
Args:
logical_name: Configuration variable name
methods: Configuration methods to check
Returns:
Configuration value or None
"""
def set_config_variable(self, logical_name: str, value: Any) -> None:
"""
Set configuration variable value.
Args:
logical_name: Configuration variable name
value: Value to set
"""
def instance_variables(self) -> dict:
"""Get mapping of instance variables."""
def get_scoped_config(self) -> dict:
"""Get profile-specific configuration."""
def full_config(self) -> dict:
"""Get complete configuration dictionary."""Manage default client configuration settings.
class Session:
def get_default_client_config(self) -> Config:
"""Get default client configuration."""
def set_default_client_config(self, client_config: Config) -> None:
"""
Set default client configuration.
Args:
client_config: Configuration to use as default
"""Access and manage AWS credentials through the session.
class Session:
def get_credentials(self) -> Credentials:
"""
Get current AWS credentials.
Returns:
Credentials: Current AWS credentials or None
"""
def get_auth_token(self, **kwargs) -> str:
"""
Get authentication token for services requiring token-based auth.
Returns:
Authentication token string
"""Discover and access AWS service information.
class Session:
def get_available_services(self) -> List[str]:
"""List of available AWS service names."""
def get_service_model(
self,
service_name: str,
api_version: str = None
) -> ServiceModel:
"""
Get service model for AWS service.
Args:
service_name: AWS service name (e.g., 's3', 'ec2')
api_version: Specific API version
Returns:
ServiceModel: Service model object
"""
def get_waiter_model(
self,
service_name: str,
api_version: str = None
) -> WaiterModel:
"""
Get waiter model for AWS service.
Args:
service_name: AWS service name
api_version: Specific API version
Returns:
WaiterModel: Waiter model object
"""
def get_paginator_model(
self,
service_name: str,
api_version: str = None
) -> PaginatorModel:
"""
Get paginator model for AWS service.
Args:
service_name: AWS service name
api_version: Specific API version
Returns:
PaginatorModel: Paginator model object
"""
def get_service_data(
self,
service_name: str,
api_version: str = None
) -> dict:
"""
Get raw service data dictionary.
Args:
service_name: AWS service name
api_version: Specific API version
Returns:
dict: Raw service definition data
"""
def get_data(self, data_path: str) -> Any:
"""
Get data from service definitions.
Args:
data_path: Path to data (e.g., 'endpoints', 'partitions')
Returns:
Data from service definitions
"""Create service-specific clients for AWS API access.
class Session:
def create_client(
self,
service_name: str,
region_name: str = None,
api_version: str = None,
use_ssl: bool = True,
verify: Union[bool, str] = None,
endpoint_url: str = None,
aws_access_key_id: str = None,
aws_secret_access_key: str = None,
aws_session_token: str = None,
config: Config = None
) -> BaseClient:
"""
Create AWS service client.
Args:
service_name: AWS service name (e.g., 's3', 'ec2')
region_name: AWS region name
api_version: Specific API version
use_ssl: Use SSL/TLS for requests
verify: SSL certificate verification
endpoint_url: Custom service endpoint URL
aws_access_key_id: AWS access key ID
aws_secret_access_key: AWS secret access key
aws_session_token: AWS session token
config: Advanced client configuration
Returns:
BaseClient: AWS service client
"""Configure logging for debugging and monitoring.
class Session:
@property
def user_agent(self) -> str:
"""User agent string for requests."""
def set_debug_logger(self, logger_name: str = 'botocore') -> None:
"""
Configure debug logging.
Args:
logger_name: Logger name to configure
"""
def set_file_logger(
self,
log_level: int,
path: str,
logger_name: str = 'botocore'
) -> None:
"""
Configure file-based logging.
Args:
log_level: Logging level (e.g., logging.DEBUG)
path: Log file path
logger_name: Logger name to configure
"""Access and manage the session's event system.
class Session:
def emit(self, event_name: str, **kwargs) -> List:
"""
Emit event to registered handlers.
Args:
event_name: Event name to emit
**kwargs: Event data
Returns:
List of handler responses
"""
def emit_first_non_none_response(
self,
event_name: str,
**kwargs
) -> Any:
"""
Emit event and return first non-None response.
Args:
event_name: Event name to emit
**kwargs: Event data
Returns:
First non-None handler response
"""Register and retrieve session components.
class Session:
def get_component(self, name: str) -> Any:
"""
Get registered component by name.
Args:
name: Component name
Returns:
Registered component
"""
def register_component(self, name: str, component: Any) -> None:
"""
Register session component.
Args:
name: Component name
component: Component to register
"""
def lazy_register_component(
self,
name: str,
component: Any
) -> None:
"""
Register component with lazy initialization.
Args:
name: Component name
component: Component factory or instance
"""Access AWS region and partition information.
class Session:
def get_available_partitions(self) -> List[str]:
"""List of available AWS partitions."""
def get_partition_for_region(self, region_name: str) -> str:
"""
Get AWS partition for region.
Args:
region_name: AWS region name
Returns:
str: AWS partition name
"""from botocore.session import get_session
# Create session with default configuration
session = get_session()
# Create session with specific profile
session = get_session()
session.profile = 'myprofile'
# Create clients for different services
s3 = session.create_client('s3', region_name='us-east-1')
ec2 = session.create_client('ec2', region_name='us-west-2')# Get configuration values
region = session.get_config_variable('region')
profile = session.profile
# Set configuration
session.set_config_variable('region', 'us-west-1')
# Access complete configuration
config = session.full_config()# List available services
services = session.get_available_services()
print(f"Available services: {len(services)}")
# Get service model
s3_model = session.get_service_model('s3')
operations = s3_model.operation_namesInstall with Tessl CLI
npx tessl i tessl/pypi-botocore