Skip to content
← All guides

Can you write Python in HubSpot workflow custom code?

Compare native HubSpot Python and Turbyn handlers with explicit input and output examples, runtime boundaries and a safe migration checklist.

Turbyn · Published · Updated

The short answer

HubSpot documents Python custom code as a beta option for eligible accounts. Turbyn also supports Python, with a different handler contract and its own runtime limits. Choose the execution environment first, then use its input, output and secrets conventions; the examples are not interchangeable.

Choose the runtime before copying a snippet

HubSpot’s current documentation labels native Python support beta. Check availability in your account. Its native action has a documented runtime budget and a supported library list.

Turbyn’s Python handler runs separately. The two environments can perform the same calculation, but their surrounding contracts differ.

Native HubSpot Python example

This complete native handler trims surrounding whitespace from a mapped email value. It does not validate the address or update a CRM property.

def main(event):
    raw = event.get("inputFields", {}).get("email")
    if not isinstance(raw, str):
        raise ValueError("email must be a string")
    return {"outputFields": {"email": raw.strip()}}

For a synthetic input containing {"inputFields": {"email": " alex@example.com "}}, the return value is:

{ "outputFields": { "email": "alex@example.com" } }

Configure email as a string data output in the native action, then select that output in a later workflow step. HubSpot’s test action can make real changes when your code includes writes; use a dedicated test record.

Turbyn Python example

This complete Turbyn handler performs the same trim, using inputs and a plain returned object. The explicit text key provides the typed text output for a later step.

async def main(event, ctx):
    raw = event.get("inputs", {}).get("email")
    if not isinstance(raw, str):
        raise ValueError("email must be a string")
    return {"text": raw.strip()}

Turbyn synthetic test event:

{ "inputs": { "email": " alex@example.com " } }

Expected returned JSON:

{ "text": "alex@example.com" }

Select the text output in the subsequent HubSpot action. See Writing actions for JSON and typed output behavior. This trim example intentionally preserves letter case; a broader normalization policy needs its own requirements.

A migration checklist

Check What to verify
Input shape Map the required values into Turbyn’s Inputs JSON.
Output shape Return the intended JSON and choose the correct typed output.
Secrets Bind credentials and access them through ctx.secrets.
Dependencies Test the exact packages in the target runtime.
Side effects Guard writes during tests and make retries safe.

Do not treat a successful import as a complete migration. Test a valid value, an empty string, a missing key and a value of the wrong type. For this example, missing or non-string values should fail explicitly instead of silently overwriting a property.

Packages and operational limits

Use Python’s standard library when it handles the task clearly. For additional packages, inspect Turbyn’s compatibility guidance and plan allowances.

A longer runtime does not change a remote API’s rate limits. Turbyn test runs also make real outbound requests: use the run-mode guidance before adding write operations.

Sources and references

Source documentation checked for this update. Availability can vary by subscription and account.

Questions from this guide

Read configured properties from event["inputFields"]. The event's object information identifies the enrolled record; it is not a complete CRM record.

Continue reading