Skip to main content

A toolkit for function calling, tool registration, and LiteLLM & OpenAI compatible tool integration with sync/async support.

Project description

Funcall

Don't repeat yourself!

Funcall is a Python library that simplifies the use of function calling, especially with OpenAI and Pydantic. Its core goal is to eliminate repetitive schema definitions and boilerplate, letting you focus on your logic instead of writing the same code again and again.

Motivation

If you use only the OpenAI SDK, enabling function call support requires you to:

  • Write your function logic
  • Manually define a schema for each function
  • Pass the schema through the tools parameter
  • Parse and handle the function call results yourself

This process is repetitive and error-prone. Funcall automates schema generation and function call handling, so you only need to define your function once.

Features

  • Automatically generate schemas from your function signatures and Pydantic models
  • Integrate easily with OpenAI's function calling API
  • No more manual, repetitive schema definitions—just define your function once
  • Easy to extend and use in your own projects

Installation

pip install funcall

Usage Example

import openai
from openai.types.responses import ResponseFunctionToolCall
from pydantic import BaseModel, Field
from funcall import Funcall

# Define your data model once
class AddForm(BaseModel):
    a: float = Field(description="The first number")
    b: float = Field(description="The second number")

# Define your function once, no need to repeat schema elsewhere
def add(data: AddForm) -> float:
    """Calculate the sum of two numbers"""
    return data.a + data.b

fc = Funcall([add])

resp = openai.responses.create(
    model="gpt-4.1",
    input="Use function call to calculate the sum of 114 and 514",
    tools=fc.get_tools(), # Automatically generates the schema
)

for o in resp.output:
    if isinstance(o, ResponseFunctionToolCall):
        result = fc.handle_function_call(o) # Automatically handles the function call
        print(result) # 628.0

Funcall can read the type hints and docstrings to generate the schema automatically:

[
    {
        "type": "function",
        "name": "add",
        "description": "Calculate the sum of two numbers",
        "parameters": {
            "type": "object",
            "properties": {
                "a": {
                    "type": "number",
                    "description": "The first number"
                },
                "b": {
                    "type": "number",
                    "description": "The second number"
                }
            },
            "required": ["a", "b"],
            "additionalProperties": false
        },
        "strict": true
    }
]

See the examples/ directory for more usage examples.

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

funcall-0.8.0.tar.gz (180.2 kB view details)

Uploaded Source

Built Distribution

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

funcall-0.8.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file funcall-0.8.0.tar.gz.

File metadata

  • Download URL: funcall-0.8.0.tar.gz
  • Upload date:
  • Size: 180.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.15

File hashes

Hashes for funcall-0.8.0.tar.gz
Algorithm Hash digest
SHA256 73646f0ccbed5b875083ea1968f907d8ed5b979a601daa651fae9b291a790bd4
MD5 f0b9a068ff93a4212df24b5b1e4f7ee9
BLAKE2b-256 8ffb9a7ae36ad87b8c79255b85c75e7b7d22d4eb71a3c0a1ce54c55f8d645bbc

See more details on using hashes here.

File details

Details for the file funcall-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: funcall-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.15

File hashes

Hashes for funcall-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 491631aeb6760b87a1e40b561cf9b1e60a5df645962b094a50aff5b87145e4d8
MD5 0ecad29829dbf5d8117cca514ff9b455
BLAKE2b-256 c4945aa7b7a0bf27f0b204cd58d7eb5ead18d9f5623c05c97fdf01d722c45974

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