Skip to content

FunctionDeclaration

A Python function declaration.

import { FunctionDeclaration } from "@alloy-js/python";
<FunctionDeclaration async />
asyncoptionalboolean

Indicates that the function is async.

This component creates a Python function declaration with optional type annotations, parameters, and return types. It supports async functions and automatically handles symbol creation and emission.

<FunctionDeclaration
name="my_function"
returnType="int"
parameters={[{ name: "a", type: { children: "int" } }, { name: "b", type: { children: "str" } }]}
>
return a + b
</FunctionDeclaration>

This will generate:

def my_function(a: int, b: str) -> int:
return a + b