Skip to main content

Python decorator for defining tools-rs LLM tool functions

Project description

tools-rs

Python decorator for defining tools-rs LLM tool functions.

What is this?

tools-rs is a Rust framework for building, registering, and executing tools with automatic JSON schema generation for LLM integration. Its Python FFI adapter lets end users write tools in Python that get loaded into a Rust application.

This pip package provides the @tool decorator so your IDE can resolve imports, provide autocomplete, and type-check your tool definitions. At runtime, the Rust adapter auto-injects the same decorator — this package is optional and only needed for IDE support.

Usage

pip install tools-rs

Then write your tools:

from tools_rs import tool

@tool(requires_approval=False, cost_tier=1)
def weather(city: str, units: str = "celsius") -> str:
    """Get current weather for a city.

    Args:
        city: City name to look up
        units: Temperature unit (celsius or fahrenheit)
    """
    import requests
    resp = requests.get(f"https://wttr.in/{city}?format=j1")
    return resp.json()["current_condition"][0]["temp_C"]

The @tool decorator extracts:

  • Name from the function name
  • Description from the docstring (first paragraph)
  • Parameter schema from type hints (str"string", int"integer", Literal["a", "b"]enum, etc.)
  • Parameter descriptions from Google-style Args: docstring blocks
  • Required vs optional from default values
  • Metadata from decorator keyword arguments

Supported type hints

Python type JSON Schema
str {"type": "string"}
int {"type": "integer"}
float {"type": "number"}
bool {"type": "boolean"}
list[T] {"type": "array", "items": ...}
Literal["a", "b"] {"type": "string", "enum": ["a", "b"]}
Optional[T] {"anyOf": [..., {"type": "null"}]}

License

MIT

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

tools_rs-0.3.3.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

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

tools_rs-0.3.3-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file tools_rs-0.3.3.tar.gz.

File metadata

  • Download URL: tools_rs-0.3.3.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for tools_rs-0.3.3.tar.gz
Algorithm Hash digest
SHA256 2807d03505571648b44a2b6b4d8b8be3c4d2ace10ad8f3660baacc7f4dfbfd44
MD5 fcbb41d4b528b13fa2d49821b50a9007
BLAKE2b-256 88be6a2bfa9e6fa7bbc30129b928e522ac63128d0ce932e2bc07d3ef866142a7

See more details on using hashes here.

File details

Details for the file tools_rs-0.3.3-py3-none-any.whl.

File metadata

  • Download URL: tools_rs-0.3.3-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for tools_rs-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2e106506164d004647ae5ee8038a4e973fae7b799bc0a1a266713fc130e786bd
MD5 ee31ab2020f16610c614f8e71980c122
BLAKE2b-256 1cffb55d094d6461bb15d5670eb7b690590fe779f2ada67cd986e72402fbe3e7

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