OpenAPI2Callables
OpenAPI2Callables is a Python library for parsing and projecting OpenAPI endpoints into OpenAI/GenericLLM compatible Tools.
It's designed to be flexible enough for non-LLM directed usage as well.
Motivation
OpenAPI is a widely used standard for describing RESTful APIs. OpenAI specified a fairly simple tool calling API. OpenAPI2Callables bridges the gap between OpenAPI and OpenAI by providing a way to parse OpenAPI schemas and project them into OpenAI compatible tool definitions and provide a 'proxy' to those OpenAPI functions from a calling service.
i.e. One can separate responsibilities from a tool calling service (toolshed?), and the actual LLM interacting client function, such as a chatservice or a local CLI.
Example
Here's an example of the interaction between a User, an App, a Toolshed, and an LLM:
The User interacts exclusively with the App. On initialisation of the App, the App uses OpenAPI2Callables to query and parse the OpenAPI schema from the Toolshed. The App then projects the OpenAPI schema into OpenAI compatible tool definitions. When the User asks a question, the App calls the LLM with the question, including the tools generated.
The LLM may then call the App with a tool call, including the tool ID and arguments. The App then calls the Toolshed with the tool call (via the APITool.call interface, i.e. 'tool(*args,**kwargs)), and the Toolshed returns the result. The App then returns the result to the LLM, which then returns a synthesised result to the User (via the App, again).
sequenceDiagram
actor User
participant App
participant Toolshed
critical OpenAPI2Callables(toolshed/openapi.json)
activate Toolshed
App ->> Toolshed: `GET /openapi.json`
Toolshed ->> App: {schema}
deactivate Toolshed
App ->> App: OpenAPI2Callables(schema) -> [APITool(operationId='get_widgets_bandled'...]
end
User->>App: "How many widgets were bangled in the past week?"
App ->> LLM: {'role':'user', 'content': "How many widgets were bangled in the past week?", tools=[APITool(operationId='get_widgets_bandled'...)...]}
activate LLM
LLM ->> App: `ToolCall(function='get_widgets_bangled', arguments={"since":"2025-02-02"}, id=1)`
deactivate LLM
critical Call get_widgets_bangled
activate App
App ->> App: tools['get_widgets_bangled'](since='2025-02-02')
App ->> Toolshed: `get toolshed/get_widgets_bangled?since=2025-02-02`
activate Toolshed
Toolshed ->> App: "{widget1:0, widget2:500, widget3:...}"
deactivate Toolshed
deactivate App
end
App ->> LLM: {'role':'tool', 'tool_id':1, 'content': "{widget1:0, widget2:500, widget3:...}"}
activate LLM
LLM ->> App: {'role':'assistant', 'content':`There have been 500+...= 28,462 widgets bangled since 2025-02-02`}
deactivate LLM
App ->> User: `There have been 500+...= 28,462 widgets bangled since 2025-02-02`
Features
- Parse OpenAPI JSON/YAML schemas and extract basic parameter and response configurations
- Host a sample server for testing and demonstration
- Project tool definitions into OpenAI compatible tool definitions
- Provide runtime callbacks for tool execution
Installation
You can install OpenAPI2Callables using pip:
pip install openapi2callables
Quick Start
Here's a simple example of how to use OpenAPI2Callables:
from openapi2callables import parse_spec, get_spec, APITool
# Load an OpenAPI specification
spec_url = "https://example.com/api/openapi.json"
spec = get_spec(spec_url)
# Parse the specification
tools = parse_spec(spec)
# Use the parsed tools in your application
tools = {}
for tool in tool_specs:
print(f"Tool: {tool.name}")
print(f"Description: {tool.description}")
print(f"Parameters: {tool.parameters}")
print("---")
tools[tool.name] = APITool(tool)
# Use the tools in your application
response = tools["get_user"](user_id=123)
print(response)
CLI Usage
OpenAPI2Callables also provides a command-line interface:
openapi2callables parse https://example.com/api/openapi.json # Parse an OpenAPI specification and dump the specs to the console, mostly for debugging
openapi2callables serve https://example.com/api/openapi.json # Start a sample server for testing and demonstration
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Roadmap
- [ ] Provide request authorization passthrough
- [ ] Enhance error handling and validation
- [ ] Add support for more complex OpenAPI features
- [ ] Improve documentation and examples
Metadata
Release files for openapi2callables 0.1.1
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 | |
|---|---|---|---|---|
| openapi2callables-0.1.1.tar.gz | 23.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| openapi2callables-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 41.5 kB
Release files / openapi2callables-0.1.1.tar.gz
| Download URL | openapi2callables-0.1.1.tar.gz |
|---|---|
| Size | 23.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
277ce84169614c74ca8c5b1601a5a0db75d7484c23a1978b80c150e7f1a5ada8
|
|
BLAKE2b-256 checksum How to use checksums |
bbb52c4aaa957f2cf00203d65cbc4ffd431752bbca2b0660c21de29cedcfb79b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.6.14
|
Release files / openapi2callables-0.1.1-py3-none-any.whl
| Download URL | openapi2callables-0.1.1-py3-none-any.whl |
|---|---|
| Size | 17.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
66fa249dbdb71ab39636f3b241cae3288e5e4c2946093a2862866515050bab77
|
|
BLAKE2b-256 checksum How to use checksums |
cec554cce14e61cac7ff51ab7b557c545bf94b6b3410c981521888853c982797
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.6.14
|
Security for openapi2callables 0.1.1
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.