IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: Nightly
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

@export

You can add the @export decorator on any function to make it publicly available as an exported symbol in the compiled artifact, allowing it to be called from external code. An @export function must declare its calling convention with an explicit abi effect.

# This function is internal - not an exported symbol
def internal_helper():
print("Internal")

# This function is exported under its own name, "my_exported_function"
@export
def my_exported_function() abi("Mojo"):
print("Exported!")
internal_helper()

# This function is exported under the name "my_renamed_function"
@export("my_renamed_function")
def my_other_function() abi("Mojo"):
print("Another function.")

The @export decorator can take an optional argument:

  • An alternate name to export the function under, as shown above.

Use the name specifier and abi("C") effect to export a function that complies with the C calling conventions. You must also supply a function name that is a valid C identifier. For example:

@export("my_func")
def my_function(
name: StaticString,
ptr: OpaquePointer[MutUntrackedOrigin],
) abi("C") -> None:
pass

To call Mojo from Python, register functions with a module builder. See Calling Mojo from Python for details.