The simplest approach is automatic cookie persistence using cookie_file:
automatic_persistence.py
from notte_sdk import NotteClientclient = NotteClient()# Cookies automatically loaded at start, saved when session endswith client.Session(cookie_file="cookies.json") as session: page = session.page page.goto("https://example.com/login") # Log in once, cookies are captured page.fill('input[name="email"]', "user@example.com") page.fill('input[name="password"]', "password") page.click('button[type="submit"]')# Next time: already logged in!with client.Session(cookie_file="cookies.json") as session: page = session.page page.goto("https://example.com/dashboard") # Authentication persisted from previous session
The cookie_file parameter handles everything automatically - loading cookies when the session starts and saving them when it ends.
For more control, use set_cookies() and get_cookies():
manual_cookie_management.py
import jsonfrom notte_sdk import NotteClientclient = NotteClient()# Save cookies from a sessionwith client.Session() as session: page = session.page page.goto("https://example.com") # Perform login... # Get and save cookies cookies = session.get_cookies() with open("cookies.json", "w") as f: json.dump(cookies, f)# Load cookies in a new sessionwith client.Session() as session: with open("cookies.json", "r") as f: cookies = json.load(f) session.set_cookies(cookies=cookies) page = session.page page.goto("https://example.com/dashboard") # Already authenticated
from typing import Anyfrom notte_sdk import NotteClient# Upload cookies for github.com to automatically logincookies: list[dict[str, Any]] = [ { "name": "sb-db-auth-token", "value": "base64-cookie-value", "domain": "github.com", "path": "/", "expires": 9778363203.913704, "httpOnly": False, "secure": False, "sameSite": "Lax", }]# create a new sessionclient = NotteClient()with client.Session() as session: _ = session.set_cookies(cookies=cookies) # type: ignore[arg-type] # can also set cookie_file="path/to/cookies.json" # Use the cookies in your session agent = client.Agent(session=session, max_steps=5) res = agent.run( task="go to nottelabs/notte get repo info. Fail if you are not logged in", url="https://github.com/nottelabs/notte", ) # or get the cookies from the session cookies_resp = session.get_cookies()
import jsonfrom pathlib import Pathfrom patchright.sync_api import sync_playwrightcookie_path = Path("github_cookies.json")# Initialize Playwrightwith sync_playwright() as playwright: browser = playwright.chromium.launch(headless=False) context = browser.new_context() page = context.new_page() # Navigate to login page github_login_url = "https://github.com/login" page.goto(github_login_url) print("Please log into GitHub in the browser window...") input("Press Enter after you've logged in...") # Save cookies to file print("Login successful. Saving cookies...") cookies = context.cookies(urls=["https://github.com"]) if cookies: cookie_path.write_text(json.dumps(cookies, indent=4)) print(f"Cookies saved to {cookie_path}") else: print("No cookies found to save.")
import jsonfrom notte_sdk import NotteClientclient = NotteClient()with client.Session() as session: # Observe the state of a webpage obs = session.observe(url="https://google.com/travel/flights") # Get and save cookies from the session with open("cookies.json", "w") as f: cookies = session.get_cookies() json.dump(cookies, f)