Create and manage code
Create Python or SQL code in a collection and manage its versions, tags, and clones. Pipelines can reference and run the saved code as a step.
Supported languages
D.Hub stores Python and SQL code.
| Language | Purpose | Description |
|---|---|---|
| Python | Data processing and AI/ML | Use data-processing libraries such as Pandas, Polars, and PyArrow. |
| SQL | Data queries and transformations | Write analytical database queries and data transformations. |
Select the language (python / sql) during creation. It cannot be changed after creation and appears as a badge in the Code tab toolbar.
Code detail screen
Select a code item in the collection tree to display its details in the right panel. The detail screen contains the following tabs.
| Order | Tab | Contents |
|---|---|---|
| 1 | Overview | Review and edit metadata. |
| 2 | Code | Use the code editor and toolbar, and manage Python packages. |
| 3 | Version History | Review versions and compare, restore, or download one. |
| 4 | Sharing and Permissions | Manage user and group permissions. See Sharing and Permissions. |
| 5 | Inputs | Define code input parameters in edit mode. |
Overview tab (metadata)
Review the code asset's metadata and change selected fields in Edit mode.
| Field | Description | Editing |
|---|---|---|
| Name | Unique code identifier | Cannot be changed after creation |
| Alias | Display name, up to 128 characters | Editable |
| Tags | Used for search and classification | Editable, with AI suggestions |
| Description | Records the purpose of the code | Editable, with AI suggestions |
| Packages | Lists Python dependencies | Edit on the Code tab |
| Collection / ID / Created and modified | Collection, identifier, and author information | Cannot be changed |
Pipeline steps reference a code name in the script field. Apply your team's naming convention so the same names are easy to find in the code list and pipeline settings.
Code tab (editor)
The code editor supports read and edit modes and opens in read mode by default. Select Edit in the detail header, then select Save changes in the bottom action bar when finished.
- Syntax highlighting: Uses language-appropriate highlighting for Python and SQL.
- Line numbers: Shows line numbers to the left of the code.
- Copy code: Select Copy code in the toolbar to copy all code to the clipboard.
- Format: Select Format in the toolbar to format the code automatically.
- Search in editor: Find text with the Search in code... field in the toolbar.
AI code generation and AI editing
The code editor includes AI-assisted code generation and editing.
- AI code generation: Select AI in the toolbar or press
⌘I(macOS) /Ctrl+I(Windows) and enter a natural-language request. With no selection, it generates new code. With code selected, it opens a request field to revise that section. - Selection menu: Select code and choose AI Edit from the floating menu to request a revision for the selected section.
- Insert / Cancel / Try again: Review the result, then select Insert to apply it or Cancel to discard it. Select Try again to generate another result.
Python packages
For Python code, the Code tab displays a Packages input section. Enter packages required at runtime as a comma-separated list, for example polars,deltalake,pandas. This section does not appear for SQL code.
Insert a connector binding
In Python edit mode, select Connector in the toolbar to bind a registered connector to the code. In the popover, choose the connector and the variable name used by the script. An @use_connector decorator is inserted on the current line. Typing @use_ in the editor also suggests @use_connector. The button is not shown for SQL code.
The UI for inserting model (
@use_llm) and knowledge (@use_rag) decorators is available in the code editors for agents and pipelines.
Inputs tab
Define code inputs (parameters) in edit mode. These are the input values passed when a pipeline uses this code as a step.
Create and edit code
Create code
- In a collection or folder, select Add Item ▾ → Code → Python / SQL.
- Under Basic Information in the Create code dialog, enter the name, alias, description, and tags. For Python, enter required packages as a comma-separated list.
- Select Next and revise the automatically populated starter code in the Code step. Use AI code generation for new code, or select code and use AI Edit to revise it.
- Review the code and select Create.
The new code appears in the list and tree for the selected collection or folder. You cannot change the selected language in the dialog. When opened from a collection or folder, the save location is also fixed.
Starter code format
Python code receives a Polars DataFrame and returns the result DataFrame under the output key.
import polars as pl
def run(input, *, options=None, contexts=None):
output = input.drop("column_name")
return {"output": output}
SQL code uses input as the input table name and passes the query result to output.
SELECT *
FROM input
WHERE column_name IS NOT NULL
See the Python code guide and SQL query guide for execution conventions and supported features.
Edit code
On the Code tab, select Edit, make changes, and select Save changes. Saving creates a new version. Previous versions remain available for restoration.
Clone code
Select Clone in the detail header to open the clone dialog. Choose the destination collection and a new name, then set the alias, description, and tags. The suggested alias appends _copy to the original value.
Version management
Code changes are stored by version.
- Version list: Review all versions with author, time, and Latest badge.
- Compare versions: Select two versions to open Compare changes. Switch between Side by side / Unified and review the number of added and removed lines.
- Restore a version: Restore a previous version as the current version after confirmation.
- Download: Download a selected version as a
.pyor.sqlfile.
Editing code can change the behavior of pipelines that reference it. Review related pipelines before making changes.
See Version management for comparison and restoration procedures.
Use code in a pipeline
A pipeline node references code through its script field. You can reuse one code asset in multiple pipelines. Running a pipeline executes the referenced code.
See Pipelines in a collection for how to manage pipelines and code together.
Next steps
- Pipelines in a collection — Manage pipelines within a collection.
- Review and restore version history — Review code changes and restore a previous version.
- Python code guide — Review the input and output contract for Python code.