UTCP Text Plugin
A text content plugin for UTCP. This plugin allows you to pass UTCP manuals or tool definitions directly as text content, without requiring file system access. It's browser-compatible and ideal for embedded configurations.
Features
- Direct Text Content: Pass UTCP manuals or tool definitions directly as strings.
- Browser Compatible: No file system access required, works in browser environments.
- JSON & YAML Support: Parses both JSON and YAML formatted content.
- OpenAPI Support: Automatically converts OpenAPI specs to UTCP tools with optional authentication.
- Base URL Override: Override API base URLs when converting OpenAPI specs.
- Tool Authentication: Supports authentication for generated tools from OpenAPI specs via
auth_tools.
Installation
pip install utcp-text
How It Works
The Text plugin operates in two main ways:
- Tool Discovery (
register_manual): It parses thecontentfield directly as a UTCP manual or OpenAPI spec. This is how theUtcpClientdiscovers what tools can be called. - Tool Execution (
call_tool): When you call a tool, the plugin returns thecontentfield directly.
Note: For file-based tool definitions, use the utcp-file plugin instead.
Quick Start
Here is a complete example demonstrating how to define and use tools with direct text content.
1. Define Tools with Inline Content
import asyncio
import json
from utcp.utcp_client import UtcpClient
# Define a UTCP manual as a Python dict, then convert to JSON string
manual_content = json.dumps({
"manual_version": "1.0.0",
"utcp_version": "1.0.2",
"tools": [
{
"name": "get_mock_user",
"description": "Returns a mock user profile.",
"tool_call_template": {
"call_template_type": "text",
"content": json.dumps({
"id": 123,
"name": "John Doe",
"email": "john.doe@example.com"
})
}
}
]
})
async def main():
# Create a client with direct text content
client = await UtcpClient.create(config={
"manual_call_templates": [{
"name": "inline_tools",
"call_template_type": "text",
"content": manual_content
}]
})
# List the tools to confirm it was loaded
tools = await client.list_tools()
print("Available tools:", [tool.name for tool in tools])
# Call the tool
result = await client.call_tool("inline_tools.get_mock_user", {})
print("\nTool Result:")
print(result)
if __name__ == "__main__":
asyncio.run(main())
2. Using with OpenAPI Specs
You can also pass OpenAPI specs directly as text content:
import asyncio
import json
from utcp.utcp_client import UtcpClient
openapi_spec = json.dumps({
"openapi": "3.0.0",
"info": {"title": "Pet Store", "version": "1.0.0"},
"servers": [{"url": "https://api.example.com"}],
"paths": {
"/pets": {
"get": {
"operationId": "listPets",
"summary": "List all pets",
"responses": {"200": {"description": "Success"}}
}
}
}
})
async def main():
client = await UtcpClient.create(config={
"manual_call_templates": [{
"name": "pet_api",
"call_template_type": "text",
"content": openapi_spec,
"base_url": "https://api.petstore.io/v1" # Optional: override base URL
}]
})
tools = await client.list_tools()
print("Available tools:", [tool.name for tool in tools])
if __name__ == "__main__":
asyncio.run(main())
Use Cases
- Embedded Configurations: Embed tool definitions directly in your application code.
- Browser Applications: Use UTCP in browser environments without file system access.
- Dynamic Tool Generation: Generate tool definitions programmatically at runtime.
- Testing: Define mock tools inline for unit tests.
Related Documentation
- Main UTCP Documentation
- Core Package Documentation
- File Plugin - For file-based tool definitions.
- HTTP Plugin - For calling real web APIs.
- CLI Plugin - For executing command-line tools.
Metadata
Release files for utcp-text 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| utcp_text-1.1.0.tar.gz | 7.9 kB | Without provenance | Details for utcp_text-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| utcp_text-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for utcp_text-1.1.0-py3-none-any.whl |
Total release size: 14.7 kB
Release files / utcp_text-1.1.0.tar.gz
| Download URL | utcp_text-1.1.0.tar.gz |
|---|---|
| Size | 7.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3d262bc0ac8727c9625260ed846de0736f48ebfbab35a19bef7aa1e1b33f573f
|
|
BLAKE2b-256 checksum How to use checksums |
51612313ed11e5c94a9f62a7d8c81894da5544b533618e830b47a030e425e4b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Release files / utcp_text-1.1.0-py3-none-any.whl
| Download URL | utcp_text-1.1.0-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9e28a77b9c95f69ad61c0b0b86c88303dfcdc5abf9b91ec8185a0904fedef550
|
|
BLAKE2b-256 checksum How to use checksums |
10db4b0de94ad0f5a210766389ed7a8408a5350318e6449d0d01c4cc65d67dd8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Security for utcp-text 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.