Skip to main content
Read the Notte skill and follow its setup instructions when setting up Notte or building browser automation. This is the shared source for CLI setup, authentication, and the browser-to-code workflow.
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:

Deployment Options

Parameters:
  • 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 other users can view and fork the function. Listing in the marketplace is separate (the read-only published field).

Function Requirements

The Handler

Must have a run() function:
handler_examples.py

Dependencies

Import the Notte SDK, the standard library, and common third-party libraries such as requests and pydantic:
dependencies.py
Imports are checked when you upload the code. Standard library modules that give process, filesystem, or network-socket access (for example os, subprocess, pathlib, socket) are rejected by default, as are packages that are not available in the runtime. The upload error lists what is allowed.

Return Values

Return JSON-serializable data:
return_values.py

Parameter Types

Supported Types

parameter_types.py

Type Validation

Type hints document what each parameter expects. They are not enforced, so convert or validate values yourself:
type_validation.py

Complex Types

Structured parameters arrive as plain JSON values (dicts and lists). Validate them with Pydantic inside run():
complex_types.py

Secrets

Store API keys and tokens as Function Secrets, either in the Console under Settings > Function Secrets, or with POST /secrets using the function_env namespace (client.secrets.store(...) in TypeScript). Every run of your functions receives them as environment variables:
read_secrets.py
Reading environment variables needs the os module, which the default code check rejects. Upload code that reads secrets with the check relaxed: function.update(path="read_secrets.py", restricted=False) in Python, or fn.update({ path: './read_secrets.py', restricted: false }) in TypeScript.

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

Run a Deployed Function Locally

Run the uploaded code on your machine, for example to debug it:
local_run.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

Bound how long each browser session can stay open, so a stuck page does not keep the run alive:
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