> For the complete documentation index, see [llms.txt](https://docs.rhinofcp.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rhinofcp.com/rhino-sdk/running-a-python-code-object-using-the-rhino-sdk.md).

# Running a Python Code Object using the Rhino SDK

To run a Python Code Object using the Rhino SDK, complete the following steps.

> Note: To learn how to run a Python Code Object using the Rhino FCP UI, see [Creating and Running a Python Code Object](/creating-and-running-code-objects/creating-and-running-a-python-code-object.md).

### Prerequisites

Before starting this process, you should have already:

1. Created a Project using the Rhino SDK or UI.
2. Created 1 or more Datasets using the Rhino SDK or UI.
3. Created a Code Object using the Rhino SDK or UI.

### Import your Python Dependencies

```python
import rhino_health as rh
from rhino_health.lib.endpoints.code.code_object_dataclass import (
    CodeObject,
    CodeObjectRunInput
)
import getpass
```

> Note: Remember to change all lines with CHANGE\_ME comments above them in all the blocks below!

#### Log into the Rhino SDK using your FCP Credentials

Your username will be the email address you log into the Rhino FCP platform with.

```python
print("Logging In")

# CHANGE_ME: MY_USERNAME
my_username = "MY_USERNAME"

session = rh.login(username=my_username, password=getpass.getpass())
print("Logged In")
```

#### Get Supporting FCP Information Needed to Run Your Code

At this point, you will need the name of your Project, any Dataset's name you would like to use as input, and your previously created Code Object's name. You can also retrieve each object's UUID by following the instructions here: [Frequently Asked Questions (FAQs)](/frequently-asked-questions/frequently-asked-questions-faqs.md)

```python
# CHANGE_ME: YOUR_FCP_PROJECT_NAME
project = session.project.get_project_by_name('YOUR_FCP_PROJECT_NAME')

# CHANGE_ME: DATASET_NAME_1 & DATASET_NAME_2 & Possibly Version Number too
dataset1 = session.dataset.get_dataset_by_name("DATASET_NAME_1", project_uid=project.uid, version=1)
dataset2 = session.dataset.get_dataset_by_name("DATASET_NAME_2", project_uid=project.uid, version=1)
# Repeat the above for as many Datasets you would like to run as input to your Code

# CHANGE_ME: CODE_OBJECT_NAME & Possibly Version Number too
code_object = session.code.get_code_object_by_name("CODE_OBJECT_NAME:, project_uid=project.uid, version=1)
```

#### Run your Code

To run your Code you will need to supply the Code Object with the input Datasets you would like to run the Code over and an output Dataset names suffix. The suffix will be appended to each input Dataset name so you can view the results of the Code Run once the output has been re-imported into the system as a Dataset.

```python
code_object_params = CodeObjectRunInput(
  code_object_uid = code_object.uid,

  # CHANGE_ME: Add/Delete Dataset variables based on how many you want as input
  input_cohort_uids = [dataset1.uid, dataset2.uid],

  # CHANGE_ME: OUTPUT_SUFFIX
  output_dataset_names_suffix = "OUTPUT_SUFFIX",

  run_params: {}, # Optional - The run params code you want to run on the Datasets
  timeout_seconds: 600, # Optional - The time before a timeout is declared for the run
  sync: False # Optional - If True wait for run to end if False let it run in the background
)
code_run = session.code.run_code_object(code_object_params)
run_result = code_run.wait_for_completion()

print("Finished running code")
print(f"Result status is '{run_result.status.value}', errors={run_result.result_info.get('errors') if run_result.result_info else None}")
```

**Getting Help**

If you have received an error or run into any issues throughout the process, please reach out to <support@rhinohealth.com> for more assistance.


---

# 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://docs.rhinofcp.com/rhino-sdk/running-a-python-code-object-using-the-rhino-sdk.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.
