agent-identity-python-sdk 0.1.1__tar.gz → 0.1.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (20) hide show
  1. {agent_identity_python_sdk-0.1.1 → agent_identity_python_sdk-0.1.3}/PKG-INFO +15 -1
  2. {agent_identity_python_sdk-0.1.1 → agent_identity_python_sdk-0.1.3}/README.md +14 -0
  3. {agent_identity_python_sdk-0.1.1 → agent_identity_python_sdk-0.1.3}/setup.py +4 -4
  4. {agent_identity_python_sdk-0.1.1 → agent_identity_python_sdk-0.1.3}/src/agent_identity_python_sdk/core/decorators.py +47 -4
  5. {agent_identity_python_sdk-0.1.1 → agent_identity_python_sdk-0.1.3}/src/agent_identity_python_sdk.egg-info/PKG-INFO +15 -1
  6. {agent_identity_python_sdk-0.1.1 → agent_identity_python_sdk-0.1.3}/src/agent_identity_python_sdk.egg-info/requires.txt +3 -3
  7. {agent_identity_python_sdk-0.1.1 → agent_identity_python_sdk-0.1.3}/setup.cfg +0 -0
  8. {agent_identity_python_sdk-0.1.1 → agent_identity_python_sdk-0.1.3}/src/agent_identity_python_sdk/__init__.py +0 -0
  9. {agent_identity_python_sdk-0.1.1 → agent_identity_python_sdk-0.1.3}/src/agent_identity_python_sdk/context/__init__.py +0 -0
  10. {agent_identity_python_sdk-0.1.1 → agent_identity_python_sdk-0.1.3}/src/agent_identity_python_sdk/context/context.py +0 -0
  11. {agent_identity_python_sdk-0.1.1 → agent_identity_python_sdk-0.1.3}/src/agent_identity_python_sdk/core/__init__.py +0 -0
  12. {agent_identity_python_sdk-0.1.1 → agent_identity_python_sdk-0.1.3}/src/agent_identity_python_sdk/core/identity.py +0 -0
  13. {agent_identity_python_sdk-0.1.1 → agent_identity_python_sdk-0.1.3}/src/agent_identity_python_sdk/model/__init__.py +0 -0
  14. {agent_identity_python_sdk-0.1.1 → agent_identity_python_sdk-0.1.3}/src/agent_identity_python_sdk/model/stscredential.py +0 -0
  15. {agent_identity_python_sdk-0.1.1 → agent_identity_python_sdk-0.1.3}/src/agent_identity_python_sdk/utils/__init__.py +0 -0
  16. {agent_identity_python_sdk-0.1.1 → agent_identity_python_sdk-0.1.3}/src/agent_identity_python_sdk/utils/cache.py +0 -0
  17. {agent_identity_python_sdk-0.1.1 → agent_identity_python_sdk-0.1.3}/src/agent_identity_python_sdk/utils/config.py +0 -0
  18. {agent_identity_python_sdk-0.1.1 → agent_identity_python_sdk-0.1.3}/src/agent_identity_python_sdk.egg-info/SOURCES.txt +0 -0
  19. {agent_identity_python_sdk-0.1.1 → agent_identity_python_sdk-0.1.3}/src/agent_identity_python_sdk.egg-info/dependency_links.txt +0 -0
  20. {agent_identity_python_sdk-0.1.1 → agent_identity_python_sdk-0.1.3}/src/agent_identity_python_sdk.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: agent_identity_python_sdk
3
- Version: 0.1.1
3
+ Version: 0.1.3
4
4
  Summary: Python SDK for using Agent Identity Service
5
5
  Home-page: https://github.com/aliyun/agent-identity-dev-kit
6
6
  Author: shaoheng
@@ -110,6 +110,20 @@ def my_function(sts_credential: STSCredential):
110
110
  my_function()
111
111
  ```
112
112
 
113
+ ### Using Decorators to Obtain Workload Credentials
114
+
115
+ ```python
116
+ from agent_identity_python_sdk.core.decorators import requires_workload_access_token
117
+ @requires_workload_access_token(inject_param_name="workload_access_token")
118
+ def my_function(workload_access_token: str):
119
+ # use workload_access_token here
120
+ print(f"Workload Access Token: {workload_access_token}")
121
+ # Your business logic
122
+
123
+ # call the function
124
+ my_function()
125
+ ```
126
+
113
127
  ## Core Modules
114
128
 
115
129
  ### IdentityClient
@@ -89,6 +89,20 @@ def my_function(sts_credential: STSCredential):
89
89
  my_function()
90
90
  ```
91
91
 
92
+ ### Using Decorators to Obtain Workload Credentials
93
+
94
+ ```python
95
+ from agent_identity_python_sdk.core.decorators import requires_workload_access_token
96
+ @requires_workload_access_token(inject_param_name="workload_access_token")
97
+ def my_function(workload_access_token: str):
98
+ # use workload_access_token here
99
+ print(f"Workload Access Token: {workload_access_token}")
100
+ # Your business logic
101
+
102
+ # call the function
103
+ my_function()
104
+ ```
105
+
92
106
  ## Core Modules
93
107
 
94
108
  ### IdentityClient
@@ -5,7 +5,7 @@ with open("README.md", encoding="utf-8") as f:
5
5
 
