> For the complete documentation index, see [llms.txt](https://titan-core.gitbook.io/titan-core/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://titan-core.gitbook.io/titan-core/resources/python_stored_procedure.md).

# PythonStoredProcedure

[Snowflake Documentation](s://docs.snowflake.com/en/sql-reference/sql/create-procedure)

Represents a Python stored procedure in Snowflake, allowing for the execution of Python code within the Snowflake environment.

## Examples

### Python

```python
procedure = PythonStoredProcedure(
    name="some_procedure",
    args=[],
    returns="STRING",
    runtime_version="3.8",
    packages=["snowflake-snowpark-python"],
    handler="process_data",
    as_="def process_data(): return 'Hello, World!'",
    comment="A simple procedure",
    copy_grants=False,
    execute_as="CALLER",
    external_access_integrations=None,
    imports=None,
    null_handling="CALLED_ON_NULL_INPUT",
    owner="SYSADMIN",
    secure=False
)
```

### YAML

```yaml
procedures:
- name: some_procedure
    args: []
    returns: STRING
    runtime_version: "3.8"
    packages:
    - snowflake-snowpark-python
    handler: process_data
    as_: "def process_data(): return 'Hello, World!'"
    comment: "A simple procedure"
    copy_grants: false
    execute_as: CALLER
    external_access_integrations: null
    imports: null
    null_handling: CALLED_ON_NULL_INPUT
    owner: SYSADMIN
    secure: false
```

## Fields

* `name` (str, required) - The name of the procedure.
* `args` (list) - The arguments of the procedure.
* `returns` ([DataType](https://github.com/Titan-Systems/titan/blob/main/docs/resources/data_type.md)) - The data type of the return value.
* `runtime_version` (str, required) - The Python runtime version.
* `packages` (list) - The list of packages required by the procedure.
* `handler` (str, required) - The handler function for the procedure.
* `as_` (str) - The procedure definition.
* `comment` (str) - A comment about the procedure. Defaults to "user-defined procedure".
* `copy_grants` (bool) - Whether to copy grants. Defaults to False.
* `execute_as` ([ExecutionRights](https://github.com/Titan-Systems/titan/blob/main/docs/resources/execution_rights.md)) - The execution rights. Defaults to ExecutionRights.CALLER.
* `external_access_integrations` (list) - External access integrations if any.
* `imports` (list) - Files to import.
* `null_handling` ([NullHandling](https://github.com/Titan-Systems/titan/blob/main/docs/resources/null_handling.md)) - How nulls are handled. Defaults to NullHandling.CALLED\_ON\_NULL\_INPUT.
* `owner` (string or [Role](/titan-core/resources/role.md)) - The owner of the procedure. Defaults to "SYSADMIN".
* `secure` (bool) - Whether the procedure is secure. Defaults to False.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://titan-core.gitbook.io/titan-core/resources/python_stored_procedure.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
