Python SDK

Complete method reference for the Crawlingo Python SDK (PyO3 bindings). Requires Python 3.8+.

12 min read Updated July 2026
ℹ️

Installation

pip install crawlingo — Python 3.8+. Pre-built wheels for Linux (x86_64, aarch64), macOS (Intel, Apple Silicon), Windows AMD64.

Session

Central config container. All operations bind to a Session and share its FetchManager, rate limiter, connection pool, middleware stack, and fingerprint store. Use as a context manager for automatic cleanup.

MethodReturnsDescription
Session() / Session.from_config(path)SessionCreate from defaults or TOML/env config
.headers(dict)SelfDefault HTTP headers for all requests
.cookies(dict)SelfDefault cookies for all requests
.proxy(str)SelfSingle proxy URL
.proxy_pool(list)SelfRound-robin proxy rotation list
.proxy_provider(str)SelfRemote proxy list endpoint URL
.rate_limit(float)SelfPer-host req/s (0.0 = unlimited)
.auto_match(bool)SelfEnable self-healing selector repair
.auto_match_weights(*floats)SelfFingerprint similarity weights (tag, class, id, attr, text, parent, pos, sibling, depth)
.timeout(int)SelfRequest timeout in seconds
.fetcher_tier(str)Self"standard" or "stealthy"
.browser_profile(str)Self"chrome", "firefox", or "safari"
.cache_enabled(bool)SelfEnable response caching (Cache-Control, ETag aware)
.retry_base_delay(int)SelfInitial retry delay (ms)
.retry_max_delay(int)SelfMaximum retry delay (ms)
.retry_multiplier(float)SelfExponential backoff factor
.basic_auth(user, pass)SelfHTTP Basic Auth
.bearer_auth(token)SelfBearer token auth
.header_auth(name, value)SelfCustom auth header
.api_key_auth(param, value)SelfQuery parameter API key
.auth_oauth2(client_id, secret, token_url)SelfOAuth2 with auto-refresh on 401
.page(url)PageFetch a page using this session
.metrics()dictLock-free metrics snapshot
.clone()SessionClone session and its config
.destroy()NoneDestroy session and release resources

Page

MethodReturnsDescription
Page(url, session?)PageFetch and parse URL (sync)
.title()str<title> text content
.html()strRaw HTML string
.markdown()strGitHub-flavored markdown
.statusintHTTP response status code
.css(selector)ElementListCSS query — returns ElementList
.xpath(expr)ElementListXPath query — returns ElementList
.regex(pattern)MatchListRegex matches against all visible text
.find_text(text)ElementListSIMD text anchor lookup
.after_text(text)ElementListSibling element after text anchor
.before_text(text)ElementListSibling element before text anchor

ElementList & ElementRef

element_ref.py
python
1els = page.css("div")
2els.first() # First match or None
3els.last() # Last match or None
4els.at(i) # i-th match
5len(els) # Count of matches
6for e in els: # Iterable
7 pass
8
9e = els.first()
10e.text() # Trimmed text content
11e.html() # Inner HTML
12e.outer_html() # Including element tag
13e.attr("href") # Attribute value
14e.tag() # Tag name (lowercase)
15e.classes() # ["class-a", "class-b"]
16e.parent() # Parent ElementRef
17e.children() # Direct children
18e.next_sibling() # Next sibling
19e.prev_sibling() # Previous sibling

Dataset

MethodReturnsDescription
Dataset(url, session?)DatasetCreate for a URL
.field(name, selector, selector_type?, transform?, default?)SelfAdd extraction field
.with_schema(schema)SelfApply DatasetSchema validation
.build()DatasetResultExecute extraction synchronously
.build_async()Awaitable[DatasetResult]Execute extraction asynchronously
.build_structured()list[dict]Extract multi-row table records from a page
→ .to_dict()dictFields as Python dict
→ .to_json(path)NoneWrite JSON file
→ .to_csv(path)NoneWrite CSV file
→ .to_parquet(path)NoneWrite Apache Parquet file
→ .df()DataFrameReturn as Pandas DataFrame

Extraction Types

TypeInput → OutputUse Case
text" Hello " → "Hello"General text trimming (default)
price"$1,234.56" → "1234.56"Currency normalization
datetime"Jan 15, 2024" → "2024-01-15"Date standardization to ISO 8601
url"/path" → "https://base.com/path"Relative URL resolution
datalink_url<a href="..."> → href valueLink extraction
datalink_email"mailto:a@b.com" → "a@b.com"Email extraction
datalink_phone"tel:+1234" → "+1234"Phone number extraction

Schema & Pagination Config

New in v1.0.0-beta.1: Configure crawl pagination loops and validate extracted datasets against strict schemas.

PaginationConfig

Exposes factory methods to configure crawl navigation:

  • crawlingo.PaginationConfig.next_link(selector: str)
  • crawlingo.PaginationConfig.page_number(template: str, start: int, max: int)
  • crawlingo.PaginationConfig.url_pattern(regex: str, max_page: int)
  • Configure on Crawl: crawl.with_pagination(config)
  • Resumable crawls: Crawl.resumable(url, session, db_path)
DatasetSchema

Validate types and required fields on datasets:

  • schema = crawlingo.DatasetSchema()
  • schema.add_field(name: str, field_type: FieldType, required: bool)
  • FieldType options: String, Integer, Float, Boolean
  • Attach to Dataset: dataset.with_schema(schema)
  • Run async: await dataset.build_async()

Crawl & Watch

See the Quick Start for full Crawl and Watch examples. Key builder methods:

Crawl
  • .follow(css)
  • .limit(n)
  • .depth(n)
  • .concurrency(n)
  • .delay(secs)
  • .field(name, sel, selector_type?, default?)
  • .with_pagination(config)
  • .webhook(url)
  • .build() → CrawlResults
  • CrawlResults.to_json(path)
  • CrawlResults.to_csv(path)
  • CrawlResults.to_parquet(path)
Watch
  • .field(name, sel, selector_type?, transform?, default?)
  • .interval(secs)
  • .on_change(fn)
  • .on_price_change(fn)
  • .on_stock_change(fn)
  • .on_element_added(fn)
  • .on_element_removed(fn)
  • .run() # blocking
  • .run_async() # awaitable
  • .stop()