> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/feature-management-experimentation/management-and-administration/api-best-practices/examples/copy-segment.md).

# Copy Segment IDs to Another Segment

### Overview <a href="#overview" id="overview"></a>

Use this script to copy segment IDs to another segment.

#### Prerequisites <a href="#prerequisites" id="prerequisites"></a>

* Install the [Python Admin API Wrapper](/feature-management-experimentation/management-and-administration/api-best-practices/wrappers/python-admin-api.md).
* You've created an Admin API key from the Split UI.

### Configuration <a href="#configuration" id="configuration"></a>

Before running the script, update the following variables in the code:

* `ADMIN API KEY`: Your Split Admin API key.
* `sourceSegmentName`: The name of the segment you want to copy.
* `sourceWorkspaceName`: The name of the workspace containing the source segment. If you only have one workspace, use the Default workspace.
* `sourceEnvironmentName`: The name of the environment where the source segment is defined.
* `targetSegmentName`: The name of the segment you want to create or update.
* `targetWorkspaceName`: The name of the workspace where the target segment will be created. If you only have one workspace, use the Default workspace.
* `targetEnvironmentName`: The name of the environment where the target segment will be created.

Run this script using Python 3 from your local machine or preferred development environment.

```python
from splitapiclient.main import get_client

#############################################
sourceSegmentName="admin_api_test"
sourceWorkspaceName="Default"
sourceEnvironmentName="Production"
targetSegmentName = "myaccounts"
targetWorkspaceName = "Default"
targetEnvironmentName = "Production"
#############################################

client = get_client({'apikey': 'ADMIN API KEY'})
sourceWs = client.workspaces.find(sourceWorkspaceName)
sourceEnv = client.environments.find(sourceEnvironmentName, sourceWs.id)
sourceSegmentDef = client.segment_definitions.find(sourceSegmentName, sourceEnv.id, sourceWs.id)
targetWs = client.workspaces.find(targetWorkspaceName)
targetEnv = client.environments.find(targetEnvironmentName, targetWs.id)
targetSegmentDef = client.segment_definitions.find(targetSegmentName, sourceEnv.id, sourceWs.id)

keys = sourceSegmentDef.get_keys()
targetSegmentDef.import_keys_from_json("false", {"keys":keys,"comment":"copy keys from segment"})
```
