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)→PairingInfogenerate_keypair()→KeyPairconnect(...)→ConnectResulthandle_callback(status, app_id, expires_at)→CallbackResultcreate_session(...)→GatewaySession
Client
GatewayClient.from_env()→ client from env varsGatewayClient.from_session(session)→ client from sessionclient.chat_completion(provider, model, messages, ...)→ChatCompletion
Session
session.is_valid()→ boolsession.is_expired()→ boolsession.time_remaining_seconds()→ intsession.time_remaining_formatted()→ str (MM:SS)session.get_resources_by_type(type)→ list of resourcessession.to_dict()/GatewaySession.from_dict(data)
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
glueco_sdk-0.1.0.tar.gz
(11.1 kB
view details)
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 glueco_sdk-0.1.0.tar.gz.
File metadata
- Download URL: glueco_sdk-0.1.0.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
199cd21f852615b1212d6ff44c44bcdf1a0efcebd4413a9997024f7f7f143d6d
|
|
| MD5 |
a30f9d403f1eb34878d99562106fc07b
|
|
| BLAKE2b-256 |
a39ba8a51727637b3a60842a07a71593f02c5eadb4511f5de2a67dfb83b15fa1
|
File details
Details for the file glueco_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: glueco_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
25931e2c302c256687dac24f74368dd9418d32876f0f06e61f65a5faaeb7e9c4
|
|
| MD5 |
22680047af33fced1f31c802250aa4b2
|
|
| BLAKE2b-256 |
1813c7f19dc4d19b7994a56a78bab85aa50317030372798ca9fb2187295c2312
|