Convert Python functions to JSON schemas using Pydantic, Compatible with LLM Function Calling.
Project description
Func2JSON
Description
Func2JSON is a Python library designed to convert Python functions into a standardized JSON format, which is particularly useful for API integration and AI function calling in applications like OpenAI's function calling.
Installation
Install Func2JSON using pip:
pip install func2json
Usage
Import the function and use it as follows:
from func2json import execf
def example_function(param1: str, param2: int) -> str:
"""Example function that takes a string and an integer."""
pass
json_struct = execf(example_function)
print(json_struct)
Output:
{
"type": "function",
"function": {
"name": "example_function",
"description": "Example function that takes a string and an integer.",
"parameters": {
"type": "object",
"properties": {
"param1": {
"type": "string",
"description": "param1 description"
},
"param2": {
"type": "integer",
"description": "param2 description"
}
},
"required": ["param1", "param2"]
}
}
}
Features
- Converts function signature and docstring into JSON.
- Handles parameter types and descriptions.
- Supports optional parameters.
- Gracefully handles functions without annotations or docstrings.
Requirements
- Python 3.10 or higher
- Dependencies:
- pydantic
- docstring_parser
Contributing
Contributions are welcome!
License
Func2JSON is licensed under the MIT License.
Contact
For questions or feedback, please contact thanabordee.noun@gmail.com.
Limitations
- Does not support functions with *args or **kwargs.
- Complex type annotations may be converted to strings.
FAQs
-
Q: Why use Func2JSON?
- A: To easily convert Python functions into a standardized JSON format for use in APIs and AI applications.
-
Q: Does it support async functions?
- A: Currently, only synchronous functions are supported.
Change Log
- 0.1: Initial release
- 0.1.1 Update Version
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
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 func2json-0.1.3.tar.gz.
File metadata
- Download URL: func2json-0.1.3.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
381b980912a2f0f7c17a7062b46b8748913ccefada55a109d3813001aad85817
|
|
| MD5 |
dc5ccdee54d4d9f60ca75aafcc471843
|
|
| BLAKE2b-256 |
a7ad088d88b50f5367e0757145328ea6ec1e88f695496f51966303ca5c199a01
|
File details
Details for the file func2json-0.1.3-py3-none-any.whl.
File metadata
- Download URL: func2json-0.1.3-py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48b70c2ffb679bfafc72c89c0499763bb1d32ae1e3ef65b87766b15250d1b45a
|
|
| MD5 |
43d390b1aeda8938659ba80f08f46cf5
|
|
| BLAKE2b-256 |
b81359345097196854842ddbf840eda8239cf28ee7c5ab7f1e9fd57692fd5377
|