@@ -136,6 +136,7 @@ def from_instance(
136136 password : Optional [str ] = None ,
137137 ip_type : Union [str , IPTypes ] = IPTypes .PUBLIC ,
138138 quota_project : Optional [str ] = None ,
139+ iam_account_email : Optional [str ] = None ,
139140 ) -> PostgresEngine :
140141 """Create a PostgresEngine from a Postgres instance.
141142
@@ -169,6 +170,7 @@ def from_instance(
169170 loop = loop ,
170171 thread = thread ,
171172 quota_project = quota_project ,
173+ iam_account_email = iam_account_email ,
172174 )
173175 return asyncio .run_coroutine_threadsafe (coro , loop ).result ()
174176
@@ -185,6 +187,7 @@ async def _create(
185187 loop : Optional [asyncio .AbstractEventLoop ] = None ,
186188 thread : Optional [Thread ] = None ,
187189 quota_project : Optional [str ] = None ,
190+ iam_account_email : Optional [str ] = None ,
188191 ) -> PostgresEngine :
189192 """Create a PostgresEngine instance.
190193
@@ -227,12 +230,15 @@ async def _create(
227230 db_user = user
228231 # otherwise use automatic IAM database authentication
229232 else :
230- # get application default credentials
231- credentials , _ = google .auth .default (
232- scopes = ["https://www.googleapis.com/auth/userinfo.email" ]
233- )
234- db_user = await _get_iam_principal_email (credentials )
235233 enable_iam_auth = True
234+ if iam_account_email :
235+ db_user = iam_account_email
236+ else :
237+ # get application default credentials
238+ credentials , _ = google .auth .default (
239+ scopes = ["https://www.googleapis.com/auth/userinfo.email" ]
240+ )
241+ db_user = await _get_iam_principal_email (credentials )
236242
237243 # anonymous function to be used for SQLAlchemy 'creator' argument
238244 async def getconn () -> asyncpg .Connection :
@@ -264,6 +270,7 @@ async def afrom_instance(
264270 password : Optional [str ] = None ,
265271 ip_type : Union [str , IPTypes ] = IPTypes .PUBLIC ,
266272 quota_project : Optional [str ] = None ,
273+ iam_account_email : Optional [str ] = None ,
267274 ) -> PostgresEngine :
268275 """Create a PostgresEngine from a Postgres instance.
269276
@@ -290,6 +297,7 @@ async def afrom_instance(
290297 user ,
291298 password ,
292299 quota_project = quota_project ,
300+ iam_account_email = iam_account_email ,
293301 )
294302
295303 @classmethod
0 commit comments