simpletool
Project description
Simpletool
SimpleTool is a lightweight Python framework designed for creating simple, strict, and explicit type-safe tools with minimal complexity. It supports both synchronous and asynchronous execution patterns, with the async functionality available in the dedicated simpletool.asyncio module. It embodies some of the Python design Zen principles, such as "Simple is better than complex" and "Explicit is better than implicit".
⚠️ Disclaimer [2025-03]
- 🛠️ Under active development: Expect frequent updates, bugs, and breaking changes.
- 🤓 Check the release notes: Always check the release notes to verify if there are any breaking changes.
💡 Overview
Simpletool is a powerful SDK that provides a structured approach to building tools with:
- Standardized input and output content types
- Automatic JSON schema generation
- Both synchronous and asynchronous support
- Environment variable handling
- Timeout management in asyncio (def. 60s)
⚡️ Architecture Overview
classDiagram
class Content {
<<abstract>>
+type: Literal["text", "image", "file", "error"]
AutoValidation
}
class TextContent {
+text: str
}
class ImageContent {
+data: str
+description: str
+mime_type: str
}
class FileContent {
+data: str
+file_name: str
+mime_type: str
AutoValidation
}
class ErrorContent {
+code: int
+message: str
+data: Any
}
class SimpleTool {
<<abstract>>
+name: str
+description: str
+input_model: Type[SimpleInputModel]
+input_schema: Dict (auto generated)
+output_schema: Dict (auto generated)
+get_env(arguments: dict, prefix: str)
+run(arguments: dict) Sequence[Content]
}
class AsyncSimpleTool {
<<abstract>>
+name: str
+description: str
+input_model: Type[SimpleInputModel]
+input_schema: Dict (auto generated)
+output_schema: Dict (auto generated)
+get_env(arguments: dict, prefix: str)
+run(arguments: dict) Sequence[Content]
}
class SimpleInputModel {
<<interface>>
AutoValidation
}
SimpleTool <-- SimpleInputModel: arguments (Dict[str, Any])
SimpleTool <-- SimpleInputModel: input_model (Type[SimpleInputModel])_
AsyncSimpleTool <-- SimpleInputModel: arguments (Dict[str, Any])
AsyncSimpleTool <-- SimpleInputModel: input_model (Type[SimpleInputModel])_
Content --|> TextContent
Content --|> ImageContent
Content --|> FileContent
Content --|> ErrorContent
SimpleTool --> Content: returns Sequence[Content]
AsyncSimpleTool --> Content: returns Sequence[Content]
💻 Core Components
SimpleTool Base Class and Key Features
The SimpleTool class provides a robust framework for building tools with the following key features:
-
Input Validation:
- Uses Pydantic models for strict input validation (SimpleInputModel)
- Automatic type checking and conversion based on Pydantic models
- SimpleInputModel have own model_json_schema (removes
titlesanddescriptionsfrom the schema) for easy dump to text schema
-
Output Type Management:
- Supports multiple content types (text, image, file, resource, error) for flexible output representation
- Strict output type checking allow List or Seqence of Content Types Objects
-
Dynamic Schema Generation:
- Input model needs to be defined as child of
SimpleInputModelType and assign toinput_modelattribute insideSimpleTool- them magic begins and automaticly:- Automatically creates output JSON schemas (
output_schema/output_model) based on the definedrunmethod typing - Automatically creates input JSON schemas (
input_schema) based on the input model
- Automatically creates output JSON schemas (
- Input model needs to be defined as child of
-
Execution Models:
- Synchronous Execution: Default mode with the standard
runmethod - Asynchronous Execution: Available via the
simpletool.asynciomodule with theAsyncSimpleToolclass - Configurable timeout management
- Context manager for easy resource management release
- Synchronous Execution: Default mode with the standard
-
Environment Integration:
- Easy retrieval of environment variables via the
envparameter - Support for random API key selection from provided list of API keys
- Easy retrieval of environment variables via the
Content Types
Simpletool defines several content types to standardize tool inputs and outputs:
TextContent: Represents text-based contentImageContent: Handles base64 encoded images with optional metadataFileContent: Represents files with base64 encoded dataResourceContent: Manages external resource referencesErrorContent: Provides structured error reportingBoolContents: Simple boolean content type
📦 Installation
Install the package using pip:
pip install simpletool
🔄 Quick Start
🛠️ Creating a Synchronous Tool
from simpletool import SimpleTool, SimpleInputModel, Sequence, Field
from simpletool.types import TextContent
class InputModel(SimpleInputModel):
name: str = Field(description="Name to greet")
class MyTool(SimpleTool):
name = "greeting_tool"
description = "A simple greeting tool"
input_model = InputModel
def run(self, arguments: dict) -> Sequence[TextContent]:
# Validation and parsing of input arguments
arg: InputModel = InputModel(**arguments)
return [TextContent(text=f"Hello, {arg.name}!")]
🛠️ Creating an Asynchronous Tool
from simpletool.asyncio import AsyncSimpleTool
from simpletool import SimpleInputModel, Sequence, Field
from simpletool.types import TextContent
class InputModel(SimpleInputModel):
name: str = Field(description="Name to greet")
class MyAsyncTool(AsyncSimpleTool):
name = "greeting_tool"
description = "A simple greeting tool"
input_model = InputModel
async def run(self, arguments: dict) -> Sequence[TextContent]:
# Validation and parsing of input arguments
arg: InputModel = InputModel(**arguments)
return [TextContent(text=f"Hello, {arg.name}!")]
📝 Development Guidelines
- Inherit Tool model from
SimpleTool(orAsyncSimpleToolfor async tools) - Define an
input_modelusing Pydantic (SimpleInputModel) - Implement the
runmethod (synchronous or asynchronous depending on your base class) - Return a list/sequence of content types
- Use the
envparameter for environment variables
📝 Contributing
Contributions are welcome! Please follow Python best practices and maintain the existing code style.
📄 License
This project is licensed under the MIT License.
📞 Contact
Contributions are welcome! Please submit a pull request with your changes.
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 simpletool-0.0.32.tar.gz.
File metadata
- Download URL: simpletool-0.0.32.tar.gz
- Upload date:
- Size: 29.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d95fd48c095ce9c97439bd9934cedcb04acc9c509d60f92c7f3a048b20e0b4d
|
|
| MD5 |
78824d05e2840dfcacf76c1b5dd876fb
|
|
| BLAKE2b-256 |
9c683f204fcea84366f1456b32dfc0b5a1ab45c0ac45c8c2c453a57fc876906e
|
Provenance
The following attestation bundles were made for simpletool-0.0.32.tar.gz:
Publisher:
publish.yml on getsimpletool/simpletool-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
simpletool-0.0.32.tar.gz -
Subject digest:
2d95fd48c095ce9c97439bd9934cedcb04acc9c509d60f92c7f3a048b20e0b4d - Sigstore transparency entry: 186672239
- Sigstore integration time:
-
Permalink:
getsimpletool/simpletool-python@2073691974335252c09d098cdce650f598eb195c -
Branch / Tag:
refs/tags/v0.0.32 - Owner: https://github.com/getsimpletool
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2073691974335252c09d098cdce650f598eb195c -
Trigger Event:
release
-
Statement type:
File details
Details for the file simpletool-0.0.32-py2.py3-none-any.whl.
File metadata
- Download URL: simpletool-0.0.32-py2.py3-none-any.whl
- Upload date:
- Size: 23.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94698736b882ff67e5f2a73e2f9cf5e362a49cc142dd671cd21a2c65acac6d32
|
|
| MD5 |
c7f869bfae95c032fd69188da2b29f23
|
|
| BLAKE2b-256 |
a141c864f9a355c3ccf4e8c485cb8f0f99679b98bb721ab04be5b633a6729600
|
Provenance
The following attestation bundles were made for simpletool-0.0.32-py2.py3-none-any.whl:
Publisher:
publish.yml on getsimpletool/simpletool-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
simpletool-0.0.32-py2.py3-none-any.whl -
Subject digest:
94698736b882ff67e5f2a73e2f9cf5e362a49cc142dd671cd21a2c65acac6d32 - Sigstore transparency entry: 186672240
- Sigstore integration time:
-
Permalink:
getsimpletool/simpletool-python@2073691974335252c09d098cdce650f598eb195c -
Branch / Tag:
refs/tags/v0.0.32 - Owner: https://github.com/getsimpletool
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2073691974335252c09d098cdce650f598eb195c -
Trigger Event:
release
-
Statement type: