You can use the assume_role method from the STS client in Boto3.
Example Code:
import boto3
client = boto3.client('sts')
response = client.assume_role(
RoleArn='arn:aws:iam::123456789012:role/ExampleRole',
RoleSessionName='ExampleSession'
)
credentials = response['Credentials']
print(credentials)