Skip to main content
Learn how to write Function scripts and deploy them to Notte’s serverless infrastructure.

Writing a Function

Functions are Python scripts with a run() function that serves as the entry point.

Basic Function

The minimal Function structure:
hello_function.py

Function with Parameters

Accept input parameters:
greet_function.py

Browser Automation Function

Use Notte SDK for browser automation:
scraper_function.py

Deploying Functions

Via SDK

Deploy from Python:
deploy_sdk.py

Deployment Options

deployment_options.py
Parameters:
  • workflow_path (str, required): Path to your Python file
  • name (str, optional): Function display name
  • description (str, optional): What the function does
  • shared (bool, default=False): Whether function is publicly accessible

Function Requirements

The Handler

Must have a run() function:
handler_examples.py

Dependencies

Import Notte SDK and standard libraries:
dependencies.py
Available packages:
  • notte-sdk - Notte SDK
  • requests - HTTP client
  • pydantic - Data validation
  • Standard Python library
  • Most common packages

Return Values

Return JSON-serializable data:
return_values.py

Parameter Types

Supported Types

parameter_types.py

Type Validation

Use type hints for automatic validation:
type_validation.py

Complex Types

Use Pydantic for structured parameters:
complex_types.py

Environment Variables

Access secrets securely:
environment_variables.py
Set environment variables in Console or locally for testing.

Error Handling

Graceful Errors

Return error information in results:
graceful_errors.py

Raising Exceptions

Let Functions fail explicitly:
raising_exceptions.py

Testing Locally

Test Before Deploying

Run your function locally:
test_locally.py

Mock API Calls

Test without deploying:
mock_api_calls.py

Best Practices

1. Document Parameters

Use clear docstrings:
document_params.py

2. Return Structured Data

Use consistent return formats:
return_structured.py

3. Add Logging

Log key steps for debugging:
add_logging.py

4. Set Timeouts

Prevent functions from hanging:
set_timeouts.py

5. Validate Inputs

Check parameters before processing:
validate_inputs.py

Examples

Simple Scraper

simple_scraper.py

Form Submission

form_submission.py

Data Extraction

structured_extraction.py

Next Steps

Invocations

Learn how to call your Functions

Schedules

Schedule Functions to run automatically

Management

Update and manage Functions

Functions Concept

Back to Functions overview