Skip to main content

scrapy-lightpanda

CI

An opt-in Scrapy downloader middleware that renders selected GET requests with Lightpanda via lightpanda-py. Unmarked requests continue through Scrapy's normal downloader.

Install

After publication, install the package with:

python -m pip install scrapy-lightpanda-middleware

For development from this repository:

python -m venv .venv
source .venv/bin/activate  # Windows: .venv\Scripts\activate
python -m pip install -e '.[dev]'

lightpanda-py bundles the Lightpanda executable for supported platforms.

Enable the middleware

Enable it in a spider's custom_settings or your Scrapy project's settings:

DOWNLOADER_MIDDLEWARES = {
    "scrapy_lightpanda.middleware.LightpandaMiddleware": 800,
}

Keep this middleware after Scrapy's request-preparation middleware, but before HTTP cache middleware. Priority 800 places it after Scrapy's default headers, cookies, and proxy middleware and before HTTP cache. Opted-in requests are marked uncacheable so rendered and ordinary responses cannot share cache entries.

Opt in individual requests with meta={"lightpanda": True}:

yield scrapy.Request(
    "https://example.com/javascript-page",
    callback=self.parse,
    meta={
        "lightpanda": True,
        "lightpanda_wait_until": "networkidle",
        "lightpanda_wait_selector": "main article",
    },
)

The middleware accepts these optional per-request settings:

  • lightpanda_wait_until: Lightpanda navigation readiness event, such as load, domcontentloaded, networkalmostidle, networkidle, or done.
  • lightpanda_wait_selector: CSS selector to wait for before returning the rendered page.

Only Accept, Accept-Language, and User-Agent are forwarded. Repeated Accept and Accept-Language values are combined, and User-Agent uses Lightpanda's dedicated option. Referer, cookies, authorization, and custom headers are not forwarded, even with opt-in: Lightpanda applies CLI headers to every outgoing request, including cross-origin subrequests. Sensitive origin headers cause a clear error when the opt-in is set rather than risking disclosure.

An unauthenticated Scrapy proxy (request.meta["proxy"]) is forwarded to Lightpanda. Scrapy's Basic proxy credentials are reconstructed from Proxy-Authorization into the proxy URL only when lightpanda_allow_sensitive_headers=True; other proxy authorization schemes are not supported. This opt-in is only for proxy credentials. Credentialed proxy values become subprocess arguments and may be visible to same-user process inspection; Lightpanda errors are redacted when such credentials are in use. Inherited proxy environment variables can override Scrapy's decision, so the middleware fails clearly if they conflict rather than silently using or bypassing a proxy.

Scrapy's per-request download_timeout (seconds), or the configured DOWNLOAD_TIMEOUT when no request override is set, becomes Lightpanda's http_timeout in milliseconds. Positive sub-millisecond values round up to one millisecond. Results without an HTTP status are treated as retryable download timeouts. The timeout limits Lightpanda's network request but is not a hard deadline for its subprocess; cancelling the Scrapy worker thread does not guarantee that the subprocess is stopped. Lightpanda also rejects browser-impersonating User-Agent strings containing Mozilla; use a compatible custom value if setting USER_AGENT.

The returned object is a Scrapy HtmlResponse, so callbacks can use the usual .css(), .xpath(), .text, and .url APIs. The synchronous Lightpanda fetch runs in a worker thread rather than blocking Scrapy's reactor. Lightpanda errors are passed back through Scrapy's normal request failure handling.

Only opted-in GET requests are supported. An opted-in request using another HTTP method raises Scrapy's NotSupported exception; it is not silently sent through a different request path.

Example

examples/spider.py issues one normal Scrapy request and one Lightpanda-rendered request to the same URL:

scrapy runspider examples/spider.py -a url=https://example.com

Lightpanda is a lightweight browser engine, not a full desktop browser. JavaScript and browser feature coverage can differ from Chromium or Firefox, so verify the rendered output for your target site.

JavaScript-rendered quotes example

examples/quotes_spider.py visits Quotes to Scrape's JavaScript demo, emits each quote's text, author, and tags, and follows the next-page link using Lightpanda for every page:

scrapy runspider examples/quotes_spider.py

Run it from this project directory after installation. It requires network access to the demo site.

Releases

The PyPI distribution is named scrapy-lightpanda-middleware (the Python import remains scrapy_lightpanda). Releases use PyPI Trusted Publishing; no PyPI API token is stored in GitHub.

Before the first release, configure a PyPI pending Trusted Publisher for:

  • PyPI project: scrapy-lightpanda-middleware
  • GitHub owner: bisdak
  • Repository: scrapy-lightpanda
  • Workflow filename: publish.yml (the file is .github/workflows/publish.yml)
  • GitHub environment: pypi

Create the pypi environment in GitHub repository settings with a required reviewer and deployment tags restricted to v*; enable prevention of self-review and disallow administrator bypass where the repository plan permits. Protect changes to the release workflow with required PR review/branch protection. These controls matter because PyPI trusts the configured workflow identity and environment, not the workflow's event trigger.

Once the pending publisher and environment protections are configured and CI is green, publish a GitHub Release tagged v0.1.0 to upload the first release. The release workflow verifies the tag matches pyproject.toml and publishes only after the full test matrix, wheel/sdist checks, and tests against the extracted source distribution pass. The shorter PyPI name scrapy-lightpanda belongs to a separate, unrelated project and must not be used.

Metadata

Release files for scrapy-lightpanda-middleware 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for scrapy-lightpanda-middleware 0.1.0
File Size Uploaded Provenance Actions
scrapy_lightpanda_middleware-0.1.0.tar.gz 14.7 kB With provenance Details for scrapy_lightpanda_middleware-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for scrapy-lightpanda-middleware 0.1.0
File Interpreter ABI Platform Actions
scrapy_lightpanda_middleware-0.1.0-py3-none-any.whl Python 3 none any Details for scrapy_lightpanda_middleware-0.1.0-py3-none-any.whl

Total release size: 23.0 kB

Release files / scrapy_lightpanda_middleware-0.1.0.tar.gz

Download URL scrapy_lightpanda_middleware-0.1.0.tar.gz
Size 14.7 kB
Tags Source
SHA-256 checksum
How to use checksums
1bde653ec09baba9c8fa51c30404f640bd55ae6250d15d007c88ef28938ffc8c
BLAKE2b-256 checksum
How to use checksums
1f90b53529a42c14a809c46592602368f22326faed7100b107add013388329d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Release files / scrapy_lightpanda_middleware-0.1.0-py3-none-any.whl

Download URL scrapy_lightpanda_middleware-0.1.0-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e114ac36b32a98a5d233feb187270640a4d50909f8af81d14162ca68edea0b1a
BLAKE2b-256 checksum
How to use checksums
c8ffab385c49d1008d70f66728f0d6b79b34272a8c94470a07f02ab350e9c0e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Security for scrapy-lightpanda-middleware 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for scrapy_lightpanda_middleware-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page