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
- Open ArcGIS Pro and add the
.pyt
toolbox if you haven't already. - Open the Generate Python Code tool.
- Fill in the parameters as described below.
- Click Run. The generated Python code will be displayed in the tool's output.
Parameters
Name | Type | Required | Description |
---|---|---|---|
Source | String (Choice) | Yes | AI provider to use (OpenAI, Azure OpenAI, Claude, DeepSeek, Local LLM). |
Model | String | No | The AI model to use. Choices depend on the selected source. |
Endpoint | String | No | Custom endpoint for Azure or local models (if applicable). |
Deployment Name | String | No | Deployment name for Azure OpenAI (if applicable). |
Layers for Context | Feature Layer (MultiValue) | No | Optional layers to provide specific context for the AI when generating code. This includes the schema and a data sample (first 5 records). |
Prompt | String | Yes | Describe the Python code you want to generate. Be specific for better results. |
Context | String | No | Map 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
- Provide detailed prompts, e.g.,
"Generate a script to buffer all layers in the map by 500 meters."
- Use the Layers for Context parameter to include specific layers in the generated code.
- Experiment with different models for varied results.
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.