Skip to content
This repository was archived by the owner on Apr 29, 2025. It is now read-only.

Commit 7791721

Browse files
committed
0.0.30
1 parent 4aacd47 commit 7791721

11 files changed

+1475
-507
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/),
66
and this project adheres to [SimpleTool](https://github.com/nchekwa/simpletool-python/tree/master).
77

8+
9+
## [0.0.30] - 2025-03-22
10+
11+
### Changed
12+
- move async version to `asyncio` module -> `simpletool.asyncio`
13+
- by default use sync version as we want to support both `sync` and `async`
14+
- we will only handle passing `env` via argument called `env` (not env_vars or resources.env like it was before)
15+
816
## [0.0.20] - 2025-01-21 Milestone Alpha1
917

1018
### Added:

README.md

+52-21
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Simpletool
22

3-
SimpleTool is a lightweight, async-first Python framework designed for creating simple, strict, and explicit type-safe tools with minimal complexity. It embodies some of the Python design Zen principles, such as "Simple is better than complex" and "Explicit is better than implicit".
3+
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".
44

5-
## ⚠️ Disclaimer [2025-01]
5+
## ⚠️ Disclaimer [2025-03]
66

77
* 🛠️ __Under active development__: Expect frequent updates, bugs, and breaking changes.
88
* 🤓 __Check the release notes__: Always check the [release notes](./CHANGELOG.md) to verify if there are any breaking changes.
@@ -12,19 +12,14 @@ SimpleTool is a lightweight, async-first Python framework designed for creating
1212
Simpletool is a powerful SDK that provides a structured approach to building tools with:
1313
- Standardized input and output content types
1414
- Automatic JSON schema generation
15-
- Async support
15+
- Both synchronous and asynchronous support
1616
- Environment variable handling
17-
- Timeout management (def. 60s)
18-
19-
20-
21-
## 💬 Example
22-
Check out the [tool_example.py](./tool_example.py) to see how to use Simpletool to create a simple, type-safe tool.
17+
- Timeout management in asyncio (def. 60s)
2318

2419
## ⚡️ Architecture Overview
2520

2621
```mermaid
27-
22+
// {{ ... }}
2823
classDiagram
2924
class Content {
3025
<<abstract>>
@@ -66,20 +61,34 @@ classDiagram
6661
+run(arguments: dict) Sequence[Content]
6762
}
6863
64+
class AsyncSimpleTool {
65+
<<abstract>>
66+
+name: str
67+
+description: str
68+
+input_model: Type[SimpleInputModel]
69+
+input_schema: Dict (auto generated)
70+
+output_schema: Dict (auto generated)
71+
+get_env(arguments: dict, prefix: str)
72+
+run(arguments: dict) Sequence[Content]
73+
}
74+
6975
class SimpleInputModel {
7076
<<interface>>
7177
AutoValidation
7278
}
7379
7480
SimpleTool <-- SimpleInputModel: arguments (Dict[str, Any])
7581
SimpleTool <-- SimpleInputModel: input_model (Type[SimpleInputModel])_
82+
AsyncSimpleTool <-- SimpleInputModel: arguments (Dict[str, Any])
83+
AsyncSimpleTool <-- SimpleInputModel: input_model (Type[SimpleInputModel])_
7684
7785
Content --|> TextContent
7886
Content --|> ImageContent
7987
Content --|> FileContent
8088
Content --|> ErrorContent
8189
8290
SimpleTool --> Content: returns Sequence[Content]
91+
AsyncSimpleTool --> Content: returns Sequence[Content]
8392
```
8493

8594
## 💻 Core Components
@@ -101,16 +110,17 @@ The `SimpleTool` class provides a robust framework for building tools with the f
101110

102111
- Input model needs to be defined as child of `SimpleInputModel` Type and assign to `input_model` attribute inside `SimpleTool` - them magic begins and automaticly:
103112
- Automatically creates output JSON schemas (`output_schema` / `output_model`) based on the defined `run` method typing
104-
- Automatically creates input JSON schemas (`input_schem`a) based on the input model
113+
- Automatically creates input JSON schemas (`input_schema`) based on the input model
105114

106-
- **Async Execution**:
107-
- Native async/await support
115+
- **Execution Models**:
116+
- **Synchronous Execution**: Default mode with the standard `run` method
117+
- **Asynchronous Execution**: Available via the `simpletool.asyncio` module with the `AsyncSimpleTool` class
108118
- Configurable timeout management
109-
- Contex manager for easy resource management release
119+
- Context manager for easy resource management release
110120

111121
- **Environment Integration**:
112-
- Easy retrieval of environment variables (`get_env`)
113-
- Support for random API key selection from provided list (`get_env`)
122+
- Easy retrieval of environment variables via the `env` parameter
123+
- Support for random API key selection from provided list of API keys
114124

115125
### Content Types
116126

@@ -133,7 +143,7 @@ pip install simpletool
133143

134144
## 🔄 Quick Start
135145

136-
### 🛠️ Creating a Tool
146+
### 🛠️ Creating a Synchronous Tool
137147

138148
```python
139149
from simpletool import SimpleTool, SimpleInputModel, Sequence, Field
@@ -147,6 +157,28 @@ class MyTool(SimpleTool):
147157
description = "A simple greeting tool"
148158
input_model = InputModel
149159

160+
def run(self, arguments: dict) -> Sequence[TextContent]:
161+
# Validation and parsing of input arguments
162+
arg: InputModel = InputModel(**arguments)
163+
164+
return [TextContent(text=f"Hello, {arg.name}!")]
165+
```
166+
167+
### 🛠️ Creating an Asynchronous Tool
168+
169+
```python
170+
from simpletool.asyncio import AsyncSimpleTool
171+
from simpletool import SimpleInputModel, Sequence, Field
172+
from simpletool.types import TextContent
173+
174+
class InputModel(SimpleInputModel):
175+
name: str = Field(description="Name to greet")
176+
177+
class MyAsyncTool(AsyncSimpleTool):
178+
name = "greeting_tool"
179+
description = "A simple greeting tool"
180+
input_model = InputModel
181+
150182
async def run(self, arguments: dict) -> Sequence[TextContent]:
151183
# Validation and parsing of input arguments
152184
arg: InputModel = InputModel(**arguments)
@@ -156,12 +188,11 @@ class MyTool(SimpleTool):
156188

157189
## 📝 Development Guidelines
158190

159-
- Inherit Tool model from `SimpleTool`
191+
- Inherit Tool model from `SimpleTool` (or `AsyncSimpleTool` for async tools)
160192
- Define an `input_model` using Pydantic (`SimpleInputModel`)
161-
- Implement the `run` method
193+
- Implement the `run` method (synchronous or asynchronous depending on your base class)
162194
- Return a list/sequence of content types
163-
- Use async/await for asynchronous operations
164-
195+
- Use the `env` parameter for environment variables
165196

166197
## 📝 Contributing
167198

0 commit comments

Comments
 (0)