Extract Package (Data Management)

Summary

Extracts the contents of a package to a specified folder. The output folder will be updated with the extracted contents of the input package.

Usage

  • The following are supported package types:

    • Geoprocessing Packages (.gpk and .gpkx)
    • Layer Packages (.lpk and .lpkx)
    • Locator Packages (.gcpk)
    • Map Packages (.mpk and .mpkx)
    • Mobile Map Packages (.mmpk)
    • Project Packages and Project Templates (.ppkx and .aptx)
    • Tile Packages (.tpk and .tpkx)
    • Vector Tile Packages (.vtpk)

  • The output folder can be a new folder or an existing folder. When extracting to an existing folder, the contents of the package will be appended to existing files and folders. If the output folder contains the extracted contents of the package, the existing contents will be overwritten.

  • Packages with attachments will have their attached files unpacked to the commondata\userdata\ subfolder in the output folder. Typically, the files in a package are supporting files, such as .pdf, .docx, or an image. You will need to browse to the extracted directory in Windows Explorer to open these files.

  • When extracting vector tile packages (.vtpk), the contents of the package will be extracted to the output folder. The cache storage format can be converted from compact (.bundle files) to exploded (.pbf files) using the Storage Format Type parameter. You can use the extracted .pbf files in other client applications, such as Mapbox.

  • When extracting tile packages (.tpk, .tpkx, or .vtpk), the Cache Package parameter is disabled.

Syntax

arcpy.management.ExtractPackage(in_package, output_folder, {cache_package}, {storage_format_type}, {create_ready_to_serve_format})
ParameterExplanationData Type
in_package

The input package that will be extracted.

File
output_folder

The output folder that will contain the contents of the package.

If the specified folder does not exist, a folder will be created.

Folder
cache_package
(Optional)

Specifies whether a copy of the package will be cached to your profile. When extracting a package, the output is first extracted to your user profile and appended with a unique ID before a copy is made to the directory specified in the output_folder parameter. Downloading and extracting subsequent versions of the same package will only update this location. You do not need to manually create a cached version of the package in your user profile when using this parameter. This parameter is not enabled if the input package is a vector tile package (.vtpk) or a tile package (.tpk and .tpkx).

  • CACHE A copy of the package will be extracted and cached to your profile. This is the default.
  • NO_CACHEA copy of the package will only be extracted to the output parameter specified.
Boolean
storage_format_type
(Optional)

Specifies the storage format of the extracted cache. This parameter is applicable only when the input package is a vector tile package (.vtpk).

  • COMPACT The tiles will be grouped in bundle files using the Compact V2 storage format. This format provides better performance on network shares and cloud store directories. This is the default.
  • EXPLODED Each tile will be stored as an individual file.
String
create_ready_to_serve_format
(Optional)

Specifies a ready-to-serve format for ArcGIS Enterprise will be created. This parameter is enabled only when the input package is a vector tile package (.vtpk) or a tile package (.tpkx).

  • READY_TO_SERVE_CACHE_DATASETA folder structure with an extracted cache that can be used to create a tile layer in ArcGIS Enterprise will be created. The file extension of the folder signifies the content it stores: .tiles (cache dataset) for tile layer packages or .vtiles (vector cache dataset) for vector tile packages.
  • EXTRACTED_PACKAGEA folder structure with extracted contents of the package will be created. This is the default.
Boolean

Code sample

ExtractPackage example 1 (Python window)

The following Python window script demonstrates how to use the ExtractPackage function to generate ready-to-serve cache datasets that can be used in ArcGIS Enterprise publishing workflows.

import arcpy
arcpy.management.ExtractPackage(r"C:\Data\packages\MyVectorPackage.vtpk", 
                                r"C:\Data\packages\Extracted", "CACHE", 
                                "COMPACT", "READY_TO_SERVE_CACHE_DATASET")
ExtractPackage example 2 (stand-alone script)

Find all geoprocessing packages in a specified folder and use the ExtractPackage function to extract contents to the specified folder.

# Name: ExtractPackage.py
# Description: Find Geoprocessing Packages in a specified folder and extract contents.

import arcpy
import os

arcpy.env.overwriteOutput = True

# set folder that contains packages to extract
arcpy.env.workspace = "C:/geoprocessing/gpks" 
wrksp = arcpy.env.workspace

for gpk in arcpy.ListFiles("*.gpk"):
    print("Extracting... " + gpk)
    arcpy.ExtractPackage_management(gpk, os.path.splitext(gpk)[0])

print("done")

Environments

Licensing information

  • Basic: Yes
  • Standard: Yes
  • Advanced: Yes

Related topics