Skip to main content

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.

LanguagePurposeDescription
PythonData processing and AI/MLUse data-processing libraries such as Pandas, Polars, and PyArrow.
SQLData queries and transformationsWrite 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.

OrderTabContents
1OverviewReview and edit metadata.
2CodeUse the code editor and toolbar, and manage Python packages.
3Version HistoryReview versions and compare, restore, or download one.
4Sharing and PermissionsManage user and group permissions. See Sharing and Permissions.
5InputsDefine code input parameters in edit mode.

Overview tab (metadata)

Review the code asset's metadata and change selected fields in Edit mode.

FieldDescriptionEditing
NameUnique code identifierCannot be changed after creation
AliasDisplay name, up to 128 charactersEditable
TagsUsed for search and classificationEditable, with AI suggestions
DescriptionRecords the purpose of the codeEditable, with AI suggestions
PackagesLists Python dependenciesEdit on the Code tab
Collection / ID / Created and modifiedCollection, identifier, and author informationCannot be changed
tip

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

  1. In a collection or folder, select Add Item ▾ → Code → Python / SQL.
  2. 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.
  3. 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.
  4. 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 .py or .sql file.
warning

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