Generate Python Code

This tool generates Python code snippets based on your prompt and the context of your map. Use it to quickly create ArcPy scripts tailored to your current project.

Usage

  1. Open ArcGIS Pro and add the .pyt toolbox if you haven't already.
  2. Open the Generate Python Code tool.
  3. Fill in the parameters as described below.
  4. Click Run. The generated Python code will be displayed in the tool's output.

Parameters

NameTypeRequiredDescription
SourceString (Choice)YesAI provider to use (OpenAI, Azure OpenAI, Claude, DeepSeek, Local LLM).
ModelStringNoThe AI model to use. Choices depend on the selected source.
EndpointStringNoCustom endpoint for Azure or local models (if applicable).
Deployment NameStringNoDeployment name for Azure OpenAI (if applicable).
Layers for ContextFeature Layer (MultiValue)NoOptional layers to provide specific context for the AI when generating code. This includes the schema and a data sample (first 5 records).
PromptStringYesDescribe the Python code you want to generate. Be specific for better results.
ContextStringNoMap context which will be passed to the AI. This is dynamically generated using the current map and selected layers from the Layers for Context parameter. For a detailed look at how this information is gathered see the Get Map Info tool.

Tips

Data Privacy Caution

Important: This tool sends data (which is visible in the "Context" parameter) to the AI provider you specify. Be mindful of your organization's data policies before sharing potentially sensitive information. Avoid including confidential, regulated, or personally identifiable information in your context layers if using non-local model options that transmit data across the web.