The Python library for the VulnRadar security scanning API: scan addresses and
crawl sites, read your scan history, download reports and check webhooks, with typed
results and errors. It uses version 3 of the API (/api/v3).
Version 3 is a beta. Releases before it (0.1.0, 2.0.0b1 and 2.0.0b2) call API versions that no longer exist and do not work. Version 0.1.0 also prints API responses to the console.
Scan only sites you own or have written permission to test. Using this library means using VulnRadar, under its Terms of Service, Acceptable Use Policy and Privacy Policy.
It talks only to the server of the API address you configure,
https://vulnradar.dev/api/v3 unless you change it (client.version() reads
/api/version on the same server). It sends your API key, what you pass to a call (such as the target and any
login details), and two headers naming the library: a User-Agent with the library and
Python versions, and x-vulnradar-client with the library version, which servers from
4.0 record against the key. It has no analytics or other telemetry.
Python 3.11 or newer.
pip install "vulnradar>=3.0.0b1"Name the version while 3.0 is a beta: a plain pip install vulnradar still picks an old
release. If PyPI has no 3.0 release yet, install from the repository:
pip install git+https://github.com/VulnRadar/Python-SDKfrom vulnradar import VulnRadar
client = VulnRadar(api_key="your-api-key")
result = client.scan("https://example.com")
print(f"Total findings: {result.summary.total}")
print(f"Critical: {result.summary.critical}")
for finding in result.findings:
print(f"[{finding.severity.value.upper()}] {finding.title}")All requests are authenticated using a Bearer token in the Authorization header. Set
VULNRADAR_TOKEN in the environment, or pass the key when constructing the client:
client = VulnRadar() # reads VULNRADAR_TOKEN
client = VulnRadar(api_key="your-api-key")client = VulnRadar(
api_key="your-api-key",
base_url="https://vulnradar.dev/api/v3", # or set VULNRADAR_API_BASE
timeout=30, # seconds to wait for the server
retries=2, # extra attempts for reads
)base_urlmust include the API path and usehttps. Plainhttpis accepted only for this computer (localhost,127.0.0.1or::1) and never goes through a proxy.- Only reads are retried, after a network failure or a 5xx reply. A request that starts or
deletes something is sent once. A
Retry-Afterof up to 30 seconds is honoured; a longer one is reported to you instead. - Redirects are never followed.
- Settings that cannot work, such as a missing key, raise
ValueError.
The server runs a scan in the background. scan() starts it, asks every few seconds how
it is going, and returns the finished result. Asking does not use up any quota.
from vulnradar import Scanner
result = client.scan("https://example.com")
# Optional: run only some scanners, keep the result out of the public directory,
# and wait no longer than two minutes.
result = client.scan(
"https://example.com",
scanners=[Scanner.HEADERS, Scanner.SSL],
public=False,
timeout=120,
)
print(result.url, result.scanned_at, result.duration_ms, result.scan_history_id)
for finding in result.findings:
print(finding.severity, finding.title)
print(finding.description)
for step in finding.fix_steps:
print(" -", step)
if result.incomplete:
print("Not everything was checked:", ", ".join(result.incomplete))A scan without findings is not necessarily clean: check result.incomplete, which lists
what was not checked. page-checks means some checks failed to run, and
crawl-pages-not-scanned means a crawl left pages out, for example when your quota ran
out. Servers before 4.0 report failed checks for single scans only, not for the pages of a
crawl. Findings your account marked as false positives are included, with
finding.suppressed set.
Scanner names are checked before anything is sent, because some servers accept a misspelt
one and then check nothing. The other options are capture_screenshot, port_scan (needs
a verified domain) and team_ids.
A target may be written without a scheme (example.com). Servers before 4.0 scan only
http and https.
job = client.scans.start("https://example.com")
status = client.scans.status(job.id)
print(status.state, status.categories_completed, status.categories_total)
result = client.scans.wait(job.id, timeout=600) # or client.scans.cancel(job.id)scan() and wait() wait 960 seconds unless you pass timeout.
wait() raises ScanFailedError if the scan fails or is cancelled, and ScanTimeoutError
if it is still running after timeout seconds. A scan that times out keeps running, so you
can wait for it again. Errors raised while waiting carry the scan's id in scan_id.
| Field | Type | Description |
|---|---|---|
url |
str |
Scanned address |
findings |
list[Finding] |
Security findings |
summary |
Summary |
Finding counts by severity |
incomplete |
list[str] |
What was not checked |
scanned_at |
datetime | None |
When the scan ran |
duration_ms |
int | None |
How long it took, in milliseconds |
scan_history_id |
int | None |
Id in your scan history |
public_id |
str | None |
Text id of the scan |
response_headers |
dict[str, str] |
HTTP headers from the target |
tags |
list[str] |
Tags on the scan |
notes |
str | None |
Your notes |
raw |
dict |
Everything the server sent, such as siteGrade or dnsRecords |
A Finding has id, title, severity, description, category, evidence,
explanation, risk_impact, fix_steps, code_examples, references, suppressed,
remediation_status and raw.
Scan several pages of a site. Each page counts as one scan against your daily quota, and your plan caps how many pages one crawl may take.
result = client.scan_crawl("https://example.com")
print(f"Pages scanned: {result.pages_scanned}, skipped: {result.pages_skipped}")
print(f"Total findings: {result.summary.total}")
for page in result.pages:
print(f"{page.url}: {page.summary.total} findings")A CrawlResult is a ScanResult for the whole site, plus pages, pages_discovered,
pages_scanned, pages_skipped and pages_unreachable. You can name the pages to scan,
and start a crawl without waiting with client.scans.start_crawl().
result = client.scan_crawl(
"https://example.com",
urls=["https://example.com/login", "https://example.com/admin"],
)Discover all crawlable URLs for a target before running a crawl scan:
discovery = client.discover_urls("https://example.com")
print(f"Found {discovery.total} URLs")
for url in discovery.urls:
print(url)# Queue many addresses. Wait for each with client.scans.wait(entry["scanId"]).
queued = client.scans.bulk(["https://example.com", "https://example.org"])
for entry in queued["results"]:
print(entry["url"], entry.get("scanId") or entry.get("error"))
# Scan while signed in. This returns when the scan is done.
result = client.scans.authenticated(
"https://example.com/account",
{"method": "header", "headerName": "Authorization", "headerValue": "Bearer ..."},
)
print(result.summary.total, result.incomplete)
found = client.discovery.subdomains("example.com")["subdomains"]
names = [entry["subdomain"] for entry in found]
verdict = client.reputation("example.com")
demo = client.demo_scan("example.com") # a few per day per network addressThe login is sent to the server as you give it: form with username and password
(your domain must be verified; loginUrl and the field names are optional), header
with headerValue, or cookie with cookies as a list of name and value. If the
session was lost, result.incomplete includes authenticated-session.
bulk(), subdomains() and reputation() return the server's reply as a dictionary.
A reputation that is not known does not mean a host is safe. Servers before 4.0 do not
say in a signed-in or demo scan's reply when some checks failed to run.
With the server's AI turned on, you can review findings and summarise a scan:
reviewed = client.scans.verify(123)
text = client.history.summary(123)A reviewed finding has raw["aiVerdict"]. If none got a verdict, the call raises
UnexpectedResponseError instead of returning findings that look approved.
Check each delivery against your webhook's secret, using the raw request body:
from vulnradar import verify_webhook
def handle(body: bytes, headers: dict[str, str]) -> int:
if not verify_webhook("your-webhook-secret", body, headers):
return 401
return 204Servers from 4.0 also sign a timestamp. If yours does, pass require_timestamp=True, so
an old delivery cannot be sent to you again. Deliveries can be repeated, so make your
handler safe to run twice. Before 4.0, test deliveries are not signed.
GitHub repository scans are not part of this history.
page = client.history.list(limit=20, query="example.com")
print(f"{page.matched} scans match")
for scan in page.scans:
if scan.summary is None:
print(scan.id, scan.url, scan.status)
else:
print(scan.id, scan.url, f"{scan.summary.total} findings")summary and findings_count are None for a scan that is still running or failed, so it
never looks like a scan without findings. A finished scan can still be partial: the list
does not say so on servers before 4.0, so check incomplete on history.get() before
calling a scan clean. Servers before 4.0 also keep each page of a crawl as its own scan
without that information, so a page that could not be fetched reads as clean.
iterate() goes through every page for you; each page uses one request of your key's
quota. A scan that finishes while you iterate can be missed.
for scan in client.history.iterate(tag="nginx"):
print(scan.id, scan.url, scan.scanned_at)result = client.history.get(123) # the numeric or the text id
print(result.url)
for finding in result.findings:
print(finding.title, finding.severity)A crawl comes back as a CrawlResult. A scan that is still running or failed raises
NoResultError.
from pathlib import Path
from vulnradar import ReportFormat
report = client.history.report(123, ReportFormat.PDF)
Path("report.pdf").write_bytes(report.content)
if report.incomplete:
print("Not everything was checked:", report.incomplete)A report takes two requests: the scan is read first, and one that is still running or
failed raises NoResultError, because the server's report of it would list no findings.
The formats are JSON, SARIF, PDF, MARKDOWN, COMPLIANCE and CSV.
include_suppressed keeps findings marked as false positives, and apply_triage applies
your triage.
client.history.update(123, notes="Checked", public=False)
client.history.delete(123)
client.history.delete_all(confirm=True) # every scan, and it cannot be undoneDeleting needs a key with the scan:delete permission, which new keys do not have.
account = client.me()
print(account.plan, account.scopes, account.quota)scopes and quota are None on servers before 4.0. This is a cheap way to test a key.
client.metadata.plan_limits() returns every plan's limits as the server publishes them.
Retrieve the full catalog of supported finding types:
catalog = client.metadata.finding_types()
print(f"Total types: {catalog.count}")
for ft in catalog.types:
print(f"[{ft.severity.value}] {ft.title} ({ft.category})")info = client.version()
print(info.current)
print(info.latest) # None if the server could not find out
print(info.engine)
print(info.status)All exceptions inherit from VulnRadarError:
from vulnradar import (
AuthenticationError,
NetworkError,
NotFoundError,
RateLimitError,
VulnRadar,
VulnRadarError,
)
client = VulnRadar()
try:
result = client.history.get(123)
except AuthenticationError:
print("Invalid or revoked API key.")
except NotFoundError:
print("No such scan.")
except RateLimitError as e:
print(f"Rate limited ({e.kind}). Retry after: {e.retry_after} seconds.")
except NetworkError as e:
print(f"No reply: {e.message}")
except VulnRadarError as e:
print(e.message, e.status_code, e.code, e.request_id)Every error has message, status_code, code (the server's error code), request_id,
retry_after and body (the server's reply). Those the server did not send are None, and
body is empty.
| Exception | HTTP status | Description |
|---|---|---|
AuthenticationError |
401 | Invalid or missing API key |
BadRequestError |
400 | Malformed request or invalid parameters |
ForbiddenError |
403 | Authenticated but not permitted |
NotFoundError |
404 | Requested resource does not exist |
UnprocessableEntityError |
422 | The target could not be processed |
RateLimitError |
429 | A rate limit or quota is used up |
ServerError |
5xx | Error on the server's side |
NetworkError |
none | No complete reply arrived |
RequestTimeoutError |
none | A NetworkError: no answer in time. A change may still have happened |
UnexpectedResponseError |
any | A redirect, or a reply that cannot be understood |
NoResultError |
none | An UnexpectedResponseError: a stored scan has no result |
ScanFailedError |
none | A scan failed or was cancelled |
ScanTimeoutError |
none | A scan did not finish in the time allowed |
InvalidURLError |
none | A target failed the check made before sending |
VulnRadarError |
other | The base class, also used for statuses such as 402, 409 and 413 |
A RateLimitError says which limit was reached in kind:
RateLimitKind |
Limit |
|---|---|
API_QUOTA |
The key's requests per 24 hours |
DAILY_SCANS |
The plan's scans per day |
CONCURRENT_SCANS |
Too many scans running at once |
TARGET |
Too many scans of one target domain |
BULK |
Too many bulk requests |
OTHER |
A short-term limit, or one the server did not name |
limit, used, remaining, resets_at and retry_after are filled in when the server
sends them and are None otherwise. A rate-limited request is not retried automatically.
How large each limit is depends on your plan; see the
API documentation.
from vulnradar import Severity
Severity.CRITICAL # "critical"
Severity.HIGH # "high"
Severity.MEDIUM # "medium"
Severity.LOW # "low"
Severity.INFO # "info"
Severity.UNKNOWN # a level this version of the SDK does not knowFilter findings by severity:
critical = [f for f in result.findings if f.severity == Severity.CRITICAL]Handle rate limits gracefully:
import time
from vulnradar import RateLimitError, VulnRadar
client = VulnRadar()
def read_scan(scan_id: int):
try:
return client.history.get(scan_id)
except RateLimitError as e:
# Wait out a short limit. A daily one can take hours, so report it.
if e.retry_after is None or e.retry_after > 60:
raise
time.sleep(e.retry_after)
return client.history.get(scan_id)Pre-discover pages before crawling:
discovery = client.discover_urls("https://example.com")
if discovery.total > 0:
# Keep within your plan's pages per crawl.
result = client.scan_crawl("https://example.com", urls=discovery.urls[:25])See CONTRIBUTING.md. Report security problems as described in SECURITY.md, not in a public issue. Changes are listed in the changelog.
MIT. See LICENSE for details.