Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different between AWS boto3.session.Session() and boto3.Session()

I am trying to use AWS python library boto3 to create a session. I found out we can do that either

session = boto3.Session(profile_name='profile1')

or

session2 = boto3.session.Session(profile_name='profile2')

I have checked their docs, it suppose to use boto3.session.Session().

Why both ways work ? What the different of concept behind them ?

like image 552
sylye Avatar asked Sep 14 '25 09:09

sylye


1 Answers

It is just for convenience; they both refer to the same class. What is happening here is that the __init__.py for the python boto3 package includes the following:

from boto3.session import Session

This just allows you to refer to the Session class in your python code as boto3.Session rather than boto3.session.Session.

This article provides more information about this python idiom:

One common thing to do in your __init__.py is to import selected Classes, functions, etc into the package level so they can be conveniently imported from the package.

like image 179
Ashaman Kingpin Avatar answered Sep 16 '25 00:09

Ashaman Kingpin