The official Python SDK for Maxun
Repo getmaxun/python-sdk, read from GitHub 27 min ago. getmaxun has not joined Take My Repo.
This release rebuilds the Python SDK around a single entry point, with simpler calls and cleaner output, and fixes several features that did not work in 0.0.12.
pip install --upgrade maxun
⚠️ Please upgrade to the latest version 0.0.13 for the best experience.
Maxun()Every feature hangs off one object. Each call takes the robot name first, then a URL, query or file, then keyword arguments.
import asyncio from maxun import Maxun
async def main():
async with Maxun(api_key="your-api-key") as maxun:
robot = await maxun.scrape("Maxun home", "https://maxun.dev", formats=["markdown", "html"])
result = await robot.run()
print(result.markdown)
asyncio.run(main())
| Call | Creates |
|---|---|
| maxun.scrape(name, url, ...) | A robot that turns a page into Markdown, HTML, text, links, a summary or screenshots |
| maxun.extract(name, url, prompt=...) | A robot that extracts data described in plain English |
| maxun.extract(name, url) | A selector robot builder: chain capture_text, capture_list, click... then .build() |
| maxun.crawl(name, url, ...) | A robot that crawls a website |
| maxun.search(name, query, ...) | A robot that searches the web |
| maxun.documents.extract(name, file, prompt) / .parse(name, file) | A robot that reads PDF, DOCX, XLSX, CSV, JPG and PNG files |
| maxun.robots | Lists, finds and deletes robots of any type |
Each resource can also list its robots: maxun.scrape.list(), maxun.crawl.list(), maxun.robots.list(type="search"), maxun.robots.find("Pricing page").
async needed: MaxunSyncMaxunSync has the same API without await, so it works in plain scripts and in Jupyter:
from maxun import MaxunSync
with MaxunSync() as maxun:
robot = maxun.scrape("Example", "https://example.com")
print(robot.run().markdown)
Options are plain keyword arguments with defaults that work out of the box:
await maxun.crawl("Docs", "https://docs.example.com", limit=100, include_paths=["/guides/*"])
await robot.schedule(run_every=6, run_every_unit="HOURS", timezone="Asia/Kolkata")
await robot.add_webhook("https://your-app.com/hook", events=["run_failed"], retry_attempts=5)
robot.run() returns only the run id, the status and the outputs the run produced:
{'runId': 'b05cea93-…', 'status': 'success', 'markdown': '# Example Domain…'}
result.markdown, result.list_data, result.crawl_data, result.search_data, result.document_data and so on.{"id", "name", "type"}, so print() and json.dumps show just that.{"id", "runId", "robotId", "name", "status", "startedAt", "finishedAt"}, with ISO UTC times.Pass monitor=True and every run is compared with the previous successful run:
robot = await maxun.scrape("Pricing watch", "https://example.com/pricing", monitor=True)
result = await robot.run()
if result.has_changes:
diff = await robot.get_run_diff(result.run_id)
hasChanges and changedFormats appear only on robots with monitoring on. Crawl robots also report which pages were added, removed or changed. You can turn monitoring on for an existing robot with await robot.set_monitoring(True).
run() waits for the run to finish, however long it takes, instead of giving up after 5 minutes. Pass timeout= (seconds) to stop waiting sooner.run(formats=..., smart_queries=...) changes the formats or asks a question for a single run.get_runs(), get_latest_run(), get_run(id) and abort(id). run.result gives the output of any run, including scheduled ones.AuthenticationError, NotFoundError, ConflictError, ValidationError and RunFailedError. All of them are subclasses of MaxunError.run.completed) that the server never sent. The SDK now uses run_completed and run_failed, and translates the old names with a warning. Webhooks saved with the old names need to be added again.limit or max_depth crawled nothing. Crawls now default to 50 pages and depth 3.Extract.get_robots() crashed with KeyError. It now works.scroll() did nothing. It now scrolls by a number of screen heights, e.g. scroll(pages=2).src layout, so its types module can no longer shadow Python's standard library. from maxun import * exports only the public API.Most 0.0.x code keeps working: Scrape(Config(...)), Extract(Config(...)), awaiting a builder and result["data"][...] are all still supported. Check these:
mode="discover", which returns titles, URLs and snippets. Leaving out mode used to scrape every result; pass mode="scrape" for that.robot.get_schedule() and robot.get_webhooks() are async and read fresh data from the server, so they also see changes made in the app. await them. get_schedule() returns None when there is no schedule, and get_webhooks() returns [] (not None) when there are no webhooks.ScheduleConfig, WebhookConfig, ExecutionOptions, CrawlConfig, SearchConfig, ExtractListConfig and PaginationConfig still import, with a DeprecationWarning. Use keyword arguments instead.run["serializableOutput"] can still be read, and get_data() returns the full record.set_cookies() and mode() were never supported by the server. They now warn and do nothing.Config reads MAXUN_API_KEY, MAXUN_BASE_URL and MAXUN_TEAM_ID when arguments are left out. The default URL is still Maxun Cloud.