Skip to main content

trustgate-sdk

The TrustGate SDK for Python. 3.10+, standard library only.

pip install trustgate-sdk

Setup

from trustgate import TrustGate, ToolFormat

tg = TrustGate()   # TRUSTGATE_URL + TRUSTGATE_API_KEY

Two values, or none if they are in the environment. The applications behind the key are asked for: tg.identity() asks the gateway once and remembers it.

identity = tg.identity()
# identity.key -> KeyInfo(name="prod", expires_at=None)   # None means never
# KeyConsumer(slug="support-agent", type="MCP", url="https://…/support-agent/mcp",
#             upstreams=[KeyUpstream(server="Notion", account="shared", connected=True)])
# KeyConsumer(slug="support-llm",   type="LLM", url="https://…/support-llm/v1")

key.expires_at is the 401 you would otherwise meet mid-run, and upstreams is the refusal you would otherwise meet on the first tool call — both answered before anything starts.

mcp_consumer and llm_consumer (or TRUSTGATE_MCP_CONSUMER / TRUSTGATE_LLM_CONSUMER) are only needed when a key reaches two applications on the same plane — the SDK names them and refuses rather than guessing.

An agent that acts as the application

agent = tg.connect(requires=["search"])

agent.mcp                                        # url + headers for a framework
tg.llm()                                         # base_url for OpenAI, anthropic_base_url for Anthropic
toolkit = agent.toolkit(ToolFormat.OPENAI_RESPONSES)
agent.call_tool("search", {"query": "runbook"})
agent.refresh()                                  # re-read the toolkit
agent.connections                                # its own upstream accounts

A batch that must not stop halfway:

try:
    agent = tg.connect(requires=["search"])
except UpstreamNotConnectedError as error:
    sys.exit(str(error))   # names each server and who fixes it

for row in rows:
    agent.call_tool("search", {"query": row.query})

The gateway serves a tool under the server it came from - Notion's search as notion_search - so two servers with a search stay apart. That prefix is the gateway's, so requires and call_tool take the name the server itself gave the tool and add it; naming a tool two of your servers serve is the one case they ask instead.

An agent acting for one of its users

alice = tg.for_end_user("user_123")
# or, from an agent you already have - no round trip, same toolkit:
bob = agent.for_end_user("user_456")

alice.connections()
alice.connect_link("com.notion/mcp")
alice.toolkit(ToolFormat.ANTHROPIC_MESSAGES)

Both handles work on the same application and the same key: who a call runs as comes from the call, not from anything configured on the application. The name is yours to choose and the gateway namespaces it, so two applications naming user_123 never reach the same account.

The model call, with tools

toolkit = agent.toolkit(ToolFormat.OPENAI_RESPONSES, strict=True)
for warning in toolkit.warnings:
    log.warning("%s could not be strict: %s", warning.tool, warning.reason)

response = client.responses.create(model="gpt-5.2", tools=toolkit.tools, input=messages)
while any(item.type == "function_call" for item in response.output):
    response = client.responses.create(
        model="gpt-5.2",
        tools=toolkit.tools,
        previous_response_id=response.id,
        input=toolkit.execute(response.output),
    )

execute() reads the provider's own objects as well as plain dicts, so the response from the OpenAI or Anthropic SDK can be passed straight in.

Your own HTTP client

tg = TrustGate(..., transport=MyTransport())

Transport is a one-method protocol. The default is UrllibTransport; the tests use a fake one. It is also where a retry policy or a proxy belongs.

Errors

Class When
MissingToolsError requires names a tool the application does not serve
UpstreamNotConnectedError a server the application calls has no account behind it; servers names them and the message says who connects it
ConsentRequiredError an end user has not connected; carries connect_url
PolicyBlockedError a gateway policy refused the call
ToolNotFoundError the tool left the toolkit under a running agent
PlaneUnavailableError the key reaches no application on that plane
AuthenticationError, RateLimitedError, ServiceUnavailableError, TrustGateServerError as named

Development

uv sync --extra dev
uv run pytest

CONTRIBUTING.md has every check CI runs.

Release files for trustgate-sdk 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for trustgate-sdk 0.1.0
File Size Uploaded
trustgate_sdk-0.1.0.tar.gz 43.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for trustgate-sdk 0.1.0
File Interpreter ABI Platform
trustgate_sdk-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 77.2 kB

Release files / trustgate_sdk-0.1.0.tar.gz

Download URL trustgate_sdk-0.1.0.tar.gz
Size 43.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ca4d9ba9e7da5dcf9ae03c143fefd7aa0cfd318dd6f630534f9fd1aa8d3fcf3b
BLAKE2b-256 checksum
How to use checksums
3327b68264663702bee07b18f7101839d418d6651c9fe4a9e5f271f363ca2d65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 22, 2026.

Transparency log

Release files / trustgate_sdk-0.1.0-py3-none-any.whl

Download URL trustgate_sdk-0.1.0-py3-none-any.whl
Size 33.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4a876b9a257169503e24d1d9482a9f63729fbfaab14fe2a50affff07a3ff6d08
BLAKE2b-256 checksum
How to use checksums
3d738577fe4ff98c24abe85c470f66cee4c6a5157ebeb1ec2bdb87c3e2999888
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 22, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.4

2 release files

0.1.3

2 release files

0.1.1

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page