Python client library for the Journal Gateway protocol
Project description
journal-gateway-client
Python client library for the Journal Gateway protocol. Runs a WebSocket server that gateways connect to, authenticates them, auto-pulls their tools and skills, and lets you call tools.
Install
pip install journal-gateway-client
Usage
import asyncio
from journal_gateway_client import GatewayServer, TokenValidationResult
async def validate_token(token: str) -> TokenValidationResult | None:
# Return a TokenValidationResult on success, None on failure
if token == "gw_valid":
return TokenValidationResult(organization_id="org_123")
return None
async def main() -> None:
server = GatewayServer(validate_token=validate_token, port=8080)
server.on_gateway_connected = lambda gw: print("connected:", gw.id, gw.integrations)
server.on_gateway_updated = lambda gw: print("tools/skills changed:", gw.id)
server.on_gateway_disconnected = lambda gw: print("disconnected:", gw.id)
await server.start()
# Call a tool on a connected gateway
result = await server.call_tool("postgresql", "query", {"sql": "SELECT 1"})
print(result.content)
await server.stop()
asyncio.run(main())
Key APIs
start()/stop()— lifecyclecall_tool(integration_id, tool_name, arguments, timeout=60.0)— execute a tool call on any gateway that provides the integrationcall_tool_for_org(organization_id, integration_id, tool_name, arguments, timeout=90.0)— same, scoped to an organization with automatic load balancing and retry on a different gatewayget_tools_for_org(organization_id)— list deduplicated tools across all gateways for an orgget_versions(gateway_id)/get_tools(gateway_id)/get_skills(gateway_id)— explicit pulls from a specific gatewayconnected_gateways— all currently connected gateways
Callbacks
Set these attributes on the server instance:
on_gateway_connected(gateway)— fired after a gateway authenticates and its initial tools/skills are pulledon_gateway_updated(gateway)— fired when a gateway's tools or skills change at runtimeon_gateway_disconnected(gateway)— fired when a gateway disconnects
Telemetry
The library has no telemetry dependency of its own. Two constructor arguments let you wire it into your logging/tracing stack:
get_trace_context— called on everycall_tool. Return the active W3C trace context as{"traceparent": ..., "tracestate": ...}and it is propagated on thetool_callmessage; the gateway parents itsgateway.tool_callspan onto it, so the remote tool execution appears in your distributed trace. ReturnNonewhen there is no active span.on_socket_error(error, gateway)— called when a gateway socket drops abnormally (e.g. a connection reset).gatewayisNoneif the socket errored before completing the handshake. If the gateway had connected,on_gateway_disconnectedfires as usual. When not provided, unexpected connection errors fall back to thejournal_gateway_clientlogger — bind this callback if you want to route them into your own error tracking.
Example wiring with OpenTelemetry and a logger:
from opentelemetry import propagate
def trace_context():
carrier: dict[str, str] = {}
propagate.inject(carrier)
if "traceparent" not in carrier:
return None
return {"traceparent": carrier["traceparent"], "tracestate": carrier.get("tracestate")}
server = GatewayServer(
validate_token=validate_token,
port=8080,
get_trace_context=trace_context,
on_socket_error=lambda err, gw: logger.error(
"gateway socket error", exc_info=err, extra={"gateway_id": gw.id if gw else None}
),
)
Full documentation
See the root README for protocol details, gateway configuration, and architecture.
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
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 journal_gateway_client-0.7.0.tar.gz.
File metadata
- Download URL: journal_gateway_client-0.7.0.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf3cb656ad8c6506bd216be4a0c07cc595a05112f084890db8a822498dd89d28
|
|
| MD5 |
92be19dba76d9d0cfdb1f33ebcc15ce8
|
|
| BLAKE2b-256 |
6beb8807f1b836b4e4e30bd5781f4003a89b07007bd0721cbf1c8062a5592bbf
|
File details
Details for the file journal_gateway_client-0.7.0-py3-none-any.whl.
File metadata
- Download URL: journal_gateway_client-0.7.0-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
812eb06b15b5e670d562060d7fae91939629dcd81a1a362729fe0bbbbeccceaa
|
|
| MD5 |
3f428725b04dcbf7d3f758eb3443a35a
|
|
| BLAKE2b-256 |
a66159fa0a7f549e3512401b4832d253a9bcb13a1e7a976c76202142db3d6998
|