Grantex scope enforcement for Strands Agents SDK
Project description
grantex-strands
Strands Agents SDK integration for the Grantex delegated authorization protocol - scope-enforced agent tools.
Wrap Strands tool functions with Grantex grant token scope checks so agents only receive tools they have been authorized to use.
Install
pip install grantex-strands
You also need the Strands Agents SDK installed:
pip install strands-agents
Quick Start
from grantex_strands import create_grantex_tool
def get_calendar_events(date: str = "") -> str:
return f"events for {date}"
read_calendar = create_grantex_tool(
name="read_calendar",
description="Read upcoming calendar events",
grant_token=grant_token,
required_scope="calendar:read",
func=get_calendar_events,
)
# Pass read_calendar into your Strands agent tools list.
If the verified grant token does not include the required scope, create_grantex_tool raises PermissionError immediately and the tool is not created.
Enforcement Modes
Verified mode is the default. It verifies the grant token against JWKS and checks the verified scp claim:
tool = create_grantex_tool(
name="read_calendar",
description="Read upcoming calendar events",
grant_token=grant_token,
required_scope="calendar:read",
func=get_calendar_events,
)
Online mode delegates enforcement to a Grantex client:
tool = create_grantex_tool(
name="read_calendar",
description="Read upcoming calendar events",
grant_token=grant_token,
required_scope="calendar:read",
func=get_calendar_events,
client=grantex_client,
connector="calendar",
online=True,
)
API Reference
create_grantex_tool()
Creates a Strands-compatible tool with Grantex scope enforcement.
| Parameter | Type | Description |
|---|---|---|
name |
str |
Tool name |
description |
str |
Tool description |
grant_token |
str |
JWT grant token from Grantex |
required_scope |
str |
Scope that must be present in the token |
func |
Callable[..., str] |
Function to wrap |
jwks_uri |
str |
JWKS URL used to verify the grant token |
issuer, issuer_did, audience |
str | None |
Optional JWT claim validation settings |
clock_tolerance |
int |
Clock tolerance in seconds for token verification |
client |
Any |
Grantex client instance for online mode |
connector |
str | None |
Connector name for online mode |
online |
bool |
Use client.enforce() instead of offline JWT scope checking |
get_tool_scopes()
Returns the scopes embedded in a grant token. Invalid tokens return an empty list.
Requirements
- Python 3.11+
grantex >= 0.3.12strands-agents >= 0.1
Grantex Ecosystem
This package is part of the Grantex ecosystem. See also:
grantex- Core Python SDKgrantex-crewai- CrewAI integrationgrantex-openai-agents- OpenAI Agents SDK integrationgrantex-adk- Google ADK integration
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file grantex_strands-0.1.1.tar.gz.
File metadata
- Download URL: grantex_strands-0.1.1.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b49024fb187bb22c0e80747c434bf8a7c5d38f755791b86ed06d4267a4074a9c
|
|
| MD5 |
e91aae8802bb3503b1d3f25751381eca
|
|
| BLAKE2b-256 |
b69011004abcd877ccf401f332618a0019302dd4eb174fd99a22ee6ff3be6338
|
File details
Details for the file grantex_strands-0.1.1-py3-none-any.whl.
File metadata
- Download URL: grantex_strands-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a48a9d2063e300a81809f6dbf0187a2e5a64f5ceb92dbb43681bd9ad6dc22afc
|
|
| MD5 |
e6e3ffa9745398895801d9641d3bab8f
|
|
| BLAKE2b-256 |
bbb3abf602ed5f2f946f436f9c51e973d3ad1672dcc03ce959d0f44c400a9c47
|