Skip to main content

Browser engine in a library — fetch, render, and extract web content.

Project description

servo-fetch

CI PyPI Python uv Ruff

Python bindings for servo-fetch — fetch, render, and extract web content with an embedded Servo browser engine.

  • No Chromium — single binary, no browser download
  • JavaScript execution — full Servo engine with SpiderMonkey
  • Schema extraction — declarative CSS-selector → structured JSON, no LLM
  • Async-readyasyncio.to_thread wrappers, AsyncClient with streaming crawl
  • Typed — full .pyi stubs, works with ty / mypy / pyright

Install

pip install servo-fetch

Quick Start

import servo_fetch
page = servo_fetch.fetch("https://example.com")
page.html          # rendered HTML
page.inner_text    # document.body.innerText
page.markdown      # readable Markdown (lazy, cached)
page.title         # str | None

Schema Extraction

from servo_fetch import Schema, Field

schema = Schema(
    base_selector=".product",
    fields=[
        Field(name="title", selector="h2", type="text"),
        Field(name="price", selector=".price", type="text"),
        Field(name="url", selector="a", type="attribute", attribute="href"),
    ],
)

page = servo_fetch.fetch("https://shop.example.com", schema=schema)
page.extracted  # [{"title": "...", "price": "...", "url": "..."}]

Session Cookies

To fetch authenticated pages, pass a str or os.PathLike path to a Netscape-format cookies.txt via cookies_file:

import servo_fetch

page = servo_fetch.fetch("https://app.example.com/dashboard", cookies_file="cookies.txt")

# Also accepted by Client.fetch / Client.crawl and their async equivalents.
client = servo_fetch.Client(user_agent="MyBot/1.0")
pages = client.crawl("https://app.example.com", cookies_file="cookies.txt", max_pages=20)

A missing or malformed file raises servo_fetch.CookieError. Cookies are scoped to the target's site, so out-of-scope entries in the file are ignored.

Custom Headers

Pass a dict[str, str] via headers to add request headers (e.g. API tokens). Accepted by fetch, Client.fetch / Client.crawl / Client.map, and their async equivalents:

import servo_fetch

page = servo_fetch.fetch("https://api.example.com", headers={"Authorization": "Bearer TOKEN"})

Framing headers (Host, Content-Length, …) are rejected, and User-Agent / Cookie have dedicated options; invalid headers raise ValueError.

Async

from servo_fetch import fetch_async, AsyncClient

page = await fetch_async("https://example.com")

async with AsyncClient(user_agent="MyBot/1.0") as client:
    async for page in client.crawl_stream("https://docs.example.com", max_pages=50):
        print(page.url, page.title)

Develop

Requires uv.

uv sync --group all              # create venv + install dev deps
uv run maturin develop           # build extension (debug, fast compile)
uv run pytest                    # run tests
uv run ruff check python tests   # lint
uv run ty check python           # type check

Troubleshooting

Linux: "cannot allocate memory in static TLS block"

Servo's native extension uses large thread-local storage. On some Linux systems, set before importing:

export GLIBC_TUNABLES=glibc.rtld.optional_static_tls=16384

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

servo_fetch-0.13.0.tar.gz (186.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

servo_fetch-0.13.0-cp310-abi3-win_amd64.whl (33.4 MB view details)

Uploaded CPython 3.10+Windows x86-64

servo_fetch-0.13.0-cp310-abi3-manylinux_2_28_x86_64.whl (37.8 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64

servo_fetch-0.13.0-cp310-abi3-manylinux_2_28_aarch64.whl (36.8 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

servo_fetch-0.13.0-cp310-abi3-macosx_11_0_arm64.whl (32.3 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

servo_fetch-0.13.0-cp310-abi3-macosx_10_12_x86_64.whl (34.1 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file servo_fetch-0.13.0.tar.gz.

File metadata

  • Download URL: servo_fetch-0.13.0.tar.gz
  • Upload date:
  • Size: 186.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for servo_fetch-0.13.0.tar.gz
Algorithm Hash digest
SHA256 21309613f549fdaf8db9422c394c8214ae3c65030f37caad4af7ea91092c2a9d
MD5 b0eabe918d7813abceea84cbf4008768
BLAKE2b-256 a2af06c6d1816c69e3f92347da25615a904085a6ffcf2839699634878bb7f1d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for servo_fetch-0.13.0.tar.gz:

Publisher: release-python.yml on konippi/servo-fetch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file servo_fetch-0.13.0-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: servo_fetch-0.13.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 33.4 MB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for servo_fetch-0.13.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 b7c86767b5f41e83b16b4796739c36452f01fdbfa2be6e180820acb31e1d53b8
MD5 a8d71ba1ed94de635314b205318595c1
BLAKE2b-256 7756eb611af731d1d6235975252d04113a3394596bd1ba96a6d25e8564132769

See more details on using hashes here.

Provenance

The following attestation bundles were made for servo_fetch-0.13.0-cp310-abi3-win_amd64.whl:

Publisher: release-python.yml on konippi/servo-fetch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file servo_fetch-0.13.0-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for servo_fetch-0.13.0-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b92e58075946963c62bb49e12de235340be94cacfa39a68aa347a1c4d12368c8
MD5 d04d48e9fc89b0daf39075a07bb4c335
BLAKE2b-256 51662372b6f70730897164d27006750ffc294c55fb613c44c4242fbdce55bb6a

See more details on using hashes here.

Provenance

The following attestation bundles were made for servo_fetch-0.13.0-cp310-abi3-manylinux_2_28_x86_64.whl:

Publisher: release-python.yml on konippi/servo-fetch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file servo_fetch-0.13.0-cp310-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for servo_fetch-0.13.0-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 7b6d2c047cd3d051455dcbcf3d13c30dd42dd708bed4e33420bb74838f80afe2
MD5 954011979e9ac17c2feb8e8fd18a3e78
BLAKE2b-256 65d14f85df55a8f611d603070848b5f592a59178bf443430397382591b1ddf3d

See more details on using hashes here.

Provenance

The following attestation bundles were made for servo_fetch-0.13.0-cp310-abi3-manylinux_2_28_aarch64.whl:

Publisher: release-python.yml on konippi/servo-fetch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file servo_fetch-0.13.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for servo_fetch-0.13.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6b218136e04c1069b7d2d083e83b861bcd048193502b2c60e7055cc4d78e02be
MD5 8028544740bf820c551112b508da20ed
BLAKE2b-256 2267a6052c65c98d06e6c667f6055aaf0951c987d7bd391628c187fd7c65a939

See more details on using hashes here.

Provenance

The following attestation bundles were made for servo_fetch-0.13.0-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: release-python.yml on konippi/servo-fetch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file servo_fetch-0.13.0-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for servo_fetch-0.13.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 9290188d3036f34678f6d2178c0b82529c3dc98685931b0ca6c87e27306591e3
MD5 7549387b5e7dbadd3c70c4b4266ad65f
BLAKE2b-256 963984b19e6a42630a5e1da05e15ab4d638155e8329c50793b71653f26811093

See more details on using hashes here.

Provenance

The following attestation bundles were made for servo_fetch-0.13.0-cp310-abi3-macosx_10_12_x86_64.whl:

Publisher: release-python.yml on konippi/servo-fetch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page