UTCP communication protocol plugin for HTTP, SSE, and streamable HTTP, plus an OpenAPI converter.
Project description
UTCP HTTP Plugin
HTTP communication protocol plugin for UTCP, supporting REST APIs, Server-Sent Events (SSE), and streaming HTTP.
Features
- HTTP/REST APIs: Full support for GET, POST, PUT, DELETE, PATCH methods
- Authentication: API key, Basic Auth, OAuth2 support
- Server-Sent Events (SSE): Real-time event streaming
- Streaming HTTP: Large response handling with chunked transfer
- OpenAPI Integration: Automatic tool generation from OpenAPI specs
- Path Parameters: URL templating with
{parameter}syntax - Custom Headers: Static and dynamic header support
Installation
pip install utcp-http
Quick Start
from utcp.utcp_client import UtcpClient
# Basic HTTP API
client = await UtcpClient.create(config={
"manual_call_templates": [{
"name": "api_service",
"call_template_type": "http",
"url": "https://api.example.com/users/{user_id}",
"http_method": "GET"
}]
})
result = await client.call_tool("api_service.get_user", {"user_id": "123"})
Configuration Examples
Basic HTTP Request
{
"name": "my_api",
"call_template_type": "http",
"url": "https://api.example.com/data",
"http_method": "GET"
}
With API Key Authentication
{
"name": "secure_api",
"call_template_type": "http",
"url": "https://api.example.com/data",
"http_method": "POST",
"auth": {
"auth_type": "api_key",
"api_key": "${API_KEY}",
"var_name": "X-API-Key",
"location": "header"
}
}
OAuth2 Authentication
{
"name": "oauth_api",
"call_template_type": "http",
"url": "https://api.example.com/data",
"auth": {
"auth_type": "oauth2",
"client_id": "${CLIENT_ID}",
"client_secret": "${CLIENT_SECRET}",
"token_url": "https://auth.example.com/token"
}
}
Server-Sent Events (SSE)
{
"name": "event_stream",
"call_template_type": "sse",
"url": "https://api.example.com/events",
"event_type": "message",
"reconnect": true
}
Streaming HTTP
{
"name": "large_data",
"call_template_type": "streamable_http",
"url": "https://api.example.com/download",
"chunk_size": 8192
}
OpenAPI Integration
Automatically generate UTCP tools from OpenAPI specifications:
from utcp_http.openapi_converter import OpenApiConverter
converter = OpenApiConverter()
manual = await converter.convert_openapi_to_manual(
"https://api.example.com/openapi.json"
)
client = await UtcpClient.create()
await client.register_manual(manual)
Error Handling
from utcp.exceptions import ToolCallError
import httpx
try:
result = await client.call_tool("api.get_data", {"id": "123"})
except ToolCallError as e:
if isinstance(e.__cause__, httpx.HTTPStatusError):
print(f"HTTP {e.__cause__.response.status_code}: {e.__cause__.response.text}")
Related Documentation
Examples
For complete examples, see the UTCP examples repository.
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 utcp_http-1.1.3.tar.gz.
File metadata
- Download URL: utcp_http-1.1.3.tar.gz
- Upload date:
- Size: 36.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
748353b9b42012f928a1aa2c0e05d6555c53492a7b880d34c30708b3e8fe9d1d
|
|
| MD5 |
f99b532144ff914d625bf9ef5c56fa0c
|
|
| BLAKE2b-256 |
19ecec949e9774fde8b255d1c3df9a55b55f6e45cfaf782adc53bb18494136fd
|
File details
Details for the file utcp_http-1.1.3-py3-none-any.whl.
File metadata
- Download URL: utcp_http-1.1.3-py3-none-any.whl
- Upload date:
- Size: 30.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2eebcf8453e2275d8123a88f700209b75b1b8267a56b1bfd2e3b0c08a2080bc9
|
|
| MD5 |
5a40816662de99da64dcd39a909879cf
|
|
| BLAKE2b-256 |
6a62d5bacde19b50c690c7f1a97b2950cf5d3f568ef3aeaffe3ac88ad25ad09d
|