6
6
  setup(
7
7
  name="agent_identity_python_sdk",
8
- version="0.1.1",
8
+ version="0.1.3",
9
9
  description="Python SDK for using Agent Identity Service",
10
10
  long_description=long_description,
11
11
  long_description_content_type="text/markdown",
@@ -20,9 +20,9 @@ setup(
20
20
  "alibabacloud-agentidentity20250901>=1.0.1",
21
21
  "alibabacloud-agentidentitydata20251127>=1.0.2",
22
22
  "setuptools",
23
- "pydantic==2.11.7",
24
- "urllib3==2.3.0",
25
- "utils==1.0.2",
23
+ "pydantic>=2.11.7",
24
+ "urllib3>=2.3.0",
25
+ "utils>=1.0.2",
26
26
  ],
27
27
  extras_require={
28
28
  "dev": [
@@ -117,7 +117,6 @@ def requires_access_token(
117
117
 
118
118
  return decorator
119
119
 
120
-
121
120
  def requires_api_key(*, credential_provider_name: str, inject_param_name: str = "api_key") -> Callable:
122
121
  """Decorator that fetches an api key before calling the decorated function.
123
122
 
@@ -235,6 +234,52 @@ def requires_sts_token(*, inject_param_name: str = "sts_credential",
235
234
 
236
235
  return decorator
237
236
 
237
+ def requries_workload_access_token(*, inject_param_name: str = "workload_access_token") -> Callable:
238
+ """Decorator that fetches a workload access token before calling the decorated function.
239
+
240
+ Args:
241
+ inject_param_name: Parameter name to inject the workload access token into
242
+
243
+ Returns:
244
+ Decorator function that handles workload access token acquisition and injection
245
+ """
246
+
247
+ def decorator(func: Callable) -> Callable:
248
+ client = IdentityClient(get_region())
249
+
250
+ async def _get_workload_token() -> str:
251
+ user_id = AgentIdentityContext.get_user_id()
252
+ id_token = AgentIdentityContext.get_user_token()
253
+
254
+ return await _get_workload_access_token(client, user_id=user_id, id_token=id_token)
255
+
256
+ @wraps(func)
257
+ async def async_wrapper(*args: Any, **kwargs: Any) -> Any:
258
+ workload_access_token = await _get_workload_token()
259
+ kwargs[inject_param_name] = workload_access_token
260
+ return await func(*args, **kwargs)
261
+
262
+ @wraps(func)
263
+ def sync_wrapper(*args: Any, **kwargs: Any) -> Any:
264
+ if _has_running_loop():
265
+ ctx = contextvars.copy_context()
266
+ import concurrent.futures
267
+
268
+ with concurrent.futures.ThreadPoolExecutor() as executor:
269
+ future = executor.submit(ctx.run, asyncio.run, _get_workload_token())
270
+ workload_access_token = future.result()
271
+ else:
272
+ workload_access_token = asyncio.run(_get_workload_token())
273
+
274
+ kwargs[inject_param_name] = workload_access_token
275
+ return func(*args, **kwargs)
276
+
277
+ if asyncio.iscoroutinefunction(func):
278
+ return async_wrapper
279
+ else:
280
+ return sync_wrapper
281
+
282
+ return decorator
238
283
 
239
284
  async def _get_workload_access_token_local(client: IdentityClient, user_id: Optional[str] = None, id_token: Optional[str] = None) -> str:
240
285
  workload_identity_name = os.environ.get("AGENT_IDENTITY_WORKLOAD_IDENTITY_NAME", None)
@@ -251,7 +296,6 @@ async def _get_workload_access_token_local(client: IdentityClient, user_id: Opti
251
296
 
252
297
  return client.get_workload_access_token(workload_identity_name, user_id=user_id, user_token=id_token)
253
298
 
254
-
255
299
  async def _get_workload_access_token(client: IdentityClient,
256
300
  user_id: Optional[str] = None,
257
301
  id_token: Optional[str] = None) -> str:
@@ -261,10 +305,9 @@ async def _get_workload_access_token(client: IdentityClient,
261
305
  else:
262
306
  return await _get_workload_access_token_local(client, user_id, id_token)
263
307
 
264
-
265
308
  def _has_running_loop() -> bool:
266
309
  try:
267
310
  asyncio.get_running_loop()
268
311
  return True
269
312
  except RuntimeError:
270
- return False
313
+ return False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: agent-identity-python-sdk
3
- Version: 0.1.1
3
+ Version: 0.1.3
4
4
  Summary: Python SDK for using Agent Identity Service
5
5
  Home-page: https://github.com/aliyun/agent-identity-dev-kit
6
6
  Author: shaoheng
@@ -110,6 +110,20 @@ def my_function(sts_credential: STSCredential):
110
110
  my_function()
111
111
  ```
112
112
 
113
+ ### Using Decorators to Obtain Workload Credentials
114
+
115
+ ```python
116
+ from agent_identity_python_sdk.core.decorators import requires_workload_access_token
117
+ @requires_workload_access_token(inject_param_name="workload_access_token")
118
+ def my_function(workload_access_token: str):
119
+ # use workload_access_token here
120
+ print(f"Workload Access Token: {workload_access_token}")
121
+ # Your business logic
122
+
123
+ # call the function
124
+ my_function()
125
+ ```
126
+
113
127
  ## Core Modules
114
128
 
115
129
  ### IdentityClient
@@ -1,9 +1,9 @@
1
1
  alibabacloud-agentidentity20250901>=1.0.1
2
2
  alibabacloud-agentidentitydata20251127>=1.0.2
3
- pydantic==2.11.7
3
+ pydantic>=2.11.7
4
4
  setuptools
5
- urllib3==2.3.0
6
- utils==1.0.2
5
+ urllib3>=2.3.0
6
+ utils>=1.0.2
7
7
 
8
8
  [dev]
9
9
  pytest-asyncio>=0.24.0