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.1.tar.gz (187.0 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.1-cp310-abi3-win_amd64.whl (33.5 MB view details)

Uploaded CPython 3.10+Windows x86-64

servo_fetch-0.13.1-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.1-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.1-cp310-abi3-macosx_11_0_arm64.whl (32.3 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

servo_fetch-0.13.1-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.1.tar.gz.

File metadata

  • Download URL: servo_fetch-0.13.1.tar.gz
  • Upload date:
  • Size: 187.0 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.1.tar.gz
Algorithm Hash digest
SHA256 4a8e7d02b235926ee9df3e3e852af3da1d374d331406a26146d749e1a95a6c8d
MD5 da5faeefb9a9fb9db6080d4f99742f84
BLAKE2b-256 a612291e3b1c438569432b1fe7f8f86d91442d558809bebd265a598d0a629c5d

See more details on using hashes here.

Provenance

The following attestation bundles were made for servo_fetch-0.13.1.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.1-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: servo_fetch-0.13.1-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 33.5 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.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 6ef49e8002a2e46836e6aceaa9c4ac00ac2f5047cd9496536037e72dd3c24276
MD5 ae509f9e573a4c3c4fec39fcf833f7e3
BLAKE2b-256 4e500aa2aa071d87a603d9dc346790fb5e4adc6eef46e8b996bee0c6e9b7ff52

See more details on using hashes here.

Provenance

The following attestation bundles were made for servo_fetch-0.13.1-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.1-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for servo_fetch-0.13.1-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d28c71fe751b427289c4f48417e90780f140ad4d9669c810066288d77b8ecb3a
MD5 7b5f4df1667dff6402b9d0b7a96e95c7
BLAKE2b-256 08b64744d0227fb7c8921902d6bbf6fe5d8b79c047390565214d77336464b6ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for servo_fetch-0.13.1-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.1-cp310-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for servo_fetch-0.13.1-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 c9118146e3604bc43732ccb08818f9b45187ca0c999bcfc38e11053b0b547415
MD5 6548a0ec8ea8c68539e9aaa7e63956b3
BLAKE2b-256 1b0a60a94b08f39a5da57d5d301b0f263bef825138e6f1c3ecef8814460d1ca8

See more details on using hashes here.

Provenance

The following attestation bundles were made for servo_fetch-0.13.1-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.1-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for servo_fetch-0.13.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9e02729919a4bb398510542e99f487e8b8e6738f81afceed353a8b8d4e597068
MD5 38e8cc4ad532f6b4bf96d00c9305de2d
BLAKE2b-256 41ecc813558e23be03239c8a0fd257ea2ce5056fee6d02d649c13bd045fbb4af

See more details on using hashes here.

Provenance

The following attestation bundles were made for servo_fetch-0.13.1-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.1-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for servo_fetch-0.13.1-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 1381f554991ffb22f2784b54e24a58bc995cbeac5746ac91c2632bfe95b5fea7
MD5 cfb46d4230f77b448401a6353e329e6c
BLAKE2b-256 56ac55c1965f940dc57022e33b606c4122b23dba5e9c0a2511eb654a184cff5b

See more details on using hashes here.

Provenance

The following attestation bundles were made for servo_fetch-0.13.1-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