# Custom Actions SDK 

Data Platform provides a Python SDK to create your own [custom actions](/en/product/dpe/actions/custom/index) within the [Data Processing Engine](/en/product/dpe/index) (DPE).  
It may also be used in other parts of the platform as described below.

- [Where is the Python SDK accessible](#where-is-the-python-sdk-accessible)
- [The connect function](#the-connect-function)
- [The bulk_insert function](#the-bulk_insert-function)
- [PySpark Support](#pyspark-support)
- [Simple Use Cases](#simple-use-cases)
- [Advanced Use Cases](#advanced-use-cases)


---
## Where is the Python SDK accessible

Most SDK functions are usable in 4 contexts, if they are not, it will be explicitly stated: 
- When creating a [Custom Action](/en/product/dpe/actions/custom/index) in the DPE.
- When creating a [Custom PySpark Action](/en/product/dpe/actions/custom-pyspark/index) in the DPE.
- When writing code in an [Integrated Jupyter Notebook](/en/product/dpe/notebooks/index).

You could, for example, write code and test it in a [Jupyter Notebook](/en/product/dpe/notebooks/index) and, once you are done, copy and paste it into a DPE Custom Action.

---
## The connect function

The `connect()` function is, most of the time, the main entry point to interact with the [Project](en/product/project/index).

It takes a **connection string** as parameter and returns a **Connector object**.  
For example:

```python
from forepaas.dwh import connect

connection_string = "dwh/default_dataset/"
connector_default = connect(connection_string)
```

Change the connection string to connect to different sources within the Data Platform environment.  
As a consequence, the object, and available methods, returned by `connect(...)` will be different.

Our [Connectors and Connection Strings article](/en/technical/sdk/dpe/connectors.md) explains each option available in more detail and below you will find the method list for two common connectors:
* [Lakehouse Manager Dataset Connector](/en/technical/sdk/dpe/connect-dm)
* [Lakehouse Manager Buckets Connector](/en/technical/sdk/dpe/connect-bucket)

---
## The bulk_insert function

The `bulk_insert()` function is a very important part of the SDK. You can use it to insert data back into a table. As shown in the code below, it takes a [Dataset Connector](/en/technical/sdk/dpe/connect-dm.md), a table name and a pandas DataFrame as parameters.

```python
import pandas as pd
from forepaas.dwh import connect
from forepaas.dwh import bulk_insert

# make connection to the default dataset
cn = connect("dwh/default_dataset/")

# extract data from the table with no SQL required
df = cn.select("stations_rides")

# perform your custom transform in the dataframe
df.loc[df["station_name"] == 'Harlem-Lake', "rides"] = 0

# reinsert your dataframe in the destination table
stats = bulk_insert(cn, "stations_rides", df) 
```

### bulk_insert(connector, table, data, source_default_schema={}, batch_size=None)

**Input Parameters**

| Name  | Type  | Description | Example |
| :---  | :---: | :---        | :---    |
| connector   | Connector| Connector instance from the connect() function | ```cn = connect("dwh/default_dataset/")``` |
| table | str | name of the destination table where the data is going to be loaded in | - |
| dataframe | pandas.DataFrame | Dataframe of data to insert, must to have the same column names and types that the target table does. | - |
| default_schema | dict | - | - |
| batch_size | int | insertion batch size | - |

**Output**

| Type  | Description | Example |
| :---: | :---        | :---    |
| Tuple(stats, error) |  tuple of the statistics of the insertion | - |

---
## PySpark Support

Data Platform offers extensive support to handle data with PySpark. 
All is done through Spark-compatible methods in the Connector object.  
Check out our [PySpark article](/en/technical/sdk/dpe/connect-spark) for further details.

---
## Simple use cases

We have prepared sample scripts for common use cases to get you started right away for 3 different use cases which you can find here - [Transform data from sources using the Python SDK](en/getting-further/sdk/index.md)

---
## Advanced use cases

Feeling confident 💪? Here are a few more specific use cases: 

* [A. Environment variables](/en/technical/sdk/dpe/3A.parameter)
* [B. Segmentation and perimeter usage](/en/technical/sdk/dpe/3B.segmentation)
* [C. Override load action](/en/technical/sdk/dpe/3C.load-override)
* [D. Using custom Python modules](/en/technical/sdk/dpe/3D.git)
* [E. Track data lineage](/en/technical/sdk/dpe/3E.lineage)

---
##  Need help? 🆘

> If you are logging-in with an OVHcloud account, you can create a ticket to raise an incident or if you need support at the [OVHcloud Help Centre](https://help.ovhcloud.com/csm/fr-home?id=csm_index). Additionally, you can ask for support by reaching out to us on the Data Platform Channel within the [Discord Server](https://discord.com/channels/850031577277792286/1163465539981672559). There is a step-by-step guide in the [support](/en/support/index.md).

