Select to view content in your preferred language

Use Folder.add function and wait ArcGIS Python API

557
1
Jump to solution
03-18-2025 05:37 AM
DavidHanimann
New Contributor

I am trying to add a FeatureService to a folder in ArcGIS Online using the Python APIs Folder.add() method.

This method returns a Future. How can I wait for this to finish and execute the remainder of the script synchronously? The only way I found was with a while loop, which is not nice.

    item_properties = {
        "title": "Test Feature Service",
        "tags": "example, feature service",
        "type": "File Geodatabase",
    }
    gdb_path = r"Default.gdb.zip"
    folder = login.content.folders.get(folder="My_Folder", owner="my-username")
    add_job = folder.add(item_properties, gdb_path)
    while True:
        if add_job.done():
            result = add_job.result()
            break
    print(result)

 

0 Kudos
1 Solution

Accepted Solutions
Clubdebambos
MVP Regular Contributor

Hi @DavidHanimann,

I just use the below.

## the .result() will return an item object representing the added gdb
item_obj = folder.add(item_properties, gdb_path).result()

# do whatever you need to the content item object, for example publish (which in-turn returns another itehm object - a Feature Service [FeatureLayerCollection]) 

another_item_obj = item_obj.publish()

# do whatever you need on the published item, add to groups, update symbology/popups, add to a WebMap etc

 

I have iterated over tens of zipped datasets for upload (add) and publishing and adding to folders, groups, adding symbology/popups/labels etc without any issues.

I hope that helps,

Glen

 

~ learn.finaldraftmapping.com

View solution in original post

1 Reply
Clubdebambos
MVP Regular Contributor

Hi @DavidHanimann,

I just use the below.

## the .result() will return an item object representing the added gdb
item_obj = folder.add(item_properties, gdb_path).result()

# do whatever you need to the content item object, for example publish (which in-turn returns another itehm object - a Feature Service [FeatureLayerCollection]) 

another_item_obj = item_obj.publish()

# do whatever you need on the published item, add to groups, update symbology/popups, add to a WebMap etc

 

I have iterated over tens of zipped datasets for upload (add) and publishing and adding to folders, groups, adding symbology/popups/labels etc without any issues.

I hope that helps,

Glen

 

~ learn.finaldraftmapping.com