<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to copy arcgis.gis.Item into memory in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-copy-arcgis-gis-item-into-memory/m-p/1582216#M11136</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/417766"&gt;@Clubdebambos&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this case the the artifacts are objects of the&amp;nbsp;&lt;A href="https://developers.arcgis.com/python/latest/api-reference/arcgis.gis.toc.html#arcgis.gis.Item" target="_self" rel="nofollow noopener noreferrer"&gt;arcgis.gis.Item&lt;/A&gt;, but the type is Feature Layer Collection and others are &lt;A href="https://developers.arcgis.com/python/latest/api-reference/arcgis.features.toc.html#arcgis.features.FeatureLayer" target="_self"&gt;FeatureLayer&lt;/A&gt;&amp;nbsp;. These are the only types I am worried about for this question. I am not using the FeatureLayer or&amp;nbsp;&lt;A href="https://developers.arcgis.com/python/latest/api-reference/arcgis.features.toc.html#arcgis.features.FeatureLayerCollection" target="_self"&gt;Feature&amp;nbsp;Layer Collection&lt;/A&gt;&amp;nbsp;types directly, but I am open to if it will do what I need.&lt;/P&gt;&lt;P&gt;This what an item looks like:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;&amp;lt;Item title:"Polygon_Map_01" type:Feature Layer Collection owner:Me&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 05 Feb 2025 14:14:19 GMT</pubDate>
    <dc:creator>chris_del101</dc:creator>
    <dc:date>2025-02-05T14:14:19Z</dc:date>
    <item>
      <title>How to copy arcgis.gis.Item into memory</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-copy-arcgis-gis-item-into-memory/m-p/1582040#M11133</link>
      <description>&lt;P&gt;I want to &lt;A href="https://developers.arcgis.com/python/latest/api-reference/arcgis.gis.toc.html#arcgis.gis.Item.update" target="_self"&gt;update&lt;/A&gt;&amp;nbsp;an&amp;nbsp;&lt;A href="https://developers.arcgis.com/python/latest/api-reference/arcgis.gis.toc.html#arcgis.gis.Item" target="_self"&gt;arcgis.gis.Item&lt;/A&gt;&amp;nbsp;but not change the original. Running update on an item &lt;EM&gt;does&amp;nbsp;&lt;/EM&gt;alter the original.&amp;nbsp;I tried&amp;nbsp;&lt;A href="https://developers.arcgis.com/python/latest/api-reference/arcgis.gis.toc.html#arcgis.gis.Item.copy" target="_self"&gt;item.copy&lt;/A&gt;&amp;nbsp;but this makes a literal copy in portal which I do not want. I just want to copy in memory so that I can make changes without altering the original. What I really want is deepcopy...&lt;/P&gt;&lt;P&gt;But using copy or deepcopy immediately crashes my program without any error. Below demonstrates why I want to do this, in case there's concern around that.&lt;/P&gt;&lt;P&gt;Please note: this is a made up simplified demo example, so if I made any typos in the code by mistake here, don't infer those are connected to my local problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;gis = GIS(url=url, username=username, password=password)
item = gis.content.get(some_id)
item_copy = copy.copy(item) # crashes the program, so does deepcopy
print("hello") # never runs further than prev line
item_copy.update({'title': 'New_Item_Title"})
gis.content.clone_items(items=[item_copy])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't understand why this kills the program, if it's an Esri error or an error with my environment, since there is no error message, except the exception __deepcopy_&lt;BR /&gt;If I can't use these copies is there another way to do this?&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2025 22:36:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-copy-arcgis-gis-item-into-memory/m-p/1582040#M11133</guid>
      <dc:creator>chris_del101</dc:creator>
      <dc:date>2025-02-04T22:36:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy arcgis.gis.Item into memory</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-copy-arcgis-gis-item-into-memory/m-p/1582149#M11134</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/852729"&gt;@chris_del101&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;When you say copy an item, do you want to perform on any item or more specifically a Feature Service (Feature Layer Collection) item?&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2025 07:51:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-copy-arcgis-gis-item-into-memory/m-p/1582149#M11134</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2025-02-05T07:51:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy arcgis.gis.Item into memory</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-copy-arcgis-gis-item-into-memory/m-p/1582216#M11136</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/417766"&gt;@Clubdebambos&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this case the the artifacts are objects of the&amp;nbsp;&lt;A href="https://developers.arcgis.com/python/latest/api-reference/arcgis.gis.toc.html#arcgis.gis.Item" target="_self" rel="nofollow noopener noreferrer"&gt;arcgis.gis.Item&lt;/A&gt;, but the type is Feature Layer Collection and others are &lt;A href="https://developers.arcgis.com/python/latest/api-reference/arcgis.features.toc.html#arcgis.features.FeatureLayer" target="_self"&gt;FeatureLayer&lt;/A&gt;&amp;nbsp;. These are the only types I am worried about for this question. I am not using the FeatureLayer or&amp;nbsp;&lt;A href="https://developers.arcgis.com/python/latest/api-reference/arcgis.features.toc.html#arcgis.features.FeatureLayerCollection" target="_self"&gt;Feature&amp;nbsp;Layer Collection&lt;/A&gt;&amp;nbsp;types directly, but I am open to if it will do what I need.&lt;/P&gt;&lt;P&gt;This what an item looks like:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;&amp;lt;Item title:"Polygon_Map_01" type:Feature Layer Collection owner:Me&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2025 14:14:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-copy-arcgis-gis-item-into-memory/m-p/1582216#M11136</guid>
      <dc:creator>chris_del101</dc:creator>
      <dc:date>2025-02-05T14:14:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy arcgis.gis.Item into memory</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-copy-arcgis-gis-item-into-memory/m-p/1582592#M11139</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/852729"&gt;@chris_del101&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Thanks for the info. Does the below meet your requirements? Code is commented to follow along but basically it copies the Feature Layer Collection item which transfers the shell (layers/tables without data) and then we take the records from the original and add them in.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS

## Access AGOL
agol = GIS("home")

## get the Feature Service as an Item object
item = agol.content.get("FS_ITEM_ID") # get the Item id for the FLC item to copy

## get the layer indexes
layers = list(range(len(item.layers)))

## get the table indexes
tables = list(range(len(item.tables)))

## copy the item - copies the shell, not data is added to the layers/tables
copied_item = item.copy_feature_layer_collection(
    service_name = "MY_COPIED_SERVICE", # rename your new Item here
    layers = layers,
    tables = tables,
    description = item.description,
    snippet = item.snippet
)

## for each layer in the original item
for lyr in item.layers:
    ## get the layer name
    item_layer_name = lyr.properties.name

    ## get the FeatureLayer object for the corresponding layer in the copied item
    copied_layer = [lyr for lyr in copied_item.layers if lyr.properties.name == item_layer_name][0]

    ## get all records from the original layer
    item_layer_records = lyr.query()

    ## add the records to the copied layer
    copied_layer.edit_features(
        adds = item_layer_records
    )

## repeat for any tables
for tbl in item.tables:

    item_table_name = tbl.properties.name

    copied_table = [tbl for tbl in copied_item.tables if tbl.properties.name == item_table_name][0]

    item_table_records = tbl.query()

    copied_table.edit_features(
        adds = item_table_records
    )&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 06 Feb 2025 08:29:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-copy-arcgis-gis-item-into-memory/m-p/1582592#M11139</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2025-02-06T08:29:20Z</dc:date>
    </item>
  </channel>
</rss>

