Skip to main content

Python SDK for Glueco Gateway - PoP-authenticated access to LLM providers

Project description

Glueco SDK for Python

Python SDK for the Glueco Gateway with PoP (Proof-of-Possession) authentication.

Installation

pip install glueco-sdk

Or install from source:

pip install -e path/to/glueco-sdk

Quick Start

Option 1: Dynamic Connection (Recommended for User-Facing Apps)

import streamlit as st
from glueco_sdk import (
    connect, handle_callback, create_session,
    GatewayClient, AppInfo, PermissionRequest,
)

# 1. User enters pairing string
pairing_string = st.text_input("Pairing String")

# 2. Initiate connection
if st.button("Connect"):
    result = connect(
        pairing_string=pairing_string,
        app=AppInfo(name="My App", description="Example app"),
        requested_permissions=[
            PermissionRequest(resource_id="llm:openai", actions=["chat.completions"]),
            PermissionRequest(resource_id="llm:groq", actions=["chat.completions"]),
        ],
        redirect_uri=f"{st.get_script_run_ctx().session_id}/callback",
    )
    # Store pending connection
    st.session_state.pending_keypair = result.keypair
    st.session_state.pending_proxy_url = result.proxy_url
    # Redirect to approval
    st.markdown(f'<meta http-equiv="refresh" content="0;url={result.approval_url}">')

# 3. Handle callback (when user returns)
params = st.query_params
callback = handle_callback(params.get("status"), params.get("app_id"), params.get("expires_at"))

if callback.approved:
    session = create_session(
        proxy_url=st.session_state.pending_proxy_url,
        app_id=callback.app_id,
        keypair=st.session_state.pending_keypair,
        expires_at=callback.expires_at,
    )
    st.session_state.gateway_session = session

# 4. Make requests
session = st.session_state.get("gateway_session")
if session and session.is_valid():
    client = GatewayClient.from_session(session)
    response = client.chat_completion(
        provider="openai",
        model="gpt-4o",
        messages=[{"role": "user", "content": "Hello!"}],
    )
    print(response.content)

Option 2: Static Configuration (Server-Side Apps)

from glueco_sdk import GatewayClient

# Uses GATEWAY_PROXY_URL, GATEWAY_APP_ID, GATEWAY_PRIVATE_KEY env vars
client = GatewayClient.from_env()

response = client.chat_completion(
    provider="openai",
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(response.content)

Session Management

from glueco_sdk import GatewaySession

session = st.session_state.gateway_session

# Check validity
if session.is_valid():
    print(f"Session expires in: {session.time_remaining_formatted()}")
    
# Check available resources
llm_resources = session.get_resources_by_type("llm")
for resource in llm_resources:
    print(f"Provider: {resource.provider}, Actions: {resource.actions}")
    
# Serialize for storage
data = session.to_dict()
restored = GatewaySession.from_dict(data)

Supported Providers

Provider Resource ID Status
OpenAI llm:openai ✅ Ready
Groq llm:groq ✅ Ready
Gemini llm:gemini ✅ Ready
Anthropic llm:anthropic ⏳ Plugin needed
xAI Grok llm:grok ⏳ Plugin needed

API Reference

Connection Flow

  • parse_pairing_string(str)PairingInfo
  • generate_keypair()KeyPair
  • connect(...)ConnectResult
  • handle_callback(status, app_id, expires_at)CallbackResult
  • create_session(...)GatewaySession

Client

  • GatewayClient.from_env() → client from env vars
  • GatewayClient.from_session(session) → client from session
  • client.chat_completion(provider, model, messages, ...)ChatCompletion

Session

  • session.is_valid() → bool
  • session.is_expired() → bool
  • session.time_remaining_seconds() → int
  • session.time_remaining_formatted() → str (MM:SS)
  • session.get_resources_by_type(type) → list of resources
  • session.to_dict() / GatewaySession.from_dict(data)

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

glueco_sdk-0.2.0.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

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

glueco_sdk-0.2.0-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file glueco_sdk-0.2.0.tar.gz.

File metadata

  • Download URL: glueco_sdk-0.2.0.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for glueco_sdk-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f7b50a881cbf7f6d37dd408a0a4f3ef4e9dda87d547098e2a91adf030ccf429b
MD5 9c43f6806200746797881b50762919b0
BLAKE2b-256 5527d335398f7c2ac7e75c8eeeddcf6b23f1646688289e2e63f78c2af1f699ee

See more details on using hashes here.

File details

Details for the file glueco_sdk-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: glueco_sdk-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 16.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for glueco_sdk-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 83643059d64e795e81fc55b6012869a8b05a7bcc86866e561c493c0abe4a9bfd
MD5 1b4ea1eac3ce0f1b5b729375f82df9fc
BLAKE2b-256 7e4a20bd44c8e34e5a9525265c79f04c7bb35622fa91d0a47901ec1af5077e9f

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