Skip to main content

Python SDK générique pour Glassbox — pousser des events, demander un pre-flight, lire la config.

Project description

glassbox-py

SDK Python générique pour Glassbox — pousse des events, demande un pre-flight, lis la config.

PyPI Python License: MIT

Pourquoi

Glassbox est une PWA française qui rend lisible l'activité de tes agents IA — Claude Code, Hermes, n8n, etc. Ce SDK est la brique d'intégration générique : tout agent peut pousser ses événements et déléguer la décision d'autorisation des actions critiques (pre-flight bidirectionnel).

Pour Hermes spécifiquement, utilise plutôt hermes-glassbox qui s'auto-discover via entry_points. Ce paquet est utile quand tu écris ton propre adaptateur pour un autre agent.

Install

pip install glassbox-py
# ou avec logging structuré
pip install "glassbox-py[logging]"

Quickstart

from glassbox_sdk import Client, Descriptor

# Charge GLASSBOX_API_URL + GLASSBOX_API_TOKEN + GLASSBOX_AGENT_NAME depuis l'env.
client = Client.from_env()

# 1. Pousser un event timeline (fire-and-forget)
client.push_event(
    external_id="my-agent-evt-123",
    source="my-agent",
    type="tool_use",
    descriptor=Descriptor.file_write(path="docs/note.md", size=1234),
    duration_ms=42,
)

# 2. Demander un pre-flight (bloquant)
decision = client.preflight(
    descriptor=Descriptor.shell_command(command="rm -rf /tmp/cache"),
    client_request_id="uuid-pour-idempotence",
    wait=True,  # ouvre un SSE et attend la décision (auto ou humain)
)
if decision.is_approved:
    # exécute l'action
    pass
else:
    # bloque + log la raison
    print(f"Refusé: {decision.reason}")

Configuration

Trois sources, dans cet ordre de priorité :

  1. Args explicites : Client(config=Config(...))
  2. Env vars : Client.from_env() lit GLASSBOX_API_URL, GLASSBOX_API_TOKEN, GLASSBOX_AGENT_NAME, GLASSBOX_FAIL_MODE (reject par défaut)
  3. TOML : Client.from_toml("~/.glassbox/config.toml")
[glassbox]
api_url = "https://glassbox.call-for-me.com"
api_token = "${GLASSBOX_TOKEN}"  # interpolation env
agent_name = "My-Custom-Agent"
fail_mode = "reject"             # ou "log_only" en dev

Failsafe

  • fail_mode="reject" (défaut) : si Glassbox unreachable, action critique bloquée (Decision.is_rejected = True)
  • fail_mode="log_only" : action laissée passer + warning loggé. Réservé au développement local.

Builders Descriptor

Descriptor.file_write(path="docs/x.md", size=1234)
Descriptor.file_delete(path="x.md")
Descriptor.shell_command(command="ls -la")
Descriptor.network_read(url="https://api.example.com")
Descriptor.network_write(url="https://api.example.com", method="POST")
Descriptor.payment(amount=9.50, currency="EUR", provider="stripe")
Descriptor.external_message(recipient="@user", excerpt="Bonjour...")

# Ou raw
Descriptor(action_type="custom_op", descriptor={"foo": "bar"}, metadata={"client_id": "X"})

Écrire ton propre adaptateur

# myagent_glassbox/__init__.py
from glassbox_sdk import Client, Descriptor

client = Client.from_env()

@my_agent.on("before_tool_call")
def before_tool(tool_name, args):
    descriptor = my_agent_to_glassbox(tool_name, args)
    decision = client.preflight(descriptor=descriptor, client_request_id=...)
    if decision.is_rejected:
        raise PermissionError(decision.reason)

Environ 50-100 lignes typiques, le reste (HTTP / SSE / cache / failsafe / redact) est géré par le SDK.

Sécurité

  • Token jamais loggé.
  • Heuristique de redaction password / token / secret / api_key / auth / authorization — séparator-bounded (ne match pas tokenize, authorize, etc.).
  • HTTPS obligatoire (https:// requis sur api_url).
  • Pas de verify=False côté TLS.

Licence

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

glassbox_py-0.1.0.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

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

glassbox_py-0.1.0-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for glassbox_py-0.1.0.tar.gz
Algorithm Hash digest
SHA256 30f39eadf58fe05c635b192ee97609e55de3f0ff44f6398fd5b894fc108910bc
MD5 a0f4d1d5b680c76811aadf21ad87417a
BLAKE2b-256 aabaa5f70cbc11382c97013d5d277d78315d6c460af7a46e503dd33749105c3c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: glassbox_py-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for glassbox_py-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 46deb036957e4790f91328d67346df25143fa481d07ef6613737be300369a136
MD5 938d27eb2cf544e6b55692044bf3879a
BLAKE2b-256 247cc5a1dc55de5d998d46051e74807e1e51f8a58a52850018a2ac8370221c9c

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