Skip to main content

nokap

Screenshots and PDFs from web pages. Powered by headless Chrome.

Python Versions PyPI License CI

nokap captures screenshots and PDFs from web pages (or local HTML) using headless Chrome via the Chrome DevTools Protocol. It doesn't need Selenium or Playwright. We use just one lightweight dependency (websockets).

Installation

pip install nokap

Chrome or Chromium must be installed on the system. nokap will hunt it down pretty quickly.

Quick Start

import nokap

# Screenshot a URL
nokap.webshot("https://example.com", "example.png")

# Save as PDF
nokap.webshot("https://example.com", "example.pdf")

# Screenshot with a CSS selector (captures just that element)
nokap.webshot("https://example.com", "header.png", selector="h1")

# From an HTML string (great for table libraries)
nokap.from_html("<h1>Hello, world!</h1>", "hello.png")

API

nokap.webshot()

Take a screenshot or PDF of a web page.

nokap.webshot(
    url,                # URL or local file path
    file="webshot.png", # Output path (.png, .jpg, .webp, .pdf)
    *,
    vwidth=992,         # Viewport width (px)
    vheight=744,        # Viewport height (px)
    selector=None,      # CSS selector to capture
    cliprect=None,      # Clip rectangle (x, y, width, height)
    expand=0,           # Padding around selector (px)
    delay=0.2,          # Wait after page load (seconds)
    zoom=1,             # Scale factor (2 = retina)
    useragent=None,     # Custom User-Agent string
)

nokap.from_html()

Render an HTML string to an image or PDF. Designed for integration with table/report libraries.

nokap.from_html(
    html,               # HTML content
    file="webshot.png", # Output path
    *,
    selector="html",    # CSS selector to capture
    **kwargs,           # All webshot() options
)

nokap.close()

Shut down the background Chrome process. Called automatically at exit, but available for explicit cleanup.

nokap.close()

How It Works

nokap communicates directly with Chrome over the Chrome DevTools Protocol via WebSockets. No browser driver binaries, no heavyweight automation frameworks.

The architecture:

  1. Launch: Finds and starts headless Chrome with a random debugging port
  2. Connect: Opens a WebSocket to Chrome's CDP endpoint
  3. Capture: Creates a tab, navigates, waits, then calls Page.captureScreenshot or Page.printToPDF
  4. Cleanup: Closes the tab; Chrome stays running for reuse until nokap.close() or process exit

Features

Feature Details
Image formats PNG, JPEG, WebP
PDF generation Configurable page size, margins, orientation
CSS selectors Capture specific elements (or union of multiple)
Zoom/scale Produce retina-quality (2×, 3×) images
Expand/padding Add whitespace around captured elements
Local HTML Render HTML strings or local .html files
Viewport control Set width/height for responsive layouts
Custom User-Agent Override the browser UA string
Auto-cleanup Chrome process managed via atexit
Jupyter-safe Works in notebooks (no event loop conflicts)

Configuration

Environment Variable Purpose
CHROME_PATH Override Chrome binary location

Requirements

  • Python ≥ 3.10
  • Chrome or Chromium installed on the system

License

MIT

Metadata

Release files for nokap 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 nokap 0.1.0
File Size Uploaded Provenance Actions
nokap-0.1.0.tar.gz 77.0 kB Without provenance Details for nokap-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 113.3 kB

Release files / nokap-0.1.0.tar.gz

Download URL nokap-0.1.0.tar.gz
Size 77.0 kB
Tags Source
SHA-256 checksum
How to use checksums
63071cf5e7c4f0487532f6281c6ea85d90673d5cd835ffe5e64c913989742eb9
BLAKE2b-256 checksum
How to use checksums
b9f7a4f3d6f89773df40884bc10790977c80a9ea17ad526ea0b0cd35a703595c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

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

Download URL nokap-0.1.0-py3-none-any.whl
Size 36.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
36f2cae8d4251945dbe311ef68916c7eddfe51da490aabe0d68c5d13294b2539
BLAKE2b-256 checksum
How to use checksums
73dcc35af5ccf8dbf3268750c54a3c0830f486b8faec38c811aff92335aa99ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Security for nokap 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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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 No 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