> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mindsdb.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Bring Your Own Function

Custom functions provide advanced means of manipulating data. Users can upload custom functions written in Python to MindsDB and apply them to data.

## How It Works

You can upload your custom functions via the MindsDB editor by clicking `Add` and `Upload custom functions`, like this:

<p align="center">
  <img src="https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/assets/upload_custom_function.png?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=2ccf18d04467026fca12c941e9e999e4" width="217" height="278" data-path="assets/upload_custom_function.png" />
</p>

Here is the form that needs to be filled out in order to bring your custom functions to MindsDB:

<p align="center">
  <img src="https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/assets/upload_custom_function_empty_form.png?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=6f519ffac0a3537f25823ab1250ae556" width="380" height="592" data-path="assets/upload_custom_function_empty_form.png" />
</p>

Let's briefly go over the files that need to be uploaded:

* The Python file stores an implementation of your custom functions. Here is the sample format:

  ```py theme={null}
  def function_name_1(a:type, b:type) -> type:
      <implementation goes here>
      return x

  def function_name_2(a:type, b:type, c:type) -> type:
      <implementation goes here>
      return x
  ```

  <Note>
    Note that if the input and output types are not set, then `str` is used by default.
  </Note>

<Accordion title="Example">
  ```py theme={null}
  def add_integers(a:int, b:int) -> int:
      return a+b
  ```
</Accordion>

* The optional requirements file, or `requirements.txt`, stores all dependencies along with their versions. Here is the sample format:

  ```sql theme={null}
  dependency_package_1 == version
  dependency_package_2 >= version
  dependency_package_3 >= verion, < version
  ...
  ```

<Accordion title="Example">
  ```sql theme={null}
  pandas
  scikit-learn
  ```
</Accordion>

Once you upload the above files, please provide the name for a storage collection.

Let's look at an example.

## Example

We upload the custom functions, as below:

<p align="center">
  <img src="https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/assets/upload_custom_function2.png?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=fe7a7d53017ee716612d4139893c37cd" width="374" height="586" data-path="assets/upload_custom_function2.png" />
</p>

Here we upload the `functions.py` file that stores an implementation of the functions and the `requirements.txt` file that stores all the dependencies. We named the storage collection as `custom_functions`.

Now we can use the functions as below:

```sql theme={null}
SELECT functions.add_integers(sqft, 1) AS added_one, sqft
FROM example_db.home_rentals
LIMIT 1;
```

Here is the output:

```sql theme={null}
+-----------+------+
| added_one | sqft |
+-----------+------+
| 918       | 917  |
+-----------+------+
```
