Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - swarmauri_tool_getmethodsignature Discord

Swarmauri Tool Get Method Signature

swarmauri_tool_getmethodsignature is a Swarmauri tool that parses Python source code with the standard-library ast module and returns the signature of a specified function or method, including its name, parameters, and return type. It is useful for documentation generation, refactoring assistants, agent-driven code review, and static introspection workflows.

Why Use Swarmauri Tool Get Method Signature

  • Inspect function and method signatures without importing source code.
  • Capture parameter names, annotations, and defaults in one call.
  • Detect overloaded definitions that share a single function name.
  • Distinguish synchronous functions from async def coroutines.
  • Reuse the same tool in agents, notebooks, scripts, and backend workflows.

FAQ

What does the tool return?
A dictionary with name, parameters, return_type, signature, and is_async. When multiple definitions share the requested name, it returns {"overloads": [...]} instead.

Does the tool execute the source code?
No. It uses ast.parse for purely static analysis and never imports or executes the supplied source.

What happens when the function is missing?
The tool returns {"error": "..."} describing the failure, including cases where the source cannot be parsed.

Are parameter defaults and annotations captured?
Yes. Each parameter entry includes name, annotation (when present), and default (when present), rendered back to source text via ast.unparse.

Features

  • Swarmauri ToolBase implementation registered as GetMethodSignatureTool.
  • Static ast-based parsing with no dynamic code execution.
  • Support for positional-only, keyword-only, *args, and **kwargs parameters.
  • Detection of overloaded functions sharing a single name.
  • Renders a human-readable signature string for each definition.
  • Supports Python 3.10, 3.11, 3.12, 3.13, and 3.14.

Installation

uv add swarmauri_tool_getmethodsignature
pip install swarmauri_tool_getmethodsignature

Usage

from swarmauri_tool_getmethodsignature import GetMethodSignatureTool

tool = GetMethodSignatureTool()
source = "def add(a: int, b: int = 0) -> int:\n    return a + b\n"
result = tool(source=source, method_name="add")

print(result["signature"])
# def add(a: int, b: int = 0) -> int

Examples

Inspect an async method inside a class

from swarmauri_tool_getmethodsignature import GetMethodSignatureTool

tool = GetMethodSignatureTool()
source = (
    "class Service:\n"
    "    async def fetch(self, url: str) -> bytes:\n"
    "        ...\n"
)
result = tool(source=source, method_name="fetch")

print(result["is_async"])  # True
print(result["return_type"])  # bytes

Detect overloaded definitions

from swarmauri_tool_getmethodsignature import GetMethodSignatureTool

tool = GetMethodSignatureTool()
source = (
    "def process(x: int) -> int:\n"
    "    return x\n"
    "def process(x: str) -> str:\n"
    "    return x\n"
)
result = tool(source=source, method_name="process")

print(len(result["overloads"]))  # 2

Register the tool inside a Swarmauri tool registry

from swarmauri_standard.tools.ToolCollection import ToolCollection
from swarmauri_tool_getmethodsignature import GetMethodSignatureTool

tools = ToolCollection(tools=[GetMethodSignatureTool()])
print(tools)

Swarmauri Foundations

More Documentation

Best Practices

  • Pass complete, syntactically valid Python source for best results.
  • Treat the signature string as a rendering hint rather than canonical source; round-trip formatting depends on the Python version.
  • Use the overloads list when auditing code that relies on name reuse.
  • Pair this tool with documentation generators to enrich API references.
  • Avoid relying on dynamic imports; this tool performs static analysis only.

Note: This tool performs static analysis on Python source code strings via the ast module. For runtime inspection of already-imported callables, see MethodSignatureExtractor in swarmauri_standard.utils.method_signature_extractor_decorator.

License

This project is licensed under the Apache-2.0 License.

Metadata

Release files for swarmauri_tool_getmethodsignature 0.11.0.dev3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for swarmauri_tool_getmethodsignature 0.11.0.dev3
File Size Uploaded Provenance Actions
swarmauri_tool_getmethodsignature-0.11.0.dev3.tar.gz 9.4 kB Without provenance Details for swarmauri_tool_getmethodsignature-0.11.0.dev3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for swarmauri_tool_getmethodsignature 0.11.0.dev3
File Interpreter ABI Platform Actions
swarmauri_tool_getmethodsignature-0.11.0.dev3-py3-none-any.whl Python 3 none any Details for swarmauri_tool_getmethodsignature-0.11.0.dev3-py3-none-any.whl

Total release size: 19.9 kB

Release files / swarmauri_tool_getmethodsignature-0.11.0.dev3.tar.gz

Download URL swarmauri_tool_getmethodsignature-0.11.0.dev3.tar.gz
Size 9.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e0c3cc7d2d4c88aca67a23d029476f2520421361240807e8a6168512bdcacc3a
BLAKE2b-256 checksum
How to use checksums
84e5a27a680a8c80b5cc3df1fe3d748f10f4db66a9d44cbd099a25412af16475
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / swarmauri_tool_getmethodsignature-0.11.0.dev3-py3-none-any.whl

Download URL swarmauri_tool_getmethodsignature-0.11.0.dev3-py3-none-any.whl
Size 10.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e58214ebaf0535baca372a963b73e786b79e40447c1b7b391a4b0199e67fc4a6
BLAKE2b-256 checksum
How to use checksums
b441cceaeabe3c34402e34d7d7907fb295839e9130570aae77f8b9bc635fa277
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for swarmauri_tool_getmethodsignature 0.11.0.dev3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page