Skip to main content

A library for managing tool registries

Project description

ToolRegistry

中文版

A Python library for managing and executing tools in a structured way.

Features

  • Tool registration and management
  • JSON Schema generation for tool parameters
  • Tool execution and result handling
  • Support for both synchronous and asynchronous tools
  • Support MCP sse, OpenAPI tools

Full Documentation

Full documentation is available at https://toolregistry.lab.oaklight.cn

Installation

Basic Installation

Install the core package (requires Python >= 3.8):

pip install toolregistry

Installing with Extra Support Modules

Extra modules can be installed by specifying extras in brackets. For example, to install specific extra supports:

pip install toolregistry[mcp,openapi]

Below is a table summarizing available extra modules:

Extra Module Python Requirement Example Command
mcp Python >= 3.10 pip install toolregistry[mcp]
openapi Python >= 3.8 pip install toolregistry[openapi]

Examples

OpenAI Implementation

The openai_tool_usage_example.py shows how to integrate ToolRegistry with OpenAI's API.

Cicada Implementation

The cicada_tool_usage_example.py demonstrates how to use ToolRegistry with the Cicada MultiModalModel.

Basic Tool Invocation

This section demonstrates how to invoke a basic tool. Example:

from toolregistry import ToolRegistry

registry = ToolRegistry()

@registry.register
def add(a: float, b: float) -> float:
    """Add two numbers together."""
    return a + b

available_tools = registry.get_available_tools()

print(available_tools) # ['add']

add_func = registry.get_callable('add')
print(type(add_func)) # <class 'function'>
add_result = add_func(1, 2)
print(add_result) # 3

add_func = registry['add']
print(type(add_func)) # <class 'function'>
add_result = add_func(4, 5)
print(add_result) # 9

For more usage examples, please refer to Documentation - Usage

MCP Integration

The ToolRegistry provides first-class support for MCP (Model Context Protocol) tools:

registry.register_mcp_tools("http://localhost:8000/mcp/sse")

# Get all tools JSON including MCP tools
tools_json = registry.get_tools_json()

OpenAPI Integration

ToolRegistry supports integration with OpenAPI for interacting with tools using a standardized API interface:

registry.register_openapi_tools("http://localhost:8000/") # by providing baseurl
registry.register_openapi_tools("./openapi_spec.json", "http://localhost/") # by providing local OpenAPI spec file and base url

# Get all tools JSON including OpenAPI tools
tools_json = registry.get_tools_json()

Static Method Integration and Hub of Tools

ToolRegistry supports integration of static methods and predefined hub tools for enhanced functionality and organization.

Static Method Integration

Static methods from Python classes can be registered as tools using the StaticMethodIntegration module. This allows developers to extend ToolRegistry by creating custom tool classes with reusable static methods.

Example:

from toolregistry import ToolRegistry

class CustomTools:
    @staticmethod
    def greet(name: str) -> str:
        return f"Hello, {name}!"

registry = ToolRegistry()
registry.register_static_tools(CustomTools) 

# List registered tools
print(registry.get_available_tools())
# Output: ['greet']

Hub Tools

Hub tools encapsulate commonly used functionalities as static methods in classes. These tools are grouped for better organization and reusability.

Examples of available hub tools include:

  • Calculator: Basic arithmetic, scientific operations, statistical functions, financial calculations, and more.
  • FileOps: File manipulation operations like diff generation, patching, and verification.
  • Filesystem: Comprehensive file system operations such as directory listing, file reading/writing, and path manipulation.
  • UnitConverter: Extensive unit conversion tools for temperature, length, weight, and more.

To register hub tools:

from toolregistry import ToolRegistry
from toolregistry.hub import Calculator

registry = ToolRegistry()
registry.register_static_tools(Calculator, with_namespace=True)

# Get available tools list
print(registry.get_available_tools())
# Output: ['Calculator.add', 'Calculator.subtract', ..., 'Calculator.multiply', ...]

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

toolregistry-0.4.2.tar.gz (28.1 kB view details)

Uploaded Source

Built Distribution

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

toolregistry-0.4.2-py3-none-any.whl (31.7 kB view details)

Uploaded Python 3

File details

Details for the file toolregistry-0.4.2.tar.gz.

File metadata

  • Download URL: toolregistry-0.4.2.tar.gz
  • Upload date:
  • Size: 28.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for toolregistry-0.4.2.tar.gz
Algorithm Hash digest
SHA256 d3e26ea4fb25ad835a591c47f8c9319165386eda95d4b4bb7e6fe6c40500402b
MD5 86b87a7b8e0d5836070c5ccc42c5249d
BLAKE2b-256 292d9fdeb067f25cc3e987e7c81f762d4b900beae4a4c2b9c4e17122593cbf5d

See more details on using hashes here.

File details

Details for the file toolregistry-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: toolregistry-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 31.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for toolregistry-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 09b183cbaf19b8c4a815ba5c157cf49e2d7e529e1528e7a0cb64c542cb2c960f
MD5 87879231a0e9cf08fc3eb4630f4990d8
BLAKE2b-256 0bb3e067abe3d4ef3e066bd1e180df9ecf4505aa31529789e970de410958014b

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