Skip to main content

Python wrapper for the urlscan.io API.

Project description

urlscope

urlscope is an async-first Python wrapper for the urlscan.io API. It provides typed Pydantic models for common API responses, automatic API key handling, built-in retry logic for rate limits, and a sync convenience wrapper for scripts.

Installation

pip install urlscope

If you want to install the current prerelease from PyPI, use:

pip install --pre urlscope

Set your API key before making requests:

export URLSCAN_API_KEY="your-api-key-here"

Quickstart

Async submit and wait

import asyncio
from urlscope import UrlscopeClient


async def main() -> None:
    async with UrlscopeClient() as client:
        result = await client.submit_and_wait(
            "https://example.com",
            visibility="public",
        )
        overall = result.verdicts.overall if result.verdicts else None
        print(result.task.uuid)
        print(result.page.url)
        print(overall.score if overall else None)


asyncio.run(main())

Sync usage

from urlscope import SyncClient


with SyncClient() as client:
    result = client.get_result("scan-uuid-here")
    print(result.page.url)

Search

import asyncio
from urlscope import UrlscopeClient


async def main() -> None:
    async with UrlscopeClient() as client:
        response = await client.search(
            "domain:example.com",
            size=10,
            datasource="scans",
        )
        print("total:", response.total, "took:", response.took)

        for item in response.results:
            page_url = item.page.get("url") if item.page else None
            print(item.id, page_url, item.result)

        # Cursor-based pagination is handled via the previous item's sort key.
        if response.has_more and response.results and response.results[-1].sort:
            next_page = await client.search(
                "domain:example.com",
                size=10,
                search_after=response.results[-1].sort,
                collapse="page.domain.keyword",
            )
            print(len(next_page.results))


asyncio.run(main())

Download artifacts

import asyncio
from urlscope import UrlscopeClient


async def main() -> None:
    async with UrlscopeClient() as client:
        screenshot = await client.get_screenshot("scan-uuid-here")
        dom = await client.get_dom("scan-uuid-here")
        print(len(screenshot), len(dom))


asyncio.run(main())

Check quotas

import asyncio
from urlscope import UrlscopeClient


async def main() -> None:
    async with UrlscopeClient() as client:
        quotas = await client.get_quotas()
        print(quotas.scope)
        for q in quotas.quotas[:5]:
            print(q.scope, q.action, q.window, q.used, q.remaining, q.limit, q.reset)


asyncio.run(main())

The live quotas response is also available in raw form via QuotaInfo.limits, including account metadata that is not flattened into QuotaInfo.quotas.

Error handling

import asyncio
from urlscope import RateLimitError, ScanTimeoutError, UrlscopeClient


async def main() -> None:
    async with UrlscopeClient() as client:
        try:
            await client.submit_and_wait("https://example.com", poll_timeout=120.0)
        except ScanTimeoutError as exc:
            print(exc.uuid)
        except RateLimitError as exc:
            print(exc.retry_after, exc.scope, exc.window)


asyncio.run(main())

submit(..., override_safety=True) is supported by the wrapper and is serialized to the current live urlscan wire format for overrideSafety.

API Reference

Primary clients:

  • UrlscopeClient: async interface for submit, result retrieval, polling, search, artifacts, and quotas
  • SyncClient: sync wrapper with the same method surface for scripts and simple integrations

Key response models:

  • SubmissionResponse
  • ScanResult, TaskInfo, PageInfo, Verdicts, BrandMatch, ScanLists, CertificateInfo
  • SearchResponse, SearchResultItem
  • QuotaInfo, QuotaWindow

ScanResult.verdicts follows the live urlscan structure with nested sections such as overall, urlscan, engines, and community. For example, use result.verdicts.overall.score for the top-level score.

SearchResponse includes total, took, has_more, and results. SearchResultItem exposes stable top-level fields such as id, score, sort, page, task, stats, result, and screenshot, while preserving less consistent live API sections as model extras. Search supports optional datasource and collapse parameters, and serializes search_after cursors in the comma-separated form expected by urlscan.

Search uses urlscan's searchable index. If you already have an exact scan UUID, prefer get_result(uuid); a retrievable UUID is not guaranteed to appear in search results under every account plan or index state.

Key exceptions:

  • UrlscopeError
  • AuthenticationError
  • ValidationError
  • NotFoundError
  • ScanDeletedError
  • RateLimitError
  • ScanTimeoutError
  • APIError

Development

uv sync --extra dev
.venv/bin/pytest tests/
.venv/bin/ruff check src/ tests/
.venv/bin/mypy src/
.venv/bin/python -m build
.venv/bin/python -m twine check dist/*

The package version is defined in src/urlscope/__init__.py and read dynamically by Hatchling during builds.

License

MIT

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

urlscope-0.1.3rc2.tar.gz (47.7 kB view details)

Uploaded Source

Built Distribution

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

urlscope-0.1.3rc2-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file urlscope-0.1.3rc2.tar.gz.

File metadata

  • Download URL: urlscope-0.1.3rc2.tar.gz
  • Upload date:
  • Size: 47.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for urlscope-0.1.3rc2.tar.gz
Algorithm Hash digest
SHA256 8d0f768e681e7202f648f3c4478cc3507d06342cbde5f6fe1962a2f6d0562c73
MD5 7a3355db7f34f3002e123205bfe96168
BLAKE2b-256 7ce8c4bb68a156c6c2e87a92fa4d1e0f8c101336e5539e7af9d02200fd9387d5

See more details on using hashes here.

Provenance

The following attestation bundles were made for urlscope-0.1.3rc2.tar.gz:

Publisher: publish-pypi.yml on janwychowaniak/urlscope

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

File details

Details for the file urlscope-0.1.3rc2-py3-none-any.whl.

File metadata

  • Download URL: urlscope-0.1.3rc2-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for urlscope-0.1.3rc2-py3-none-any.whl
Algorithm Hash digest
SHA256 ec65ffaf48b85d83c22d9ac8ffc2e1b50ad3d6b74b44a25ef8d8d0909b5349e8
MD5 e47edfe862e15cfba8e78361fd42c46a
BLAKE2b-256 e54835cece63fd338316f22c6641e22454acbc7faa5c6628ad1a261a0b636c97

See more details on using hashes here.

Provenance

The following attestation bundles were made for urlscope-0.1.3rc2-py3-none-any.whl:

Publisher: publish-pypi.yml on janwychowaniak/urlscope

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