Skip to main content

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.

PyPI Python License

Homepage | Docs | GitHub

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 grant token does not include the required scope, create_grantex_tool raises PermissionError immediately and the tool is not created.

Enforcement Modes

Offline mode is the default. It decodes the grant token payload and checks the scp claim without a network call:

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
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+
  • strands-agents >= 0.1

Grantex Ecosystem

This package is part of the Grantex ecosystem. See also:

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

grantex_strands-0.1.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

grantex_strands-0.1.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file grantex_strands-0.1.0.tar.gz.

File metadata

  • Download URL: grantex_strands-0.1.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for grantex_strands-0.1.0.tar.gz
Algorithm Hash digest
SHA256 91fec1c7c9922eee49245678d8077706861cac78e33bfa25601ae93a5ad75180
MD5 e10b2ad1c279c6cb1209957109148f0f
BLAKE2b-256 a8c4685e3563897549b04d6fd517cad4ab76ffd2c2a7dacf483fc1d479be3de7

See more details on using hashes here.

File details

Details for the file grantex_strands-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for grantex_strands-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 58200132a8ea2207b0e5a6543e5f59f3514a3fe5f41266515b8c7b01cd86c226
MD5 0df5b4f79dabf2aa202c16880293d9ea
BLAKE2b-256 7419aaea92a6cbc1227b60d1bbe3716d595d01ffc9a237924ee2aa5349d045e0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page