# Getting started with Python functions The following documentation will guide you through the initial steps to prepare Python functions for use in the Palantir platform. You will learn how to create a Python functions repository, commit and publish a function, test in live previews, and more. ## Create a Python functions repository Navigate to a project of your choice and create a new code repository by selecting **+ New > Repository**. Select the **Python functions** template to initialize your repository. We recommend grouping all functions for use in Workshop or Ontology-based applications in a single repository to minimize costs. ![Create a Python function code repository.](../../../assets/ed1237374fd4f654ac92a688db3e0f747cfd7a72a00a2aaa3bcd396329486967.webp) Once the repository is created, navigate to the `python-functions/python/python-functions/my_function.py` file. ## Explore the repository Your repository will be initialized with a `my_function.py` file containing some example functions, including the following: ```python tab="Python" from functions.api import function, String @function def my_function() -> String: return "Hello World!" ``` Notice that the function adheres to the following constraints: * The function must be decorated with `@function` from the `functions.api` package to be recognized as a Python function. You may have multiple Python files with multiple functions in each file, but *only the functions with this decorator* will be registered as Python functions. * The function must declare the types of all of its inputs along with the type of its output, either using the type from the functions API package or its corresponding Python type. For example, the above example’s output type is declared as `String` from the functions API, but it may also be declared as the corresponding Python type `str`. Even if you declare the type of an argument with the API type (for example, `String`), your function will be passed the corresponding Python type at runtime (in this example, `str`). For a full overview of types in Python functions see our [type reference documentation](../types-reference/index.md). To add a Python package to your repository, use the **Libraries** side panel, as described in [discovering and using Python libraries](../../transforms-python/use-python-libraries/index.md). ## Test in live preview After you add the new function, you can run it immediately in the **Functions** helper. Open the **Functions** helper from the bottom left of the screen and select **Live Preview**. Choose the `add_seconds_to_datetime` function, enter input values, and select **Run** to run the code. ![Run your new function in the functions helper.](../../../assets/c1541b60216158f47b244a8fc025ddce5bcb5d0a32eb9526051cf377ff2d1cb7.webp) Select **Commit** in the upper right to commit your changes onto the `master` branch of your repository. ### Commit and publish a function Once you write a function (or uncomment one of the example functions provided), follow the steps below to commit and publish it. 1. Commit your changes by selecting **Commit** in the **Source control** tab and adding a commit message. 2. Select the **Branches** tab from the top center of the screen, then select **Tags and releases**. 3. Choose **New tag** and provide a version for the release. Select an appropriate version 4. Select **Tag and release** and wait for the release step to complete. 5. Once the check is successful, select the **Code** tab, then open the **Functions** tab on the bottom of the page. You will see `my_function` in the results. ![Open the Functions helper.](../../../assets/0c9df491ab3f2827e73c009446ed8a1e4ff0e9b9ca59895d620d852e5b7a30b2.webp) 6. Select the function, then choose **Run** to execute the function that you just published. ![Run the function in the Functions helper.](../../../assets/eae96464b39269cb1c2af589b6b9f390fe575dd02695f1b803fc8379eb367a6e.webp) ## Add another function Now, we will add a more complex function to this repository to test and publish. Copy and paste the code below to the bottom of the `my_function` file. ```python tab="Python" from functions.api import function, String from datetime import datetime, timedelta @function def add_seconds_to_datetime(start_time: datetime, elapsed_millis: int) -> str: dt = start_time + timedelta(milliseconds=elapsed_millis) return dt.isoformat() ``` For more examples of how to use your Python functions in the platform, review our documentation on [using Python functions in Pipeline Builder](../python-functions-builder/index.md) and on [using Python functions in Workshop](../python-functions-workshop/index.md).