Repository files navigation

VulnCheck Logo

The VulnCheck SDK For Python

Bring the VulnCheck API to your Python applications.

PyPI - VersionJupyter

Installation

# From PyPi
pip install vulncheck-sdk

Important

Windows users may need to enable Long Path Support

Resources

Quickstart

importurllib.requestimportvulncheck_sdkimportos# First let's setup a few variables to help usTOKEN=os.environ["VULNCHECK_API_TOKEN"] # Remember to store your token securely!# Now let's create a configuration objectconfiguration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKEN# Pass that config object to our API client and now...withvulncheck_sdk.ApiClient(configuration) asapi_client:
# We can use two classes to explore the VulnCheck API: EndpointsApi & IndicesApi### EndpointsApi has methods to query every endpoint except `/v3/index`# See the full list of endpoints here: https://docs.vulncheck.com/apiendpoints_client=vulncheck_sdk.EndpointsApi(api_client)
# PURLapi_response=endpoints_client.purl_get("pkg:hex/coherence@0.1.2")
data=V3controllersPurlResponseData=api_response.dataprint(data.cves)
# CPEcpe="cpe:/a:microsoft:internet_explorer:8.0.6001:beta"api_response=endpoints_client.cpe_get(cpe)
forcveinapi_response.data:
print(cve)
# Download a Backupindex="initial-access"api_response=endpoints_client.backup_index_get(index)
file_path=f"{index}.zip"withurllib.request.urlopen(api_response.data[0].url) asresponse:
withopen(file_path, "wb") asfile:
file.write(response.read())
### IndicesApi has methods for each indexindices_client=vulncheck_sdk.IndicesApi(api_client)
# Add query parameters to filter what you needapi_response=indices_client.index_vulncheck_nvd2_get(cve="CVE-2019-19781")
print(api_response.data)
Click to View Async Implementation
importasyncioimportosimportaiohttpimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefrun_vulnerability_checks():
# Use 'async with' to manage the ApiClient connection poolasyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
indices_client=vcaio.IndicesApi(api_client)
# --- PURL Search ---# 'await' the coroutine to get resultspurl_response=awaitendpoints_client.purl_get("pkg:hex/coherence@0.1.2")
ifpurl_response.data:
print(f"PURL CVEs: {purl_response.data.cves}")
# --- CPE Search ---cpe="cpe:/a:microsoft:internet_explorer:8.0.6001:beta"# 'await' the coroutine to get resultscpe_response=awaitendpoints_client.cpe_get(cpe)
print(f"CPE Results for {cpe}:")
forcveincpe_response.data:
print(f" - {cve}")
# --- Index Query (NVD2) ---# 'await' the coroutine to get resultsnvd_response=awaitindices_client.index_vulncheck_nvd2_get(
cve="CVE-2019-19781"
)
print(f"NVD2 Data: {nvd_response.data}")
# --- Download Backup (Async) ---index_name="initial-access"# 'await' the coroutine to get resultsbackup_response=awaitendpoints_client.backup_index_get(index_name)
ifbackup_response.data:
download_url=backup_response.data[0].urlfile_path=f"{index_name}.zip"print(f"Downloading backup from {download_url}...")
# Use aiohttp (already in your environment) for async downloadasyncwithaiohttp.ClientSession() assession:
asyncwithsession.get(download_url) asresp:
ifresp.status==200:
# 'await' the coroutine to get resultscontent=awaitresp.read()
withopen(file_path, "wb") asf:
f.write(content)
print(f"Saved backup to {file_path}")
if__name__=="__main__":
# Entry point to start the event loopasyncio.run(run_vulnerability_checks())

Examples

Advisory

List all advisory feeds and query advisories filtered by feed

importvulncheck_sdkfromvulncheck_sdk.models.search_v4_advisory_return_valueimportSearchV4AdvisoryReturnValuefromvulncheck_sdk.models.search_v4_list_feed_return_valueimportSearchV4ListFeedReturnValueimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
advisory_client=vulncheck_sdk.AdvisoryApi(api_client)
# List all available advisory feeds (/v4/advisory)feeds: SearchV4ListFeedReturnValue=advisory_client.v4_list_advisory_feeds()
print("Available feeds:")
forfeedinfeeds.data:
print(f"name: {feed.name}")
feed="wolfi"# Query advisories filtered by feed=wolfi (/v4/advisory?feed=wolfi)advisories: SearchV4AdvisoryReturnValue=advisory_client.v4_query_advisories(name=feed)
print(f"{feed.capitalize()} advisories (page 1): {len(advisories.data)} results")
foradvisoryinadvisories.data:
print(f"cve: {advisory.cve_metadata.cve_id}")
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaiofromvulncheck_sdk.aio.models.search_v4_advisory_return_valueimportSearchV4AdvisoryReturnValuefromvulncheck_sdk.aio.models.search_v4_list_feed_return_valueimportSearchV4ListFeedReturnValueTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefmain():
asyncwithvcaio.ApiClient(configuration) asapi_client:
advisory_client=vcaio.AdvisoryApi(api_client)
# List all available advisory feeds (/v4/advisory)feeds: SearchV4ListFeedReturnValue=awaitadvisory_client.v4_list_advisory_feeds()
print("Available feeds:")
forfeedinfeeds.data:
print(f"name: {feed.name}")
feed="wolfi"# Query advisories filtered by feed=wolfi (/v4/advisory?feed=wolfi)advisories: SearchV4AdvisoryReturnValue=awaitadvisory_client.v4_query_advisories(name=feed)
print(f"{feed.capitalize()} advisories (page 1): {len(advisories.data)} results")
foradvisoryinadvisories.data:
print(f"cve: {advisory.cve_metadata.cve_id}")
if__name__=="__main__":
asyncio.run(main())

Backup

Download the backup for an index

importurllib.requestimportvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
endpoints_client=vulncheck_sdk.EndpointsApi(api_client)
index="initial-access"api_response=endpoints_client.backup_index_get(index)
file_path=f"{index}.zip"withurllib.request.urlopen(api_response.data[0].url) asresponse:
withopen(file_path, "wb") asfile:
file.write(response.read())
Click to View Async Implementation
importasyncioimportosimporturllib.requestimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENdefdownload_sync(url, file_path):
""" Standard synchronous download using urllib.request. This runs in a separate thread to avoid blocking the event loop. """withurllib.request.urlopen(url) asresponse:
withopen(file_path, "wb") asfile:
file.write(response.read())
asyncdefmain():
# Use 'async with' to manage the connection life-cycleasyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
index="initial-access"# 'await' the coroutine to get the actual response dataapi_response=awaitendpoints_client.backup_index_get(index)
ifnotapi_response.data:
print("No backup URL found.")
returndownload_url=api_response.data[0].urlfile_path=f"{index}.zip"print(f"Downloading {index} via urllib (offloaded to thread)...")
# Use asyncio.to_thread to run the blocking call safely# 'await' the coroutine to get the actual response dataawaitasyncio.to_thread(download_sync, download_url, file_path)
print(f"Successfully saved to {file_path}")
if__name__=="__main__":
asyncio.run(main())

Backup v4

List available v4 backups and download a backup by feed name

importosimporttempfileimporturllib.requestfromurllib3.util.retryimportRetryimportvulncheck_sdkfromvulncheck_sdk.models.backup_backup_responseimportBackupBackupResponsefromvulncheck_sdk.models.backup_list_backups_responseimportBackupListBackupsResponseTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENconfiguration.retries=Retry(
total=5,
backoff_factor=2,
status_forcelist=[502, 503, 504],
allowed_methods=["GET"],
respect_retry_after_header=True,
)
withvulncheck_sdk.ApiClient(configuration) asapi_client:
backup_client=vulncheck_sdk.BackupApi(api_client)
# List available backups (/v4/backup)available: BackupListBackupsResponse=backup_client.v4_list_backups()
forpotential_backupinavailable.data:
print(f"Found backup: {potential_backup.name}")
# Get backup for the wolfi feed (/v4/backup/wolfi)feed="wolfi"response: BackupBackupResponse=backup_client.v4_get_backup_by_name(feed)
print(response.to_json())
print(f"Downloading {feed} backup")
withtempfile.TemporaryDirectory() astmpdir:
file_path=os.path.join(tmpdir, f"{feed}.zip")
withurllib.request.urlopen(response.url_mrap) asr:
withopen(file_path, "wb") asf:
f.write(r.read())
print(f"Successfully saved to {file_path}")
Click to View Async Implementation
importasyncioimportosimporttempfileimporturllib.requestimportvulncheck_sdk.aioasvcaiofromvulncheck_sdk.aio.models.backup_backup_responseimportBackupBackupResponsefromvulncheck_sdk.aio.models.backup_list_backups_responseimport (
BackupListBackupsResponse,
)
TOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENconfiguration.retries=5defdownload_sync(url, file_path):
""" Standard synchronous download using urllib.request. This runs in a separate thread to avoid blocking the event loop. """withurllib.request.urlopen(url) asresponse:
withopen(file_path, "wb") asfile:
file.write(response.read())
asyncdefmain():
asyncwithvcaio.ApiClient(configuration) asapi_client:
backup_client=vcaio.BackupApi(api_client)
# List available backups (/v4/backup)available: BackupListBackupsResponse=awaitbackup_client.v4_list_backups()
forpotential_backupinavailable.data:
print(f"Found backup: {potential_backup.name}")
# Get backup for the wolfi feed (/v4/backup/wolfi)feed="wolfi"response: BackupBackupResponse=awaitbackup_client.v4_get_backup_by_name(feed)
print(response.to_json())
print(f"Downloading {feed} backup via urllib (offloaded to thread)...")
withtempfile.TemporaryDirectory() astmpdir:
file_path=os.path.join(tmpdir, f"{feed}.zip")
awaitasyncio.to_thread(download_sync, response.url_mrap, file_path)
print(f"Successfully saved to {file_path}")
if__name__=="__main__":
asyncio.run(main())

CPE

Get all CPE's related to a CVE

importvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
endpoints_client=vulncheck_sdk.EndpointsApi(api_client)
cpe="cpe:/a:microsoft:internet_explorer:8.0.6001:beta"api_response=endpoints_client.cpe_get(cpe)
forcveinapi_response.data:
print(cve)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefget_cpe_vulnerabilities():
# 'async with' to manage the connection life-cycleasyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
cpe="cpe:/a:microsoft:internet_explorer:8.0.6001:beta"# 'await' the coroutine to get the actual response dataapi_response=awaitendpoints_client.cpe_get(cpe)
# Iterate through the resultsifapi_response.data:
forcveinapi_response.data:
print(cve)
else:
print(f"No vulnerabilities found for CPE: {cpe}")
if__name__=="__main__":
# Run the main async entry pointasyncio.run(get_cpe_vulnerabilities())

Index

Query VulnCheck-NVD2 for CVE-2019-19781

importvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
indices_client=vulncheck_sdk.IndicesApi(api_client)
api_response=indices_client.index_vulncheck_nvd2_get(cve="CVE-2019-19781")
print(api_response.data)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefget_cve_details():
# Use 'async with' for the ApiClientasyncwithvcaio.ApiClient(configuration) asapi_client:
indices_client=vcaio.IndicesApi(api_client)
# 'await' the API callapi_response=awaitindices_client.index_vulncheck_nvd2_get(
cve="CVE-2019-19781"
)
# Access and print the dataifapi_response.data:
print(api_response.data)
else:
print("No data found for the specified CVE.")
if__name__=="__main__":
# Start the async event loopasyncio.run(get_cve_details())

Indices

Get all available indices

importvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
endpoints_client=vulncheck_sdk.EndpointsApi(api_client)
api_response=endpoints_client.index_get()
forindexinapi_response.data:
print(index.name)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdeflist_indices():
# Use 'async with' to manage the connection life-cycleasyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
# 'await' the coroutine to get the actual responseapi_response=awaitendpoints_client.index_get()
# Iterate through the resultsifapi_response.data:
print(f"{'Index Name':<30} | {'Description'}")
print("-"*50)
forindexinapi_response.data:
print(f"{index.name:<30}")
else:
print("No indices found.")
if__name__=="__main__":
# 4. Entry point to run the asynchronous event loopasyncio.run(list_indices())

Pagination

Paginate over results for a query to VulnCheck-KEV using cursor

importvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
indices_client=vulncheck_sdk.IndicesApi(api_client)
api_response=indices_client.index_vulncheck_kev_get(
start_cursor="true",
# `limit` increases the size of each page, making it faster# to download large datasetslimit=300,
)
print(api_response.data)
whileapi_response.meta.next_cursorisnotNone:
api_response=indices_client.index_vulncheck_kev_get(
cursor=api_response.meta.next_cursor
)
print(api_response.data)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdeffetch_kev_data():
# Use 'async with' to properly manage the lifecycle of the async clientasyncwithvcaio.ApiClient(configuration) asapi_client:
indices_client=vcaio.IndicesApi(api_client)
# 'await' the coroutine to get the actual response dataapi_response=awaitindices_client.index_vulncheck_kev_get(
start_cursor="true", limit=300
)
print(f"Fetched {len(api_response.data)} records...")
# Process initial data# (e.g., save to a list or database)# Pagination loopwhileapi_response.metaandapi_response.meta.next_cursor:
print(f"Fetching next page: {api_response.meta.next_cursor}")
# 'await' the coroutine to get the actual response dataapi_response=awaitindices_client.index_vulncheck_kev_get(
cursor=api_response.meta.next_cursor, limit=300
)
ifapi_response.data:
print(f"Fetched {len(api_response.data)} records...")
else:
breakif__name__=="__main__":
# Entry point to run the async event loopasyncio.run(fetch_kev_data())

PURL

Get the CVE's for a given PURL

importvulncheck_sdkfromvulncheck_sdk.models.v3controllers_purl_response_dataimport (
V3controllersPurlResponseData,
)
importosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
endpoints_client=vulncheck_sdk.EndpointsApi(api_client)
purl="pkg:hex/coherence@0.1.2"api_response=endpoints_client.purl_get(purl)
data: V3controllersPurlResponseData=api_response.dataprint(data.cves)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaiofromvulncheck_sdk.aio.models.v3controllers_purl_response_dataimport (
V3controllersPurlResponseData,
)
# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefget_data(client, purl: str):
# Await the client call directlyapi_response=awaitclient.purl_get(purl)
# Access the data attribute from the response objectreturnapi_response.dataasyncdefmain():
asyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
purl="pkg:hex/coherence@0.1.2"# 'await' the async function calldata: V3controllersPurlResponseData=awaitget_data(endpoints_client, purl)
ifdataanddata.cves:
print(f"Found {len(data.cves)} CVEs:")
forcveindata.cves:
print(f"- {cve}")
else:
print("No CVEs found or data is empty.")
if__name__=="__main__":
asyncio.run(main())

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please create an issue.

Sponsorship

Development of this project is sponsored by VulnCheck learn more about us!

License

Apache License 2.0. Please see License File for more information.

About

A generated Python SDK from VulnCheck's OpenAPI specification

Topics

Resources

Contributing

Stars

14 stars

Watchers

2 watching

Forks

Releases

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Repository files navigation

VulnCheck Logo

The VulnCheck SDK For Python

Bring the VulnCheck API to your Python applications.

PyPI - VersionJupyter

Installation

# From PyPi
pip install vulncheck-sdk

Important

Windows users may need to enable Long Path Support

Resources

Quickstart

importurllib.requestimportvulncheck_sdkimportos# First let's setup a few variables to help usTOKEN=os.environ["VULNCHECK_API_TOKEN"] # Remember to store your token securely!# Now let's create a configuration objectconfiguration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKEN# Pass that config object to our API client and now...withvulncheck_sdk.ApiClient(configuration) asapi_client:
# We can use two classes to explore the VulnCheck API: EndpointsApi & IndicesApi### EndpointsApi has methods to query every endpoint except `/v3/index`# See the full list of endpoints here: https://docs.vulncheck.com/apiendpoints_client=vulncheck_sdk.EndpointsApi(api_client)
# PURLapi_response=endpoints_client.purl_get("pkg:hex/coherence@0.1.2")
data=V3controllersPurlResponseData=api_response.dataprint(data.cves)
# CPEcpe="cpe:/a:microsoft:internet_explorer:8.0.6001:beta"api_response=endpoints_client.cpe_get(cpe)
forcveinapi_response.data:
print(cve)
# Download a Backupindex="initial-access"api_response=endpoints_client.backup_index_get(index)
file_path=f"{index}.zip"withurllib.request.urlopen(api_response.data[0].url) asresponse:
withopen(file_path, "wb") asfile:
file.write(response.read())
### IndicesApi has methods for each indexindices_client=vulncheck_sdk.IndicesApi(api_client)
# Add query parameters to filter what you needapi_response=indices_client.index_vulncheck_nvd2_get(cve="CVE-2019-19781")
print(api_response.data)
Click to View Async Implementation
importasyncioimportosimportaiohttpimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefrun_vulnerability_checks():
# Use 'async with' to manage the ApiClient connection poolasyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
indices_client=vcaio.IndicesApi(api_client)
# --- PURL Search ---# 'await' the coroutine to get resultspurl_response=awaitendpoints_client.purl_get("pkg:hex/coherence@0.1.2")
ifpurl_response.data:
print(f"PURL CVEs: {purl_response.data.cves}")
# --- CPE Search ---cpe="cpe:/a:microsoft:internet_explorer:8.0.6001:beta"# 'await' the coroutine to get resultscpe_response=awaitendpoints_client.cpe_get(cpe)
print(f"CPE Results for {cpe}:")
forcveincpe_response.data:
print(f" - {cve}")
# --- Index Query (NVD2) ---# 'await' the coroutine to get resultsnvd_response=awaitindices_client.index_vulncheck_nvd2_get(
cve="CVE-2019-19781"
)
print(f"NVD2 Data: {nvd_response.data}")
# --- Download Backup (Async) ---index_name="initial-access"# 'await' the coroutine to get resultsbackup_response=awaitendpoints_client.backup_index_get(index_name)
ifbackup_response.data:
download_url=backup_response.data[0].urlfile_path=f"{index_name}.zip"print(f"Downloading backup from {download_url}...")
# Use aiohttp (already in your environment) for async downloadasyncwithaiohttp.ClientSession() assession:
asyncwithsession.get(download_url) asresp:
ifresp.status==200:
# 'await' the coroutine to get resultscontent=awaitresp.read()
withopen(file_path, "wb") asf:
f.write(content)
print(f"Saved backup to {file_path}")
if__name__=="__main__":
# Entry point to start the event loopasyncio.run(run_vulnerability_checks())

Examples

Advisory

List all advisory feeds and query advisories filtered by feed

importvulncheck_sdkfromvulncheck_sdk.models.search_v4_advisory_return_valueimportSearchV4AdvisoryReturnValuefromvulncheck_sdk.models.search_v4_list_feed_return_valueimportSearchV4ListFeedReturnValueimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
advisory_client=vulncheck_sdk.AdvisoryApi(api_client)
# List all available advisory feeds (/v4/advisory)feeds: SearchV4ListFeedReturnValue=advisory_client.v4_list_advisory_feeds()
print("Available feeds:")
forfeedinfeeds.data:
print(f"name: {feed.name}")
feed="wolfi"# Query advisories filtered by feed=wolfi (/v4/advisory?feed=wolfi)advisories: SearchV4AdvisoryReturnValue=advisory_client.v4_query_advisories(name=feed)
print(f"{feed.capitalize()} advisories (page 1): {len(advisories.data)} results")
foradvisoryinadvisories.data:
print(f"cve: {advisory.cve_metadata.cve_id}")
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaiofromvulncheck_sdk.aio.models.search_v4_advisory_return_valueimportSearchV4AdvisoryReturnValuefromvulncheck_sdk.aio.models.search_v4_list_feed_return_valueimportSearchV4ListFeedReturnValueTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefmain():
asyncwithvcaio.ApiClient(configuration) asapi_client:
advisory_client=vcaio.AdvisoryApi(api_client)
# List all available advisory feeds (/v4/advisory)feeds: SearchV4ListFeedReturnValue=awaitadvisory_client.v4_list_advisory_feeds()
print("Available feeds:")
forfeedinfeeds.data:
print(f"name: {feed.name}")
feed="wolfi"# Query advisories filtered by feed=wolfi (/v4/advisory?feed=wolfi)advisories: SearchV4AdvisoryReturnValue=awaitadvisory_client.v4_query_advisories(name=feed)
print(f"{feed.capitalize()} advisories (page 1): {len(advisories.data)} results")
foradvisoryinadvisories.data:
print(f"cve: {advisory.cve_metadata.cve_id}")
if__name__=="__main__":
asyncio.run(main())

Backup

Download the backup for an index

importurllib.requestimportvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
endpoints_client=vulncheck_sdk.EndpointsApi(api_client)
index="initial-access"api_response=endpoints_client.backup_index_get(index)
file_path=f"{index}.zip"withurllib.request.urlopen(api_response.data[0].url) asresponse:
withopen(file_path, "wb") asfile:
file.write(response.read())
Click to View Async Implementation
importasyncioimportosimporturllib.requestimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENdefdownload_sync(url, file_path):
""" Standard synchronous download using urllib.request. This runs in a separate thread to avoid blocking the event loop. """withurllib.request.urlopen(url) asresponse:
withopen(file_path, "wb") asfile:
file.write(response.read())
asyncdefmain():
# Use 'async with' to manage the connection life-cycleasyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
index="initial-access"# 'await' the coroutine to get the actual response dataapi_response=awaitendpoints_client.backup_index_get(index)
ifnotapi_response.data:
print("No backup URL found.")
returndownload_url=api_response.data[0].urlfile_path=f"{index}.zip"print(f"Downloading {index} via urllib (offloaded to thread)...")
# Use asyncio.to_thread to run the blocking call safely# 'await' the coroutine to get the actual response dataawaitasyncio.to_thread(download_sync, download_url, file_path)
print(f"Successfully saved to {file_path}")
if__name__=="__main__":
asyncio.run(main())

Backup v4

List available v4 backups and download a backup by feed name

importosimporttempfileimporturllib.requestfromurllib3.util.retryimportRetryimportvulncheck_sdkfromvulncheck_sdk.models.backup_backup_responseimportBackupBackupResponsefromvulncheck_sdk.models.backup_list_backups_responseimportBackupListBackupsResponseTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENconfiguration.retries=Retry(
total=5,
backoff_factor=2,
status_forcelist=[502, 503, 504],
allowed_methods=["GET"],
respect_retry_after_header=True,
)
withvulncheck_sdk.ApiClient(configuration) asapi_client:
backup_client=vulncheck_sdk.BackupApi(api_client)
# List available backups (/v4/backup)available: BackupListBackupsResponse=backup_client.v4_list_backups()
forpotential_backupinavailable.data:
print(f"Found backup: {potential_backup.name}")
# Get backup for the wolfi feed (/v4/backup/wolfi)feed="wolfi"response: BackupBackupResponse=backup_client.v4_get_backup_by_name(feed)
print(response.to_json())
print(f"Downloading {feed} backup")
withtempfile.TemporaryDirectory() astmpdir:
file_path=os.path.join(tmpdir, f"{feed}.zip")
withurllib.request.urlopen(response.url_mrap) asr:
withopen(file_path, "wb") asf:
f.write(r.read())
print(f"Successfully saved to {file_path}")
Click to View Async Implementation
importasyncioimportosimporttempfileimporturllib.requestimportvulncheck_sdk.aioasvcaiofromvulncheck_sdk.aio.models.backup_backup_responseimportBackupBackupResponsefromvulncheck_sdk.aio.models.backup_list_backups_responseimport (
BackupListBackupsResponse,
)
TOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENconfiguration.retries=5defdownload_sync(url, file_path):
""" Standard synchronous download using urllib.request. This runs in a separate thread to avoid blocking the event loop. """withurllib.request.urlopen(url) asresponse:
withopen(file_path, "wb") asfile:
file.write(response.read())
asyncdefmain():
asyncwithvcaio.ApiClient(configuration) asapi_client:
backup_client=vcaio.BackupApi(api_client)
# List available backups (/v4/backup)available: BackupListBackupsResponse=awaitbackup_client.v4_list_backups()
forpotential_backupinavailable.data:
print(f"Found backup: {potential_backup.name}")
# Get backup for the wolfi feed (/v4/backup/wolfi)feed="wolfi"response: BackupBackupResponse=awaitbackup_client.v4_get_backup_by_name(feed)
print(response.to_json())
print(f"Downloading {feed} backup via urllib (offloaded to thread)...")
withtempfile.TemporaryDirectory() astmpdir:
file_path=os.path.join(tmpdir, f"{feed}.zip")
awaitasyncio.to_thread(download_sync, response.url_mrap, file_path)
print(f"Successfully saved to {file_path}")
if__name__=="__main__":
asyncio.run(main())

CPE

Get all CPE's related to a CVE

importvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
endpoints_client=vulncheck_sdk.EndpointsApi(api_client)
cpe="cpe:/a:microsoft:internet_explorer:8.0.6001:beta"api_response=endpoints_client.cpe_get(cpe)
forcveinapi_response.data:
print(cve)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefget_cpe_vulnerabilities():
# 'async with' to manage the connection life-cycleasyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
cpe="cpe:/a:microsoft:internet_explorer:8.0.6001:beta"# 'await' the coroutine to get the actual response dataapi_response=awaitendpoints_client.cpe_get(cpe)
# Iterate through the resultsifapi_response.data:
forcveinapi_response.data:
print(cve)
else:
print(f"No vulnerabilities found for CPE: {cpe}")
if__name__=="__main__":
# Run the main async entry pointasyncio.run(get_cpe_vulnerabilities())

Index

Query VulnCheck-NVD2 for CVE-2019-19781

importvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
indices_client=vulncheck_sdk.IndicesApi(api_client)
api_response=indices_client.index_vulncheck_nvd2_get(cve="CVE-2019-19781")
print(api_response.data)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefget_cve_details():
# Use 'async with' for the ApiClientasyncwithvcaio.ApiClient(configuration) asapi_client:
indices_client=vcaio.IndicesApi(api_client)
# 'await' the API callapi_response=awaitindices_client.index_vulncheck_nvd2_get(
cve="CVE-2019-19781"
)
# Access and print the dataifapi_response.data:
print(api_response.data)
else:
print("No data found for the specified CVE.")
if__name__=="__main__":
# Start the async event loopasyncio.run(get_cve_details())

Indices

Get all available indices

importvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
endpoints_client=vulncheck_sdk.EndpointsApi(api_client)
api_response=endpoints_client.index_get()
forindexinapi_response.data:
print(index.name)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdeflist_indices():
# Use 'async with' to manage the connection life-cycleasyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
# 'await' the coroutine to get the actual responseapi_response=awaitendpoints_client.index_get()
# Iterate through the resultsifapi_response.data:
print(f"{'Index Name':<30} | {'Description'}")
print("-"*50)
forindexinapi_response.data:
print(f"{index.name:<30}")
else:
print("No indices found.")
if__name__=="__main__":
# 4. Entry point to run the asynchronous event loopasyncio.run(list_indices())

Pagination

Paginate over results for a query to VulnCheck-KEV using cursor

importvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
indices_client=vulncheck_sdk.IndicesApi(api_client)
api_response=indices_client.index_vulncheck_kev_get(
start_cursor="true",
# `limit` increases the size of each page, making it faster# to download large datasetslimit=300,
)
print(api_response.data)
whileapi_response.meta.next_cursorisnotNone:
api_response=indices_client.index_vulncheck_kev_get(
cursor=api_response.meta.next_cursor
)
print(api_response.data)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdeffetch_kev_data():
# Use 'async with' to properly manage the lifecycle of the async clientasyncwithvcaio.ApiClient(configuration) asapi_client:
indices_client=vcaio.IndicesApi(api_client)
# 'await' the coroutine to get the actual response dataapi_response=awaitindices_client.index_vulncheck_kev_get(
start_cursor="true", limit=300
)
print(f"Fetched {len(api_response.data)} records...")
# Process initial data# (e.g., save to a list or database)# Pagination loopwhileapi_response.metaandapi_response.meta.next_cursor:
print(f"Fetching next page: {api_response.meta.next_cursor}")
# 'await' the coroutine to get the actual response dataapi_response=awaitindices_client.index_vulncheck_kev_get(
cursor=api_response.meta.next_cursor, limit=300
)
ifapi_response.data:
print(f"Fetched {len(api_response.data)} records...")
else:
breakif__name__=="__main__":
# Entry point to run the async event loopasyncio.run(fetch_kev_data())

PURL

Get the CVE's for a given PURL

importvulncheck_sdkfromvulncheck_sdk.models.v3controllers_purl_response_dataimport (
V3controllersPurlResponseData,
)
importosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
endpoints_client=vulncheck_sdk.EndpointsApi(api_client)
purl="pkg:hex/coherence@0.1.2"api_response=endpoints_client.purl_get(purl)
data: V3controllersPurlResponseData=api_response.dataprint(data.cves)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaiofromvulncheck_sdk.aio.models.v3controllers_purl_response_dataimport (
V3controllersPurlResponseData,
)
# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefget_data(client, purl: str):
# Await the client call directlyapi_response=awaitclient.purl_get(purl)
# Access the data attribute from the response objectreturnapi_response.dataasyncdefmain():
asyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
purl="pkg:hex/coherence@0.1.2"# 'await' the async function calldata: V3controllersPurlResponseData=awaitget_data(endpoints_client, purl)
ifdataanddata.cves:
print(f"Found {len(data.cves)} CVEs:")
forcveindata.cves:
print(f"- {cve}")
else:
print("No CVEs found or data is empty.")
if__name__=="__main__":
asyncio.run(main())

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please create an issue.

Sponsorship

Development of this project is sponsored by VulnCheck learn more about us!

License

Apache License 2.0. Please see License File for more information.

About

A generated Python SDK from VulnCheck's OpenAPI specification

Topics

Resources

Contributing

Stars

14 stars

Watchers

2 watching

Forks

Releases

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

VulnCheck Logo

The VulnCheck SDK For Python

Bring the VulnCheck API to your Python applications.

PyPI - VersionJupyter

Installation

# From PyPi
pip install vulncheck-sdk

Important

Windows users may need to enable Long Path Support

Resources

Quickstart

importurllib.requestimportvulncheck_sdkimportos# First let's setup a few variables to help usTOKEN=os.environ["VULNCHECK_API_TOKEN"] # Remember to store your token securely!# Now let's create a configuration objectconfiguration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKEN# Pass that config object to our API client and now...withvulncheck_sdk.ApiClient(configuration) asapi_client:
# We can use two classes to explore the VulnCheck API: EndpointsApi & IndicesApi### EndpointsApi has methods to query every endpoint except `/v3/index`# See the full list of endpoints here: https://docs.vulncheck.com/apiendpoints_client=vulncheck_sdk.EndpointsApi(api_client)
# PURLapi_response=endpoints_client.purl_get("pkg:hex/coherence@0.1.2")
data=V3controllersPurlResponseData=api_response.dataprint(data.cves)
# CPEcpe="cpe:/a:microsoft:internet_explorer:8.0.6001:beta"api_response=endpoints_client.cpe_get(cpe)
forcveinapi_response.data:
print(cve)
# Download a Backupindex="initial-access"api_response=endpoints_client.backup_index_get(index)
file_path=f"{index}.zip"withurllib.request.urlopen(api_response.data[0].url) asresponse:
withopen(file_path, "wb") asfile:
file.write(response.read())
### IndicesApi has methods for each indexindices_client=vulncheck_sdk.IndicesApi(api_client)
# Add query parameters to filter what you needapi_response=indices_client.index_vulncheck_nvd2_get(cve="CVE-2019-19781")
print(api_response.data)
Click to View Async Implementation
importasyncioimportosimportaiohttpimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefrun_vulnerability_checks():
# Use 'async with' to manage the ApiClient connection poolasyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
indices_client=vcaio.IndicesApi(api_client)
# --- PURL Search ---# 'await' the coroutine to get resultspurl_response=awaitendpoints_client.purl_get("pkg:hex/coherence@0.1.2")
ifpurl_response.data:
print(f"PURL CVEs: {purl_response.data.cves}")
# --- CPE Search ---cpe="cpe:/a:microsoft:internet_explorer:8.0.6001:beta"# 'await' the coroutine to get resultscpe_response=awaitendpoints_client.cpe_get(cpe)
print(f"CPE Results for {cpe}:")
forcveincpe_response.data:
print(f" - {cve}")
# --- Index Query (NVD2) ---# 'await' the coroutine to get resultsnvd_response=awaitindices_client.index_vulncheck_nvd2_get(
cve="CVE-2019-19781"
)
print(f"NVD2 Data: {nvd_response.data}")
# --- Download Backup (Async) ---index_name="initial-access"# 'await' the coroutine to get resultsbackup_response=awaitendpoints_client.backup_index_get(index_name)
ifbackup_response.data:
download_url=backup_response.data[0].urlfile_path=f"{index_name}.zip"print(f"Downloading backup from {download_url}...")
# Use aiohttp (already in your environment) for async downloadasyncwithaiohttp.ClientSession() assession:
asyncwithsession.get(download_url) asresp:
ifresp.status==200:
# 'await' the coroutine to get resultscontent=awaitresp.read()
withopen(file_path, "wb") asf:
f.write(content)
print(f"Saved backup to {file_path}")
if__name__=="__main__":
# Entry point to start the event loopasyncio.run(run_vulnerability_checks())

Examples

Advisory

List all advisory feeds and query advisories filtered by feed

importvulncheck_sdkfromvulncheck_sdk.models.search_v4_advisory_return_valueimportSearchV4AdvisoryReturnValuefromvulncheck_sdk.models.search_v4_list_feed_return_valueimportSearchV4ListFeedReturnValueimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
advisory_client=vulncheck_sdk.AdvisoryApi(api_client)
# List all available advisory feeds (/v4/advisory)feeds: SearchV4ListFeedReturnValue=advisory_client.v4_list_advisory_feeds()
print("Available feeds:")
forfeedinfeeds.data:
print(f"name: {feed.name}")
feed="wolfi"# Query advisories filtered by feed=wolfi (/v4/advisory?feed=wolfi)advisories: SearchV4AdvisoryReturnValue=advisory_client.v4_query_advisories(name=feed)
print(f"{feed.capitalize()} advisories (page 1): {len(advisories.data)} results")
foradvisoryinadvisories.data:
print(f"cve: {advisory.cve_metadata.cve_id}")
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaiofromvulncheck_sdk.aio.models.search_v4_advisory_return_valueimportSearchV4AdvisoryReturnValuefromvulncheck_sdk.aio.models.search_v4_list_feed_return_valueimportSearchV4ListFeedReturnValueTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefmain():
asyncwithvcaio.ApiClient(configuration) asapi_client:
advisory_client=vcaio.AdvisoryApi(api_client)
# List all available advisory feeds (/v4/advisory)feeds: SearchV4ListFeedReturnValue=awaitadvisory_client.v4_list_advisory_feeds()
print("Available feeds:")
forfeedinfeeds.data:
print(f"name: {feed.name}")
feed="wolfi"# Query advisories filtered by feed=wolfi (/v4/advisory?feed=wolfi)advisories: SearchV4AdvisoryReturnValue=awaitadvisory_client.v4_query_advisories(name=feed)
print(f"{feed.capitalize()} advisories (page 1): {len(advisories.data)} results")
foradvisoryinadvisories.data:
print(f"cve: {advisory.cve_metadata.cve_id}")
if__name__=="__main__":
asyncio.run(main())

Backup

Download the backup for an index

importurllib.requestimportvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
endpoints_client=vulncheck_sdk.EndpointsApi(api_client)
index="initial-access"api_response=endpoints_client.backup_index_get(index)
file_path=f"{index}.zip"withurllib.request.urlopen(api_response.data[0].url) asresponse:
withopen(file_path, "wb") asfile:
file.write(response.read())
Click to View Async Implementation
importasyncioimportosimporturllib.requestimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENdefdownload_sync(url, file_path):
""" Standard synchronous download using urllib.request. This runs in a separate thread to avoid blocking the event loop. """withurllib.request.urlopen(url) asresponse:
withopen(file_path, "wb") asfile:
file.write(response.read())
asyncdefmain():
# Use 'async with' to manage the connection life-cycleasyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
index="initial-access"# 'await' the coroutine to get the actual response dataapi_response=awaitendpoints_client.backup_index_get(index)
ifnotapi_response.data:
print("No backup URL found.")
returndownload_url=api_response.data[0].urlfile_path=f"{index}.zip"print(f"Downloading {index} via urllib (offloaded to thread)...")
# Use asyncio.to_thread to run the blocking call safely# 'await' the coroutine to get the actual response dataawaitasyncio.to_thread(download_sync, download_url, file_path)
print(f"Successfully saved to {file_path}")
if__name__=="__main__":
asyncio.run(main())

Backup v4

List available v4 backups and download a backup by feed name

importosimporttempfileimporturllib.requestfromurllib3.util.retryimportRetryimportvulncheck_sdkfromvulncheck_sdk.models.backup_backup_responseimportBackupBackupResponsefromvulncheck_sdk.models.backup_list_backups_responseimportBackupListBackupsResponseTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENconfiguration.retries=Retry(
total=5,
backoff_factor=2,
status_forcelist=[502, 503, 504],
allowed_methods=["GET"],
respect_retry_after_header=True,
)
withvulncheck_sdk.ApiClient(configuration) asapi_client:
backup_client=vulncheck_sdk.BackupApi(api_client)
# List available backups (/v4/backup)available: BackupListBackupsResponse=backup_client.v4_list_backups()
forpotential_backupinavailable.data:
print(f"Found backup: {potential_backup.name}")
# Get backup for the wolfi feed (/v4/backup/wolfi)feed="wolfi"response: BackupBackupResponse=backup_client.v4_get_backup_by_name(feed)
print(response.to_json())
print(f"Downloading {feed} backup")
withtempfile.TemporaryDirectory() astmpdir:
file_path=os.path.join(tmpdir, f"{feed}.zip")
withurllib.request.urlopen(response.url_mrap) asr:
withopen(file_path, "wb") asf:
f.write(r.read())
print(f"Successfully saved to {file_path}")
Click to View Async Implementation
importasyncioimportosimporttempfileimporturllib.requestimportvulncheck_sdk.aioasvcaiofromvulncheck_sdk.aio.models.backup_backup_responseimportBackupBackupResponsefromvulncheck_sdk.aio.models.backup_list_backups_responseimport (
BackupListBackupsResponse,
)
TOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENconfiguration.retries=5defdownload_sync(url, file_path):
""" Standard synchronous download using urllib.request. This runs in a separate thread to avoid blocking the event loop. """withurllib.request.urlopen(url) asresponse:
withopen(file_path, "wb") asfile:
file.write(response.read())
asyncdefmain():
asyncwithvcaio.ApiClient(configuration) asapi_client:
backup_client=vcaio.BackupApi(api_client)
# List available backups (/v4/backup)available: BackupListBackupsResponse=awaitbackup_client.v4_list_backups()
forpotential_backupinavailable.data:
print(f"Found backup: {potential_backup.name}")
# Get backup for the wolfi feed (/v4/backup/wolfi)feed="wolfi"response: BackupBackupResponse=awaitbackup_client.v4_get_backup_by_name(feed)
print(response.to_json())
print(f"Downloading {feed} backup via urllib (offloaded to thread)...")
withtempfile.TemporaryDirectory() astmpdir:
file_path=os.path.join(tmpdir, f"{feed}.zip")
awaitasyncio.to_thread(download_sync, response.url_mrap, file_path)
print(f"Successfully saved to {file_path}")
if__name__=="__main__":
asyncio.run(main())

CPE

Get all CPE's related to a CVE

importvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
endpoints_client=vulncheck_sdk.EndpointsApi(api_client)
cpe="cpe:/a:microsoft:internet_explorer:8.0.6001:beta"api_response=endpoints_client.cpe_get(cpe)
forcveinapi_response.data:
print(cve)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefget_cpe_vulnerabilities():
# 'async with' to manage the connection life-cycleasyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
cpe="cpe:/a:microsoft:internet_explorer:8.0.6001:beta"# 'await' the coroutine to get the actual response dataapi_response=awaitendpoints_client.cpe_get(cpe)
# Iterate through the resultsifapi_response.data:
forcveinapi_response.data:
print(cve)
else:
print(f"No vulnerabilities found for CPE: {cpe}")
if__name__=="__main__":
# Run the main async entry pointasyncio.run(get_cpe_vulnerabilities())

Index

Query VulnCheck-NVD2 for CVE-2019-19781

importvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
indices_client=vulncheck_sdk.IndicesApi(api_client)
api_response=indices_client.index_vulncheck_nvd2_get(cve="CVE-2019-19781")
print(api_response.data)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefget_cve_details():
# Use 'async with' for the ApiClientasyncwithvcaio.ApiClient(configuration) asapi_client:
indices_client=vcaio.IndicesApi(api_client)
# 'await' the API callapi_response=awaitindices_client.index_vulncheck_nvd2_get(
cve="CVE-2019-19781"
)
# Access and print the dataifapi_response.data:
print(api_response.data)
else:
print("No data found for the specified CVE.")
if__name__=="__main__":
# Start the async event loopasyncio.run(get_cve_details())

Indices

Get all available indices

importvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
endpoints_client=vulncheck_sdk.EndpointsApi(api_client)
api_response=endpoints_client.index_get()
forindexinapi_response.data:
print(index.name)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdeflist_indices():
# Use 'async with' to manage the connection life-cycleasyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
# 'await' the coroutine to get the actual responseapi_response=awaitendpoints_client.index_get()
# Iterate through the resultsifapi_response.data:
print(f"{'Index Name':<30} | {'Description'}")
print("-"*50)
forindexinapi_response.data:
print(f"{index.name:<30}")
else:
print("No indices found.")
if__name__=="__main__":
# 4. Entry point to run the asynchronous event loopasyncio.run(list_indices())

Pagination

Paginate over results for a query to VulnCheck-KEV using cursor

importvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
indices_client=vulncheck_sdk.IndicesApi(api_client)
api_response=indices_client.index_vulncheck_kev_get(
start_cursor="true",
# `limit` increases the size of each page, making it faster# to download large datasetslimit=300,
)
print(api_response.data)
whileapi_response.meta.next_cursorisnotNone:
api_response=indices_client.index_vulncheck_kev_get(
cursor=api_response.meta.next_cursor
)
print(api_response.data)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdeffetch_kev_data():
# Use 'async with' to properly manage the lifecycle of the async clientasyncwithvcaio.ApiClient(configuration) asapi_client:
indices_client=vcaio.IndicesApi(api_client)
# 'await' the coroutine to get the actual response dataapi_response=awaitindices_client.index_vulncheck_kev_get(
start_cursor="true", limit=300
)
print(f"Fetched {len(api_response.data)} records...")
# Process initial data# (e.g., save to a list or database)# Pagination loopwhileapi_response.metaandapi_response.meta.next_cursor:
print(f"Fetching next page: {api_response.meta.next_cursor}")
# 'await' the coroutine to get the actual response dataapi_response=awaitindices_client.index_vulncheck_kev_get(
cursor=api_response.meta.next_cursor, limit=300
)
ifapi_response.data:
print(f"Fetched {len(api_response.data)} records...")
else:
breakif__name__=="__main__":
# Entry point to run the async event loopasyncio.run(fetch_kev_data())

PURL

Get the CVE's for a given PURL

importvulncheck_sdkfromvulncheck_sdk.models.v3controllers_purl_response_dataimport (
V3controllersPurlResponseData,
)
importosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
endpoints_client=vulncheck_sdk.EndpointsApi(api_client)
purl="pkg:hex/coherence@0.1.2"api_response=endpoints_client.purl_get(purl)
data: V3controllersPurlResponseData=api_response.dataprint(data.cves)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaiofromvulncheck_sdk.aio.models.v3controllers_purl_response_dataimport (
V3controllersPurlResponseData,
)
# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefget_data(client, purl: str):
# Await the client call directlyapi_response=awaitclient.purl_get(purl)
# Access the data attribute from the response objectreturnapi_response.dataasyncdefmain():
asyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
purl="pkg:hex/coherence@0.1.2"# 'await' the async function calldata: V3controllersPurlResponseData=awaitget_data(endpoints_client, purl)
ifdataanddata.cves:
print(f"Found {len(data.cves)} CVEs:")
forcveindata.cves:
print(f"- {cve}")
else:
print("No CVEs found or data is empty.")
if__name__=="__main__":
asyncio.run(main())

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please create an issue.

Sponsorship

Development of this project is sponsored by VulnCheck learn more about us!

License

Apache License 2.0. Please see License File for more information.

About

A generated Python SDK from VulnCheck's OpenAPI specification

Topics

Resources

Contributing

Stars

14 stars

Watchers

2 watching

Forks

Releases

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

VulnCheck Logo

The VulnCheck SDK For Python

Bring the VulnCheck API to your Python applications.

PyPI - VersionJupyter

Installation

# From PyPi
pip install vulncheck-sdk

Important

Windows users may need to enable Long Path Support

Resources

Quickstart

importurllib.requestimportvulncheck_sdkimportos# First let's setup a few variables to help usTOKEN=os.environ["VULNCHECK_API_TOKEN"] # Remember to store your token securely!# Now let's create a configuration objectconfiguration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKEN# Pass that config object to our API client and now...withvulncheck_sdk.ApiClient(configuration) asapi_client:
# We can use two classes to explore the VulnCheck API: EndpointsApi & IndicesApi### EndpointsApi has methods to query every endpoint except `/v3/index`# See the full list of endpoints here: https://docs.vulncheck.com/apiendpoints_client=vulncheck_sdk.EndpointsApi(api_client)
# PURLapi_response=endpoints_client.purl_get("pkg:hex/coherence@0.1.2")
data=V3controllersPurlResponseData=api_response.dataprint(data.cves)
# CPEcpe="cpe:/a:microsoft:internet_explorer:8.0.6001:beta"api_response=endpoints_client.cpe_get(cpe)
forcveinapi_response.data:
print(cve)
# Download a Backupindex="initial-access"api_response=endpoints_client.backup_index_get(index)
file_path=f"{index}.zip"withurllib.request.urlopen(api_response.data[0].url) asresponse:
withopen(file_path, "wb") asfile:
file.write(response.read())
### IndicesApi has methods for each indexindices_client=vulncheck_sdk.IndicesApi(api_client)
# Add query parameters to filter what you needapi_response=indices_client.index_vulncheck_nvd2_get(cve="CVE-2019-19781")
print(api_response.data)
Click to View Async Implementation
importasyncioimportosimportaiohttpimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefrun_vulnerability_checks():
# Use 'async with' to manage the ApiClient connection poolasyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
indices_client=vcaio.IndicesApi(api_client)
# --- PURL Search ---# 'await' the coroutine to get resultspurl_response=awaitendpoints_client.purl_get("pkg:hex/coherence@0.1.2")
ifpurl_response.data:
print(f"PURL CVEs: {purl_response.data.cves}")
# --- CPE Search ---cpe="cpe:/a:microsoft:internet_explorer:8.0.6001:beta"# 'await' the coroutine to get resultscpe_response=awaitendpoints_client.cpe_get(cpe)
print(f"CPE Results for {cpe}:")
forcveincpe_response.data:
print(f" - {cve}")
# --- Index Query (NVD2) ---# 'await' the coroutine to get resultsnvd_response=awaitindices_client.index_vulncheck_nvd2_get(
cve="CVE-2019-19781"
)
print(f"NVD2 Data: {nvd_response.data}")
# --- Download Backup (Async) ---index_name="initial-access"# 'await' the coroutine to get resultsbackup_response=awaitendpoints_client.backup_index_get(index_name)
ifbackup_response.data:
download_url=backup_response.data[0].urlfile_path=f"{index_name}.zip"print(f"Downloading backup from {download_url}...")
# Use aiohttp (already in your environment) for async downloadasyncwithaiohttp.ClientSession() assession:
asyncwithsession.get(download_url) asresp:
ifresp.status==200:
# 'await' the coroutine to get resultscontent=awaitresp.read()
withopen(file_path, "wb") asf:
f.write(content)
print(f"Saved backup to {file_path}")
if__name__=="__main__":
# Entry point to start the event loopasyncio.run(run_vulnerability_checks())

Examples

Advisory

List all advisory feeds and query advisories filtered by feed

importvulncheck_sdkfromvulncheck_sdk.models.search_v4_advisory_return_valueimportSearchV4AdvisoryReturnValuefromvulncheck_sdk.models.search_v4_list_feed_return_valueimportSearchV4ListFeedReturnValueimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
advisory_client=vulncheck_sdk.AdvisoryApi(api_client)
# List all available advisory feeds (/v4/advisory)feeds: SearchV4ListFeedReturnValue=advisory_client.v4_list_advisory_feeds()
print("Available feeds:")
forfeedinfeeds.data:
print(f"name: {feed.name}")
feed="wolfi"# Query advisories filtered by feed=wolfi (/v4/advisory?feed=wolfi)advisories: SearchV4AdvisoryReturnValue=advisory_client.v4_query_advisories(name=feed)
print(f"{feed.capitalize()} advisories (page 1): {len(advisories.data)} results")
foradvisoryinadvisories.data:
print(f"cve: {advisory.cve_metadata.cve_id}")
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaiofromvulncheck_sdk.aio.models.search_v4_advisory_return_valueimportSearchV4AdvisoryReturnValuefromvulncheck_sdk.aio.models.search_v4_list_feed_return_valueimportSearchV4ListFeedReturnValueTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefmain():
asyncwithvcaio.ApiClient(configuration) asapi_client:
advisory_client=vcaio.AdvisoryApi(api_client)
# List all available advisory feeds (/v4/advisory)feeds: SearchV4ListFeedReturnValue=awaitadvisory_client.v4_list_advisory_feeds()
print("Available feeds:")
forfeedinfeeds.data:
print(f"name: {feed.name}")
feed="wolfi"# Query advisories filtered by feed=wolfi (/v4/advisory?feed=wolfi)advisories: SearchV4AdvisoryReturnValue=awaitadvisory_client.v4_query_advisories(name=feed)
print(f"{feed.capitalize()} advisories (page 1): {len(advisories.data)} results")
foradvisoryinadvisories.data:
print(f"cve: {advisory.cve_metadata.cve_id}")
if__name__=="__main__":
asyncio.run(main())

Backup

Download the backup for an index

importurllib.requestimportvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
endpoints_client=vulncheck_sdk.EndpointsApi(api_client)
index="initial-access"api_response=endpoints_client.backup_index_get(index)
file_path=f"{index}.zip"withurllib.request.urlopen(api_response.data[0].url) asresponse:
withopen(file_path, "wb") asfile:
file.write(response.read())
Click to View Async Implementation
importasyncioimportosimporturllib.requestimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENdefdownload_sync(url, file_path):
""" Standard synchronous download using urllib.request. This runs in a separate thread to avoid blocking the event loop. """withurllib.request.urlopen(url) asresponse:
withopen(file_path, "wb") asfile:
file.write(response.read())
asyncdefmain():
# Use 'async with' to manage the connection life-cycleasyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
index="initial-access"# 'await' the coroutine to get the actual response dataapi_response=awaitendpoints_client.backup_index_get(index)
ifnotapi_response.data:
print("No backup URL found.")
returndownload_url=api_response.data[0].urlfile_path=f"{index}.zip"print(f"Downloading {index} via urllib (offloaded to thread)...")
# Use asyncio.to_thread to run the blocking call safely# 'await' the coroutine to get the actual response dataawaitasyncio.to_thread(download_sync, download_url, file_path)
print(f"Successfully saved to {file_path}")
if__name__=="__main__":
asyncio.run(main())

Backup v4

List available v4 backups and download a backup by feed name

importosimporttempfileimporturllib.requestfromurllib3.util.retryimportRetryimportvulncheck_sdkfromvulncheck_sdk.models.backup_backup_responseimportBackupBackupResponsefromvulncheck_sdk.models.backup_list_backups_responseimportBackupListBackupsResponseTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENconfiguration.retries=Retry(
total=5,
backoff_factor=2,
status_forcelist=[502, 503, 504],
allowed_methods=["GET"],
respect_retry_after_header=True,
)
withvulncheck_sdk.ApiClient(configuration) asapi_client:
backup_client=vulncheck_sdk.BackupApi(api_client)
# List available backups (/v4/backup)available: BackupListBackupsResponse=backup_client.v4_list_backups()
forpotential_backupinavailable.data:
print(f"Found backup: {potential_backup.name}")
# Get backup for the wolfi feed (/v4/backup/wolfi)feed="wolfi"response: BackupBackupResponse=backup_client.v4_get_backup_by_name(feed)
print(response.to_json())
print(f"Downloading {feed} backup")
withtempfile.TemporaryDirectory() astmpdir:
file_path=os.path.join(tmpdir, f"{feed}.zip")
withurllib.request.urlopen(response.url_mrap) asr:
withopen(file_path, "wb") asf:
f.write(r.read())
print(f"Successfully saved to {file_path}")
Click to View Async Implementation
importasyncioimportosimporttempfileimporturllib.requestimportvulncheck_sdk.aioasvcaiofromvulncheck_sdk.aio.models.backup_backup_responseimportBackupBackupResponsefromvulncheck_sdk.aio.models.backup_list_backups_responseimport (
BackupListBackupsResponse,
)
TOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENconfiguration.retries=5defdownload_sync(url, file_path):
""" Standard synchronous download using urllib.request. This runs in a separate thread to avoid blocking the event loop. """withurllib.request.urlopen(url) asresponse:
withopen(file_path, "wb") asfile:
file.write(response.read())
asyncdefmain():
asyncwithvcaio.ApiClient(configuration) asapi_client:
backup_client=vcaio.BackupApi(api_client)
# List available backups (/v4/backup)available: BackupListBackupsResponse=awaitbackup_client.v4_list_backups()
forpotential_backupinavailable.data:
print(f"Found backup: {potential_backup.name}")
# Get backup for the wolfi feed (/v4/backup/wolfi)feed="wolfi"response: BackupBackupResponse=awaitbackup_client.v4_get_backup_by_name(feed)
print(response.to_json())
print(f"Downloading {feed} backup via urllib (offloaded to thread)...")
withtempfile.TemporaryDirectory() astmpdir:
file_path=os.path.join(tmpdir, f"{feed}.zip")
awaitasyncio.to_thread(download_sync, response.url_mrap, file_path)
print(f"Successfully saved to {file_path}")
if__name__=="__main__":
asyncio.run(main())

CPE

Get all CPE's related to a CVE

importvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
endpoints_client=vulncheck_sdk.EndpointsApi(api_client)
cpe="cpe:/a:microsoft:internet_explorer:8.0.6001:beta"api_response=endpoints_client.cpe_get(cpe)
forcveinapi_response.data:
print(cve)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefget_cpe_vulnerabilities():
# 'async with' to manage the connection life-cycleasyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
cpe="cpe:/a:microsoft:internet_explorer:8.0.6001:beta"# 'await' the coroutine to get the actual response dataapi_response=awaitendpoints_client.cpe_get(cpe)
# Iterate through the resultsifapi_response.data:
forcveinapi_response.data:
print(cve)
else:
print(f"No vulnerabilities found for CPE: {cpe}")
if__name__=="__main__":
# Run the main async entry pointasyncio.run(get_cpe_vulnerabilities())

Index

Query VulnCheck-NVD2 for CVE-2019-19781

importvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
indices_client=vulncheck_sdk.IndicesApi(api_client)
api_response=indices_client.index_vulncheck_nvd2_get(cve="CVE-2019-19781")
print(api_response.data)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefget_cve_details():
# Use 'async with' for the ApiClientasyncwithvcaio.ApiClient(configuration) asapi_client:
indices_client=vcaio.IndicesApi(api_client)
# 'await' the API callapi_response=awaitindices_client.index_vulncheck_nvd2_get(
cve="CVE-2019-19781"
)
# Access and print the dataifapi_response.data:
print(api_response.data)
else:
print("No data found for the specified CVE.")
if__name__=="__main__":
# Start the async event loopasyncio.run(get_cve_details())

Indices

Get all available indices

importvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
endpoints_client=vulncheck_sdk.EndpointsApi(api_client)
api_response=endpoints_client.index_get()
forindexinapi_response.data:
print(index.name)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdeflist_indices():
# Use 'async with' to manage the connection life-cycleasyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
# 'await' the coroutine to get the actual responseapi_response=awaitendpoints_client.index_get()
# Iterate through the resultsifapi_response.data:
print(f"{'Index Name':<30} | {'Description'}")
print("-"*50)
forindexinapi_response.data:
print(f"{index.name:<30}")
else:
print("No indices found.")
if__name__=="__main__":
# 4. Entry point to run the asynchronous event loopasyncio.run(list_indices())

Pagination

Paginate over results for a query to VulnCheck-KEV using cursor

importvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
indices_client=vulncheck_sdk.IndicesApi(api_client)
api_response=indices_client.index_vulncheck_kev_get(
start_cursor="true",
# `limit` increases the size of each page, making it faster# to download large datasetslimit=300,
)
print(api_response.data)
whileapi_response.meta.next_cursorisnotNone:
api_response=indices_client.index_vulncheck_kev_get(
cursor=api_response.meta.next_cursor
)
print(api_response.data)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdeffetch_kev_data():
# Use 'async with' to properly manage the lifecycle of the async clientasyncwithvcaio.ApiClient(configuration) asapi_client:
indices_client=vcaio.IndicesApi(api_client)
# 'await' the coroutine to get the actual response dataapi_response=awaitindices_client.index_vulncheck_kev_get(
start_cursor="true", limit=300
)
print(f"Fetched {len(api_response.data)} records...")
# Process initial data# (e.g., save to a list or database)# Pagination loopwhileapi_response.metaandapi_response.meta.next_cursor:
print(f"Fetching next page: {api_response.meta.next_cursor}")
# 'await' the coroutine to get the actual response dataapi_response=awaitindices_client.index_vulncheck_kev_get(
cursor=api_response.meta.next_cursor, limit=300
)
ifapi_response.data:
print(f"Fetched {len(api_response.data)} records...")
else:
breakif__name__=="__main__":
# Entry point to run the async event loopasyncio.run(fetch_kev_data())

PURL

Get the CVE's for a given PURL

importvulncheck_sdkfromvulncheck_sdk.models.v3controllers_purl_response_dataimport (
V3controllersPurlResponseData,
)
importosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
endpoints_client=vulncheck_sdk.EndpointsApi(api_client)
purl="pkg:hex/coherence@0.1.2"api_response=endpoints_client.purl_get(purl)
data: V3controllersPurlResponseData=api_response.dataprint(data.cves)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaiofromvulncheck_sdk.aio.models.v3controllers_purl_response_dataimport (
V3controllersPurlResponseData,
)
# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefget_data(client, purl: str):
# Await the client call directlyapi_response=awaitclient.purl_get(purl)
# Access the data attribute from the response objectreturnapi_response.dataasyncdefmain():
asyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
purl="pkg:hex/coherence@0.1.2"# 'await' the async function calldata: V3controllersPurlResponseData=awaitget_data(endpoints_client, purl)
ifdataanddata.cves:
print(f"Found {len(data.cves)} CVEs:")
forcveindata.cves:
print(f"- {cve}")
else:
print("No CVEs found or data is empty.")
if__name__=="__main__":
asyncio.run(main())

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please create an issue.

Sponsorship

Development of this project is sponsored by VulnCheck learn more about us!

License

Apache License 2.0. Please see License File for more information.

About

A generated Python SDK from VulnCheck's OpenAPI specification

Topics

Resources

Contributing

Stars

14 stars

Watchers

2 watching

Forks

Releases

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Repository files navigation

VulnCheck Logo

The VulnCheck SDK For Python

Bring the VulnCheck API to your Python applications.

PyPI - VersionJupyter

Installation

# From PyPi
pip install vulncheck-sdk

Important

Windows users may need to enable Long Path Support

Resources

Quickstart

importurllib.requestimportvulncheck_sdkimportos# First let's setup a few variables to help usTOKEN=os.environ["VULNCHECK_API_TOKEN"] # Remember to store your token securely!# Now let's create a configuration objectconfiguration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKEN# Pass that config object to our API client and now...withvulncheck_sdk.ApiClient(configuration) asapi_client:
# We can use two classes to explore the VulnCheck API: EndpointsApi & IndicesApi### EndpointsApi has methods to query every endpoint except `/v3/index`# See the full list of endpoints here: https://docs.vulncheck.com/apiendpoints_client=vulncheck_sdk.EndpointsApi(api_client)
# PURLapi_response=endpoints_client.purl_get("pkg:hex/coherence@0.1.2")
data=V3controllersPurlResponseData=api_response.dataprint(data.cves)
# CPEcpe="cpe:/a:microsoft:internet_explorer:8.0.6001:beta"api_response=endpoints_client.cpe_get(cpe)
forcveinapi_response.data:
print(cve)
# Download a Backupindex="initial-access"api_response=endpoints_client.backup_index_get(index)
file_path=f"{index}.zip"withurllib.request.urlopen(api_response.data[0].url) asresponse:
withopen(file_path, "wb") asfile:
file.write(response.read())
### IndicesApi has methods for each indexindices_client=vulncheck_sdk.IndicesApi(api_client)
# Add query parameters to filter what you needapi_response=indices_client.index_vulncheck_nvd2_get(cve="CVE-2019-19781")
print(api_response.data)
Click to View Async Implementation
importasyncioimportosimportaiohttpimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefrun_vulnerability_checks():
# Use 'async with' to manage the ApiClient connection poolasyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
indices_client=vcaio.IndicesApi(api_client)
# --- PURL Search ---# 'await' the coroutine to get resultspurl_response=awaitendpoints_client.purl_get("pkg:hex/coherence@0.1.2")
ifpurl_response.data:
print(f"PURL CVEs: {purl_response.data.cves}")
# --- CPE Search ---cpe="cpe:/a:microsoft:internet_explorer:8.0.6001:beta"# 'await' the coroutine to get resultscpe_response=awaitendpoints_client.cpe_get(cpe)
print(f"CPE Results for {cpe}:")
forcveincpe_response.data:
print(f" - {cve}")
# --- Index Query (NVD2) ---# 'await' the coroutine to get resultsnvd_response=awaitindices_client.index_vulncheck_nvd2_get(
cve="CVE-2019-19781"
)
print(f"NVD2 Data: {nvd_response.data}")
# --- Download Backup (Async) ---index_name="initial-access"# 'await' the coroutine to get resultsbackup_response=awaitendpoints_client.backup_index_get(index_name)
ifbackup_response.data:
download_url=backup_response.data[0].urlfile_path=f"{index_name}.zip"print(f"Downloading backup from {download_url}...")
# Use aiohttp (already in your environment) for async downloadasyncwithaiohttp.ClientSession() assession:
asyncwithsession.get(download_url) asresp:
ifresp.status==200:
# 'await' the coroutine to get resultscontent=awaitresp.read()
withopen(file_path, "wb") asf:
f.write(content)
print(f"Saved backup to {file_path}")
if__name__=="__main__":
# Entry point to start the event loopasyncio.run(run_vulnerability_checks())

Examples

Advisory

List all advisory feeds and query advisories filtered by feed

importvulncheck_sdkfromvulncheck_sdk.models.search_v4_advisory_return_valueimportSearchV4AdvisoryReturnValuefromvulncheck_sdk.models.search_v4_list_feed_return_valueimportSearchV4ListFeedReturnValueimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
advisory_client=vulncheck_sdk.AdvisoryApi(api_client)
# List all available advisory feeds (/v4/advisory)feeds: SearchV4ListFeedReturnValue=advisory_client.v4_list_advisory_feeds()
print("Available feeds:")
forfeedinfeeds.data:
print(f"name: {feed.name}")
feed="wolfi"# Query advisories filtered by feed=wolfi (/v4/advisory?feed=wolfi)advisories: SearchV4AdvisoryReturnValue=advisory_client.v4_query_advisories(name=feed)
print(f"{feed.capitalize()} advisories (page 1): {len(advisories.data)} results")
foradvisoryinadvisories.data:
print(f"cve: {advisory.cve_metadata.cve_id}")
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaiofromvulncheck_sdk.aio.models.search_v4_advisory_return_valueimportSearchV4AdvisoryReturnValuefromvulncheck_sdk.aio.models.search_v4_list_feed_return_valueimportSearchV4ListFeedReturnValueTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefmain():
asyncwithvcaio.ApiClient(configuration) asapi_client:
advisory_client=vcaio.AdvisoryApi(api_client)
# List all available advisory feeds (/v4/advisory)feeds: SearchV4ListFeedReturnValue=awaitadvisory_client.v4_list_advisory_feeds()
print("Available feeds:")
forfeedinfeeds.data:
print(f"name: {feed.name}")
feed="wolfi"# Query advisories filtered by feed=wolfi (/v4/advisory?feed=wolfi)advisories: SearchV4AdvisoryReturnValue=awaitadvisory_client.v4_query_advisories(name=feed)
print(f"{feed.capitalize()} advisories (page 1): {len(advisories.data)} results")
foradvisoryinadvisories.data:
print(f"cve: {advisory.cve_metadata.cve_id}")
if__name__=="__main__":
asyncio.run(main())

Backup

Download the backup for an index

importurllib.requestimportvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
endpoints_client=vulncheck_sdk.EndpointsApi(api_client)
index="initial-access"api_response=endpoints_client.backup_index_get(index)
file_path=f"{index}.zip"withurllib.request.urlopen(api_response.data[0].url) asresponse:
withopen(file_path, "wb") asfile:
file.write(response.read())
Click to View Async Implementation
importasyncioimportosimporturllib.requestimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENdefdownload_sync(url, file_path):
""" Standard synchronous download using urllib.request. This runs in a separate thread to avoid blocking the event loop. """withurllib.request.urlopen(url) asresponse:
withopen(file_path, "wb") asfile:
file.write(response.read())
asyncdefmain():
# Use 'async with' to manage the connection life-cycleasyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
index="initial-access"# 'await' the coroutine to get the actual response dataapi_response=awaitendpoints_client.backup_index_get(index)
ifnotapi_response.data:
print("No backup URL found.")
returndownload_url=api_response.data[0].urlfile_path=f"{index}.zip"print(f"Downloading {index} via urllib (offloaded to thread)...")
# Use asyncio.to_thread to run the blocking call safely# 'await' the coroutine to get the actual response dataawaitasyncio.to_thread(download_sync, download_url, file_path)
print(f"Successfully saved to {file_path}")
if__name__=="__main__":
asyncio.run(main())

Backup v4

List available v4 backups and download a backup by feed name

importosimporttempfileimporturllib.requestfromurllib3.util.retryimportRetryimportvulncheck_sdkfromvulncheck_sdk.models.backup_backup_responseimportBackupBackupResponsefromvulncheck_sdk.models.backup_list_backups_responseimportBackupListBackupsResponseTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENconfiguration.retries=Retry(
total=5,
backoff_factor=2,
status_forcelist=[502, 503, 504],
allowed_methods=["GET"],
respect_retry_after_header=True,
)
withvulncheck_sdk.ApiClient(configuration) asapi_client:
backup_client=vulncheck_sdk.BackupApi(api_client)
# List available backups (/v4/backup)available: BackupListBackupsResponse=backup_client.v4_list_backups()
forpotential_backupinavailable.data:
print(f"Found backup: {potential_backup.name}")
# Get backup for the wolfi feed (/v4/backup/wolfi)feed="wolfi"response: BackupBackupResponse=backup_client.v4_get_backup_by_name(feed)
print(response.to_json())
print(f"Downloading {feed} backup")
withtempfile.TemporaryDirectory() astmpdir:
file_path=os.path.join(tmpdir, f"{feed}.zip")
withurllib.request.urlopen(response.url_mrap) asr:
withopen(file_path, "wb") asf:
f.write(r.read())
print(f"Successfully saved to {file_path}")
Click to View Async Implementation
importasyncioimportosimporttempfileimporturllib.requestimportvulncheck_sdk.aioasvcaiofromvulncheck_sdk.aio.models.backup_backup_responseimportBackupBackupResponsefromvulncheck_sdk.aio.models.backup_list_backups_responseimport (
BackupListBackupsResponse,
)
TOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENconfiguration.retries=5defdownload_sync(url, file_path):
""" Standard synchronous download using urllib.request. This runs in a separate thread to avoid blocking the event loop. """withurllib.request.urlopen(url) asresponse:
withopen(file_path, "wb") asfile:
file.write(response.read())
asyncdefmain():
asyncwithvcaio.ApiClient(configuration) asapi_client:
backup_client=vcaio.BackupApi(api_client)
# List available backups (/v4/backup)available: BackupListBackupsResponse=awaitbackup_client.v4_list_backups()
forpotential_backupinavailable.data:
print(f"Found backup: {potential_backup.name}")
# Get backup for the wolfi feed (/v4/backup/wolfi)feed="wolfi"response: BackupBackupResponse=awaitbackup_client.v4_get_backup_by_name(feed)
print(response.to_json())
print(f"Downloading {feed} backup via urllib (offloaded to thread)...")
withtempfile.TemporaryDirectory() astmpdir:
file_path=os.path.join(tmpdir, f"{feed}.zip")
awaitasyncio.to_thread(download_sync, response.url_mrap, file_path)
print(f"Successfully saved to {file_path}")
if__name__=="__main__":
asyncio.run(main())

CPE

Get all CPE's related to a CVE

importvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
endpoints_client=vulncheck_sdk.EndpointsApi(api_client)
cpe="cpe:/a:microsoft:internet_explorer:8.0.6001:beta"api_response=endpoints_client.cpe_get(cpe)
forcveinapi_response.data:
print(cve)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefget_cpe_vulnerabilities():
# 'async with' to manage the connection life-cycleasyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
cpe="cpe:/a:microsoft:internet_explorer:8.0.6001:beta"# 'await' the coroutine to get the actual response dataapi_response=awaitendpoints_client.cpe_get(cpe)
# Iterate through the resultsifapi_response.data:
forcveinapi_response.data:
print(cve)
else:
print(f"No vulnerabilities found for CPE: {cpe}")
if__name__=="__main__":
# Run the main async entry pointasyncio.run(get_cpe_vulnerabilities())

Index

Query VulnCheck-NVD2 for CVE-2019-19781

importvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
indices_client=vulncheck_sdk.IndicesApi(api_client)
api_response=indices_client.index_vulncheck_nvd2_get(cve="CVE-2019-19781")
print(api_response.data)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefget_cve_details():
# Use 'async with' for the ApiClientasyncwithvcaio.ApiClient(configuration) asapi_client:
indices_client=vcaio.IndicesApi(api_client)
# 'await' the API callapi_response=awaitindices_client.index_vulncheck_nvd2_get(
cve="CVE-2019-19781"
)
# Access and print the dataifapi_response.data:
print(api_response.data)
else:
print("No data found for the specified CVE.")
if__name__=="__main__":
# Start the async event loopasyncio.run(get_cve_details())

Indices

Get all available indices

importvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
endpoints_client=vulncheck_sdk.EndpointsApi(api_client)
api_response=endpoints_client.index_get()
forindexinapi_response.data:
print(index.name)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdeflist_indices():
# Use 'async with' to manage the connection life-cycleasyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
# 'await' the coroutine to get the actual responseapi_response=awaitendpoints_client.index_get()
# Iterate through the resultsifapi_response.data:
print(f"{'Index Name':<30} | {'Description'}")
print("-"*50)
forindexinapi_response.data:
print(f"{index.name:<30}")
else:
print("No indices found.")
if__name__=="__main__":
# 4. Entry point to run the asynchronous event loopasyncio.run(list_indices())

Pagination

Paginate over results for a query to VulnCheck-KEV using cursor

importvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
indices_client=vulncheck_sdk.IndicesApi(api_client)
api_response=indices_client.index_vulncheck_kev_get(
start_cursor="true",
# `limit` increases the size of each page, making it faster# to download large datasetslimit=300,
)
print(api_response.data)
whileapi_response.meta.next_cursorisnotNone:
api_response=indices_client.index_vulncheck_kev_get(
cursor=api_response.meta.next_cursor
)
print(api_response.data)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdeffetch_kev_data():
# Use 'async with' to properly manage the lifecycle of the async clientasyncwithvcaio.ApiClient(configuration) asapi_client:
indices_client=vcaio.IndicesApi(api_client)
# 'await' the coroutine to get the actual response dataapi_response=awaitindices_client.index_vulncheck_kev_get(
start_cursor="true", limit=300
)
print(f"Fetched {len(api_response.data)} records...")
# Process initial data# (e.g., save to a list or database)# Pagination loopwhileapi_response.metaandapi_response.meta.next_cursor:
print(f"Fetching next page: {api_response.meta.next_cursor}")
# 'await' the coroutine to get the actual response dataapi_response=awaitindices_client.index_vulncheck_kev_get(
cursor=api_response.meta.next_cursor, limit=300
)
ifapi_response.data:
print(f"Fetched {len(api_response.data)} records...")
else:
breakif__name__=="__main__":
# Entry point to run the async event loopasyncio.run(fetch_kev_data())

PURL

Get the CVE's for a given PURL

importvulncheck_sdkfromvulncheck_sdk.models.v3controllers_purl_response_dataimport (
V3controllersPurlResponseData,
)
importosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
endpoints_client=vulncheck_sdk.EndpointsApi(api_client)
purl="pkg:hex/coherence@0.1.2"api_response=endpoints_client.purl_get(purl)
data: V3controllersPurlResponseData=api_response.dataprint(data.cves)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaiofromvulncheck_sdk.aio.models.v3controllers_purl_response_dataimport (
V3controllersPurlResponseData,
)
# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefget_data(client, purl: str):
# Await the client call directlyapi_response=awaitclient.purl_get(purl)
# Access the data attribute from the response objectreturnapi_response.dataasyncdefmain():
asyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
purl="pkg:hex/coherence@0.1.2"# 'await' the async function calldata: V3controllersPurlResponseData=awaitget_data(endpoints_client, purl)
ifdataanddata.cves:
print(f"Found {len(data.cves)} CVEs:")
forcveindata.cves:
print(f"- {cve}")
else:
print("No CVEs found or data is empty.")
if__name__=="__main__":
asyncio.run(main())

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please create an issue.

Sponsorship

Development of this project is sponsored by VulnCheck learn more about us!

License

Apache License 2.0. Please see License File for more information.

About

A generated Python SDK from VulnCheck's OpenAPI specification

Topics

Resources

Contributing

Stars

14 stars

Watchers

2 watching

Forks

Releases

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

VulnCheck Logo

The VulnCheck SDK For Python

Bring the VulnCheck API to your Python applications.

PyPI - VersionJupyter

Installation

# From PyPi
pip install vulncheck-sdk

Important

Windows users may need to enable Long Path Support

Resources

Quickstart

importurllib.requestimportvulncheck_sdkimportos# First let's setup a few variables to help usTOKEN=os.environ["VULNCHECK_API_TOKEN"] # Remember to store your token securely!# Now let's create a configuration objectconfiguration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKEN# Pass that config object to our API client and now...withvulncheck_sdk.ApiClient(configuration) asapi_client:
# We can use two classes to explore the VulnCheck API: EndpointsApi & IndicesApi### EndpointsApi has methods to query every endpoint except `/v3/index`# See the full list of endpoints here: https://docs.vulncheck.com/apiendpoints_client=vulncheck_sdk.EndpointsApi(api_client)
# PURLapi_response=endpoints_client.purl_get("pkg:hex/coherence@0.1.2")
data=V3controllersPurlResponseData=api_response.dataprint(data.cves)
# CPEcpe="cpe:/a:microsoft:internet_explorer:8.0.6001:beta"api_response=endpoints_client.cpe_get(cpe)
forcveinapi_response.data:
print(cve)
# Download a Backupindex="initial-access"api_response=endpoints_client.backup_index_get(index)
file_path=f"{index}.zip"withurllib.request.urlopen(api_response.data[0].url) asresponse:
withopen(file_path, "wb") asfile:
file.write(response.read())
### IndicesApi has methods for each indexindices_client=vulncheck_sdk.IndicesApi(api_client)
# Add query parameters to filter what you needapi_response=indices_client.index_vulncheck_nvd2_get(cve="CVE-2019-19781")
print(api_response.data)
Click to View Async Implementation
importasyncioimportosimportaiohttpimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefrun_vulnerability_checks():
# Use 'async with' to manage the ApiClient connection poolasyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
indices_client=vcaio.IndicesApi(api_client)
# --- PURL Search ---# 'await' the coroutine to get resultspurl_response=awaitendpoints_client.purl_get("pkg:hex/coherence@0.1.2")
ifpurl_response.data:
print(f"PURL CVEs: {purl_response.data.cves}")
# --- CPE Search ---cpe="cpe:/a:microsoft:internet_explorer:8.0.6001:beta"# 'await' the coroutine to get resultscpe_response=awaitendpoints_client.cpe_get(cpe)
print(f"CPE Results for {cpe}:")
forcveincpe_response.data:
print(f" - {cve}")
# --- Index Query (NVD2) ---# 'await' the coroutine to get resultsnvd_response=awaitindices_client.index_vulncheck_nvd2_get(
cve="CVE-2019-19781"
)
print(f"NVD2 Data: {nvd_response.data}")
# --- Download Backup (Async) ---index_name="initial-access"# 'await' the coroutine to get resultsbackup_response=awaitendpoints_client.backup_index_get(index_name)
ifbackup_response.data:
download_url=backup_response.data[0].urlfile_path=f"{index_name}.zip"print(f"Downloading backup from {download_url}...")
# Use aiohttp (already in your environment) for async downloadasyncwithaiohttp.ClientSession() assession:
asyncwithsession.get(download_url) asresp:
ifresp.status==200:
# 'await' the coroutine to get resultscontent=awaitresp.read()
withopen(file_path, "wb") asf:
f.write(content)
print(f"Saved backup to {file_path}")
if__name__=="__main__":
# Entry point to start the event loopasyncio.run(run_vulnerability_checks())

Examples

Advisory

List all advisory feeds and query advisories filtered by feed

importvulncheck_sdkfromvulncheck_sdk.models.search_v4_advisory_return_valueimportSearchV4AdvisoryReturnValuefromvulncheck_sdk.models.search_v4_list_feed_return_valueimportSearchV4ListFeedReturnValueimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
advisory_client=vulncheck_sdk.AdvisoryApi(api_client)
# List all available advisory feeds (/v4/advisory)feeds: SearchV4ListFeedReturnValue=advisory_client.v4_list_advisory_feeds()
print("Available feeds:")
forfeedinfeeds.data:
print(f"name: {feed.name}")
feed="wolfi"# Query advisories filtered by feed=wolfi (/v4/advisory?feed=wolfi)advisories: SearchV4AdvisoryReturnValue=advisory_client.v4_query_advisories(name=feed)
print(f"{feed.capitalize()} advisories (page 1): {len(advisories.data)} results")
foradvisoryinadvisories.data:
print(f"cve: {advisory.cve_metadata.cve_id}")
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaiofromvulncheck_sdk.aio.models.search_v4_advisory_return_valueimportSearchV4AdvisoryReturnValuefromvulncheck_sdk.aio.models.search_v4_list_feed_return_valueimportSearchV4ListFeedReturnValueTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefmain():
asyncwithvcaio.ApiClient(configuration) asapi_client:
advisory_client=vcaio.AdvisoryApi(api_client)
# List all available advisory feeds (/v4/advisory)feeds: SearchV4ListFeedReturnValue=awaitadvisory_client.v4_list_advisory_feeds()
print("Available feeds:")
forfeedinfeeds.data:
print(f"name: {feed.name}")
feed="wolfi"# Query advisories filtered by feed=wolfi (/v4/advisory?feed=wolfi)advisories: SearchV4AdvisoryReturnValue=awaitadvisory_client.v4_query_advisories(name=feed)
print(f"{feed.capitalize()} advisories (page 1): {len(advisories.data)} results")
foradvisoryinadvisories.data:
print(f"cve: {advisory.cve_metadata.cve_id}")
if__name__=="__main__":
asyncio.run(main())

Backup

Download the backup for an index

importurllib.requestimportvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
endpoints_client=vulncheck_sdk.EndpointsApi(api_client)
index="initial-access"api_response=endpoints_client.backup_index_get(index)
file_path=f"{index}.zip"withurllib.request.urlopen(api_response.data[0].url) asresponse:
withopen(file_path, "wb") asfile:
file.write(response.read())
Click to View Async Implementation
importasyncioimportosimporturllib.requestimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENdefdownload_sync(url, file_path):
""" Standard synchronous download using urllib.request. This runs in a separate thread to avoid blocking the event loop. """withurllib.request.urlopen(url) asresponse:
withopen(file_path, "wb") asfile:
file.write(response.read())
asyncdefmain():
# Use 'async with' to manage the connection life-cycleasyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
index="initial-access"# 'await' the coroutine to get the actual response dataapi_response=awaitendpoints_client.backup_index_get(index)
ifnotapi_response.data:
print("No backup URL found.")
returndownload_url=api_response.data[0].urlfile_path=f"{index}.zip"print(f"Downloading {index} via urllib (offloaded to thread)...")
# Use asyncio.to_thread to run the blocking call safely# 'await' the coroutine to get the actual response dataawaitasyncio.to_thread(download_sync, download_url, file_path)
print(f"Successfully saved to {file_path}")
if__name__=="__main__":
asyncio.run(main())

Backup v4

List available v4 backups and download a backup by feed name

importosimporttempfileimporturllib.requestfromurllib3.util.retryimportRetryimportvulncheck_sdkfromvulncheck_sdk.models.backup_backup_responseimportBackupBackupResponsefromvulncheck_sdk.models.backup_list_backups_responseimportBackupListBackupsResponseTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENconfiguration.retries=Retry(
total=5,
backoff_factor=2,
status_forcelist=[502, 503, 504],
allowed_methods=["GET"],
respect_retry_after_header=True,
)
withvulncheck_sdk.ApiClient(configuration) asapi_client:
backup_client=vulncheck_sdk.BackupApi(api_client)
# List available backups (/v4/backup)available: BackupListBackupsResponse=backup_client.v4_list_backups()
forpotential_backupinavailable.data:
print(f"Found backup: {potential_backup.name}")
# Get backup for the wolfi feed (/v4/backup/wolfi)feed="wolfi"response: BackupBackupResponse=backup_client.v4_get_backup_by_name(feed)
print(response.to_json())
print(f"Downloading {feed} backup")
withtempfile.TemporaryDirectory() astmpdir:
file_path=os.path.join(tmpdir, f"{feed}.zip")
withurllib.request.urlopen(response.url_mrap) asr:
withopen(file_path, "wb") asf:
f.write(r.read())
print(f"Successfully saved to {file_path}")
Click to View Async Implementation
importasyncioimportosimporttempfileimporturllib.requestimportvulncheck_sdk.aioasvcaiofromvulncheck_sdk.aio.models.backup_backup_responseimportBackupBackupResponsefromvulncheck_sdk.aio.models.backup_list_backups_responseimport (
BackupListBackupsResponse,
)
TOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENconfiguration.retries=5defdownload_sync(url, file_path):
""" Standard synchronous download using urllib.request. This runs in a separate thread to avoid blocking the event loop. """withurllib.request.urlopen(url) asresponse:
withopen(file_path, "wb") asfile:
file.write(response.read())
asyncdefmain():
asyncwithvcaio.ApiClient(configuration) asapi_client:
backup_client=vcaio.BackupApi(api_client)
# List available backups (/v4/backup)available: BackupListBackupsResponse=awaitbackup_client.v4_list_backups()
forpotential_backupinavailable.data:
print(f"Found backup: {potential_backup.name}")
# Get backup for the wolfi feed (/v4/backup/wolfi)feed="wolfi"response: BackupBackupResponse=awaitbackup_client.v4_get_backup_by_name(feed)
print(response.to_json())
print(f"Downloading {feed} backup via urllib (offloaded to thread)...")
withtempfile.TemporaryDirectory() astmpdir:
file_path=os.path.join(tmpdir, f"{feed}.zip")
awaitasyncio.to_thread(download_sync, response.url_mrap, file_path)
print(f"Successfully saved to {file_path}")
if__name__=="__main__":
asyncio.run(main())

CPE

Get all CPE's related to a CVE

importvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
endpoints_client=vulncheck_sdk.EndpointsApi(api_client)
cpe="cpe:/a:microsoft:internet_explorer:8.0.6001:beta"api_response=endpoints_client.cpe_get(cpe)
forcveinapi_response.data:
print(cve)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefget_cpe_vulnerabilities():
# 'async with' to manage the connection life-cycleasyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
cpe="cpe:/a:microsoft:internet_explorer:8.0.6001:beta"# 'await' the coroutine to get the actual response dataapi_response=awaitendpoints_client.cpe_get(cpe)
# Iterate through the resultsifapi_response.data:
forcveinapi_response.data:
print(cve)
else:
print(f"No vulnerabilities found for CPE: {cpe}")
if__name__=="__main__":
# Run the main async entry pointasyncio.run(get_cpe_vulnerabilities())

Index

Query VulnCheck-NVD2 for CVE-2019-19781

importvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
indices_client=vulncheck_sdk.IndicesApi(api_client)
api_response=indices_client.index_vulncheck_nvd2_get(cve="CVE-2019-19781")
print(api_response.data)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefget_cve_details():
# Use 'async with' for the ApiClientasyncwithvcaio.ApiClient(configuration) asapi_client:
indices_client=vcaio.IndicesApi(api_client)
# 'await' the API callapi_response=awaitindices_client.index_vulncheck_nvd2_get(
cve="CVE-2019-19781"
)
# Access and print the dataifapi_response.data:
print(api_response.data)
else:
print("No data found for the specified CVE.")
if__name__=="__main__":
# Start the async event loopasyncio.run(get_cve_details())

Indices

Get all available indices

importvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
endpoints_client=vulncheck_sdk.EndpointsApi(api_client)
api_response=endpoints_client.index_get()
forindexinapi_response.data:
print(index.name)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdeflist_indices():
# Use 'async with' to manage the connection life-cycleasyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
# 'await' the coroutine to get the actual responseapi_response=awaitendpoints_client.index_get()
# Iterate through the resultsifapi_response.data:
print(f"{'Index Name':<30} | {'Description'}")
print("-"*50)
forindexinapi_response.data:
print(f"{index.name:<30}")
else:
print("No indices found.")
if__name__=="__main__":
# 4. Entry point to run the asynchronous event loopasyncio.run(list_indices())

Pagination

Paginate over results for a query to VulnCheck-KEV using cursor

importvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
indices_client=vulncheck_sdk.IndicesApi(api_client)
api_response=indices_client.index_vulncheck_kev_get(
start_cursor="true",
# `limit` increases the size of each page, making it faster# to download large datasetslimit=300,
)
print(api_response.data)
whileapi_response.meta.next_cursorisnotNone:
api_response=indices_client.index_vulncheck_kev_get(
cursor=api_response.meta.next_cursor
)
print(api_response.data)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdeffetch_kev_data():
# Use 'async with' to properly manage the lifecycle of the async clientasyncwithvcaio.ApiClient(configuration) asapi_client:
indices_client=vcaio.IndicesApi(api_client)
# 'await' the coroutine to get the actual response dataapi_response=awaitindices_client.index_vulncheck_kev_get(
start_cursor="true", limit=300
)
print(f"Fetched {len(api_response.data)} records...")
# Process initial data# (e.g., save to a list or database)# Pagination loopwhileapi_response.metaandapi_response.meta.next_cursor:
print(f"Fetching next page: {api_response.meta.next_cursor}")
# 'await' the coroutine to get the actual response dataapi_response=awaitindices_client.index_vulncheck_kev_get(
cursor=api_response.meta.next_cursor, limit=300
)
ifapi_response.data:
print(f"Fetched {len(api_response.data)} records...")
else:
breakif__name__=="__main__":
# Entry point to run the async event loopasyncio.run(fetch_kev_data())

PURL

Get the CVE's for a given PURL

importvulncheck_sdkfromvulncheck_sdk.models.v3controllers_purl_response_dataimport (
V3controllersPurlResponseData,
)
importosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
endpoints_client=vulncheck_sdk.EndpointsApi(api_client)
purl="pkg:hex/coherence@0.1.2"api_response=endpoints_client.purl_get(purl)
data: V3controllersPurlResponseData=api_response.dataprint(data.cves)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaiofromvulncheck_sdk.aio.models.v3controllers_purl_response_dataimport (
V3controllersPurlResponseData,
)
# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefget_data(client, purl: str):
# Await the client call directlyapi_response=awaitclient.purl_get(purl)
# Access the data attribute from the response objectreturnapi_response.dataasyncdefmain():
asyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
purl="pkg:hex/coherence@0.1.2"# 'await' the async function calldata: V3controllersPurlResponseData=awaitget_data(endpoints_client, purl)
ifdataanddata.cves:
print(f"Found {len(data.cves)} CVEs:")
forcveindata.cves:
print(f"- {cve}")
else:
print("No CVEs found or data is empty.")
if__name__=="__main__":
asyncio.run(main())

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please create an issue.

Sponsorship

Development of this project is sponsored by VulnCheck learn more about us!

License

Apache License 2.0. Please see License File for more information.

About

A generated Python SDK from VulnCheck's OpenAPI specification

Topics

Resources

Contributing

Stars

14 stars

Watchers

2 watching

Forks

Releases

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

VulnCheck Logo

The VulnCheck SDK For Python

Bring the VulnCheck API to your Python applications.

PyPI - VersionJupyter

Installation

# From PyPi
pip install vulncheck-sdk

Important

Windows users may need to enable Long Path Support

Resources

Quickstart

importurllib.requestimportvulncheck_sdkimportos# First let's setup a few variables to help usTOKEN=os.environ["VULNCHECK_API_TOKEN"] # Remember to store your token securely!# Now let's create a configuration objectconfiguration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKEN# Pass that config object to our API client and now...withvulncheck_sdk.ApiClient(configuration) asapi_client:
# We can use two classes to explore the VulnCheck API: EndpointsApi & IndicesApi### EndpointsApi has methods to query every endpoint except `/v3/index`# See the full list of endpoints here: https://docs.vulncheck.com/apiendpoints_client=vulncheck_sdk.EndpointsApi(api_client)
# PURLapi_response=endpoints_client.purl_get("pkg:hex/coherence@0.1.2")
data=V3controllersPurlResponseData=api_response.dataprint(data.cves)
# CPEcpe="cpe:/a:microsoft:internet_explorer:8.0.6001:beta"api_response=endpoints_client.cpe_get(cpe)
forcveinapi_response.data:
print(cve)
# Download a Backupindex="initial-access"api_response=endpoints_client.backup_index_get(index)
file_path=f"{index}.zip"withurllib.request.urlopen(api_response.data[0].url) asresponse:
withopen(file_path, "wb") asfile:
file.write(response.read())
### IndicesApi has methods for each indexindices_client=vulncheck_sdk.IndicesApi(api_client)
# Add query parameters to filter what you needapi_response=indices_client.index_vulncheck_nvd2_get(cve="CVE-2019-19781")
print(api_response.data)
Click to View Async Implementation
importasyncioimportosimportaiohttpimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefrun_vulnerability_checks():
# Use 'async with' to manage the ApiClient connection poolasyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
indices_client=vcaio.IndicesApi(api_client)
# --- PURL Search ---# 'await' the coroutine to get resultspurl_response=awaitendpoints_client.purl_get("pkg:hex/coherence@0.1.2")
ifpurl_response.data:
print(f"PURL CVEs: {purl_response.data.cves}")
# --- CPE Search ---cpe="cpe:/a:microsoft:internet_explorer:8.0.6001:beta"# 'await' the coroutine to get resultscpe_response=awaitendpoints_client.cpe_get(cpe)
print(f"CPE Results for {cpe}:")
forcveincpe_response.data:
print(f" - {cve}")
# --- Index Query (NVD2) ---# 'await' the coroutine to get resultsnvd_response=awaitindices_client.index_vulncheck_nvd2_get(
cve="CVE-2019-19781"
)
print(f"NVD2 Data: {nvd_response.data}")
# --- Download Backup (Async) ---index_name="initial-access"# 'await' the coroutine to get resultsbackup_response=awaitendpoints_client.backup_index_get(index_name)
ifbackup_response.data:
download_url=backup_response.data[0].urlfile_path=f"{index_name}.zip"print(f"Downloading backup from {download_url}...")
# Use aiohttp (already in your environment) for async downloadasyncwithaiohttp.ClientSession() assession:
asyncwithsession.get(download_url) asresp:
ifresp.status==200:
# 'await' the coroutine to get resultscontent=awaitresp.read()
withopen(file_path, "wb") asf:
f.write(content)
print(f"Saved backup to {file_path}")
if__name__=="__main__":
# Entry point to start the event loopasyncio.run(run_vulnerability_checks())

Examples

Advisory

List all advisory feeds and query advisories filtered by feed

importvulncheck_sdkfromvulncheck_sdk.models.search_v4_advisory_return_valueimportSearchV4AdvisoryReturnValuefromvulncheck_sdk.models.search_v4_list_feed_return_valueimportSearchV4ListFeedReturnValueimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
advisory_client=vulncheck_sdk.AdvisoryApi(api_client)
# List all available advisory feeds (/v4/advisory)feeds: SearchV4ListFeedReturnValue=advisory_client.v4_list_advisory_feeds()
print("Available feeds:")
forfeedinfeeds.data:
print(f"name: {feed.name}")
feed="wolfi"# Query advisories filtered by feed=wolfi (/v4/advisory?feed=wolfi)advisories: SearchV4AdvisoryReturnValue=advisory_client.v4_query_advisories(name=feed)
print(f"{feed.capitalize()} advisories (page 1): {len(advisories.data)} results")
foradvisoryinadvisories.data:
print(f"cve: {advisory.cve_metadata.cve_id}")
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaiofromvulncheck_sdk.aio.models.search_v4_advisory_return_valueimportSearchV4AdvisoryReturnValuefromvulncheck_sdk.aio.models.search_v4_list_feed_return_valueimportSearchV4ListFeedReturnValueTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefmain():
asyncwithvcaio.ApiClient(configuration) asapi_client:
advisory_client=vcaio.AdvisoryApi(api_client)
# List all available advisory feeds (/v4/advisory)feeds: SearchV4ListFeedReturnValue=awaitadvisory_client.v4_list_advisory_feeds()
print("Available feeds:")
forfeedinfeeds.data:
print(f"name: {feed.name}")
feed="wolfi"# Query advisories filtered by feed=wolfi (/v4/advisory?feed=wolfi)advisories: SearchV4AdvisoryReturnValue=awaitadvisory_client.v4_query_advisories(name=feed)
print(f"{feed.capitalize()} advisories (page 1): {len(advisories.data)} results")
foradvisoryinadvisories.data:
print(f"cve: {advisory.cve_metadata.cve_id}")
if__name__=="__main__":
asyncio.run(main())

Backup

Download the backup for an index

importurllib.requestimportvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
endpoints_client=vulncheck_sdk.EndpointsApi(api_client)
index="initial-access"api_response=endpoints_client.backup_index_get(index)
file_path=f"{index}.zip"withurllib.request.urlopen(api_response.data[0].url) asresponse:
withopen(file_path, "wb") asfile:
file.write(response.read())
Click to View Async Implementation
importasyncioimportosimporturllib.requestimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENdefdownload_sync(url, file_path):
""" Standard synchronous download using urllib.request. This runs in a separate thread to avoid blocking the event loop. """withurllib.request.urlopen(url) asresponse:
withopen(file_path, "wb") asfile:
file.write(response.read())
asyncdefmain():
# Use 'async with' to manage the connection life-cycleasyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
index="initial-access"# 'await' the coroutine to get the actual response dataapi_response=awaitendpoints_client.backup_index_get(index)
ifnotapi_response.data:
print("No backup URL found.")
returndownload_url=api_response.data[0].urlfile_path=f"{index}.zip"print(f"Downloading {index} via urllib (offloaded to thread)...")
# Use asyncio.to_thread to run the blocking call safely# 'await' the coroutine to get the actual response dataawaitasyncio.to_thread(download_sync, download_url, file_path)
print(f"Successfully saved to {file_path}")
if__name__=="__main__":
asyncio.run(main())

Backup v4

List available v4 backups and download a backup by feed name

importosimporttempfileimporturllib.requestfromurllib3.util.retryimportRetryimportvulncheck_sdkfromvulncheck_sdk.models.backup_backup_responseimportBackupBackupResponsefromvulncheck_sdk.models.backup_list_backups_responseimportBackupListBackupsResponseTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENconfiguration.retries=Retry(
total=5,
backoff_factor=2,
status_forcelist=[502, 503, 504],
allowed_methods=["GET"],
respect_retry_after_header=True,
)
withvulncheck_sdk.ApiClient(configuration) asapi_client:
backup_client=vulncheck_sdk.BackupApi(api_client)
# List available backups (/v4/backup)available: BackupListBackupsResponse=backup_client.v4_list_backups()
forpotential_backupinavailable.data:
print(f"Found backup: {potential_backup.name}")
# Get backup for the wolfi feed (/v4/backup/wolfi)feed="wolfi"response: BackupBackupResponse=backup_client.v4_get_backup_by_name(feed)
print(response.to_json())
print(f"Downloading {feed} backup")
withtempfile.TemporaryDirectory() astmpdir:
file_path=os.path.join(tmpdir, f"{feed}.zip")
withurllib.request.urlopen(response.url_mrap) asr:
withopen(file_path, "wb") asf:
f.write(r.read())
print(f"Successfully saved to {file_path}")
Click to View Async Implementation
importasyncioimportosimporttempfileimporturllib.requestimportvulncheck_sdk.aioasvcaiofromvulncheck_sdk.aio.models.backup_backup_responseimportBackupBackupResponsefromvulncheck_sdk.aio.models.backup_list_backups_responseimport (
BackupListBackupsResponse,
)
TOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENconfiguration.retries=5defdownload_sync(url, file_path):
""" Standard synchronous download using urllib.request. This runs in a separate thread to avoid blocking the event loop. """withurllib.request.urlopen(url) asresponse:
withopen(file_path, "wb") asfile:
file.write(response.read())
asyncdefmain():
asyncwithvcaio.ApiClient(configuration) asapi_client:
backup_client=vcaio.BackupApi(api_client)
# List available backups (/v4/backup)available: BackupListBackupsResponse=awaitbackup_client.v4_list_backups()
forpotential_backupinavailable.data:
print(f"Found backup: {potential_backup.name}")
# Get backup for the wolfi feed (/v4/backup/wolfi)feed="wolfi"response: BackupBackupResponse=awaitbackup_client.v4_get_backup_by_name(feed)
print(response.to_json())
print(f"Downloading {feed} backup via urllib (offloaded to thread)...")
withtempfile.TemporaryDirectory() astmpdir:
file_path=os.path.join(tmpdir, f"{feed}.zip")
awaitasyncio.to_thread(download_sync, response.url_mrap, file_path)
print(f"Successfully saved to {file_path}")
if__name__=="__main__":
asyncio.run(main())

CPE

Get all CPE's related to a CVE

importvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
endpoints_client=vulncheck_sdk.EndpointsApi(api_client)
cpe="cpe:/a:microsoft:internet_explorer:8.0.6001:beta"api_response=endpoints_client.cpe_get(cpe)
forcveinapi_response.data:
print(cve)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefget_cpe_vulnerabilities():
# 'async with' to manage the connection life-cycleasyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
cpe="cpe:/a:microsoft:internet_explorer:8.0.6001:beta"# 'await' the coroutine to get the actual response dataapi_response=awaitendpoints_client.cpe_get(cpe)
# Iterate through the resultsifapi_response.data:
forcveinapi_response.data:
print(cve)
else:
print(f"No vulnerabilities found for CPE: {cpe}")
if__name__=="__main__":
# Run the main async entry pointasyncio.run(get_cpe_vulnerabilities())

Index

Query VulnCheck-NVD2 for CVE-2019-19781

importvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
indices_client=vulncheck_sdk.IndicesApi(api_client)
api_response=indices_client.index_vulncheck_nvd2_get(cve="CVE-2019-19781")
print(api_response.data)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefget_cve_details():
# Use 'async with' for the ApiClientasyncwithvcaio.ApiClient(configuration) asapi_client:
indices_client=vcaio.IndicesApi(api_client)
# 'await' the API callapi_response=awaitindices_client.index_vulncheck_nvd2_get(
cve="CVE-2019-19781"
)
# Access and print the dataifapi_response.data:
print(api_response.data)
else:
print("No data found for the specified CVE.")
if__name__=="__main__":
# Start the async event loopasyncio.run(get_cve_details())

Indices

Get all available indices

importvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
endpoints_client=vulncheck_sdk.EndpointsApi(api_client)
api_response=endpoints_client.index_get()
forindexinapi_response.data:
print(index.name)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdeflist_indices():
# Use 'async with' to manage the connection life-cycleasyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
# 'await' the coroutine to get the actual responseapi_response=awaitendpoints_client.index_get()
# Iterate through the resultsifapi_response.data:
print(f"{'Index Name':<30} | {'Description'}")
print("-"*50)
forindexinapi_response.data:
print(f"{index.name:<30}")
else:
print("No indices found.")
if__name__=="__main__":
# 4. Entry point to run the asynchronous event loopasyncio.run(list_indices())

Pagination

Paginate over results for a query to VulnCheck-KEV using cursor

importvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
indices_client=vulncheck_sdk.IndicesApi(api_client)
api_response=indices_client.index_vulncheck_kev_get(
start_cursor="true",
# `limit` increases the size of each page, making it faster# to download large datasetslimit=300,
)
print(api_response.data)
whileapi_response.meta.next_cursorisnotNone:
api_response=indices_client.index_vulncheck_kev_get(
cursor=api_response.meta.next_cursor
)
print(api_response.data)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdeffetch_kev_data():
# Use 'async with' to properly manage the lifecycle of the async clientasyncwithvcaio.ApiClient(configuration) asapi_client:
indices_client=vcaio.IndicesApi(api_client)
# 'await' the coroutine to get the actual response dataapi_response=awaitindices_client.index_vulncheck_kev_get(
start_cursor="true", limit=300
)
print(f"Fetched {len(api_response.data)} records...")
# Process initial data# (e.g., save to a list or database)# Pagination loopwhileapi_response.metaandapi_response.meta.next_cursor:
print(f"Fetching next page: {api_response.meta.next_cursor}")
# 'await' the coroutine to get the actual response dataapi_response=awaitindices_client.index_vulncheck_kev_get(
cursor=api_response.meta.next_cursor, limit=300
)
ifapi_response.data:
print(f"Fetched {len(api_response.data)} records...")
else:
breakif__name__=="__main__":
# Entry point to run the async event loopasyncio.run(fetch_kev_data())

PURL

Get the CVE's for a given PURL

importvulncheck_sdkfromvulncheck_sdk.models.v3controllers_purl_response_dataimport (
V3controllersPurlResponseData,
)
importosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
endpoints_client=vulncheck_sdk.EndpointsApi(api_client)
purl="pkg:hex/coherence@0.1.2"api_response=endpoints_client.purl_get(purl)
data: V3controllersPurlResponseData=api_response.dataprint(data.cves)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaiofromvulncheck_sdk.aio.models.v3controllers_purl_response_dataimport (
V3controllersPurlResponseData,
)
# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefget_data(client, purl: str):
# Await the client call directlyapi_response=awaitclient.purl_get(purl)
# Access the data attribute from the response objectreturnapi_response.dataasyncdefmain():
asyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
purl="pkg:hex/coherence@0.1.2"# 'await' the async function calldata: V3controllersPurlResponseData=awaitget_data(endpoints_client, purl)
ifdataanddata.cves:
print(f"Found {len(data.cves)} CVEs:")
forcveindata.cves:
print(f"- {cve}")
else:
print("No CVEs found or data is empty.")
if__name__=="__main__":
asyncio.run(main())

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please create an issue.

Sponsorship

Development of this project is sponsored by VulnCheck learn more about us!

License

Apache License 2.0. Please see License File for more information.

About

A generated Python SDK from VulnCheck's OpenAPI specification

Topics

Resources

Contributing

Stars

14 stars

Watchers

2 watching

Forks

Releases

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Repository files navigation

VulnCheck Logo

The VulnCheck SDK For Python

Bring the VulnCheck API to your Python applications.

PyPI - VersionJupyter

Installation

# From PyPi
pip install vulncheck-sdk

Important

Windows users may need to enable Long Path Support

Resources

Quickstart

importurllib.requestimportvulncheck_sdkimportos# First let's setup a few variables to help usTOKEN=os.environ["VULNCHECK_API_TOKEN"] # Remember to store your token securely!# Now let's create a configuration objectconfiguration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKEN# Pass that config object to our API client and now...withvulncheck_sdk.ApiClient(configuration) asapi_client:
# We can use two classes to explore the VulnCheck API: EndpointsApi & IndicesApi### EndpointsApi has methods to query every endpoint except `/v3/index`# See the full list of endpoints here: https://docs.vulncheck.com/apiendpoints_client=vulncheck_sdk.EndpointsApi(api_client)
# PURLapi_response=endpoints_client.purl_get("pkg:hex/coherence@0.1.2")
data=V3controllersPurlResponseData=api_response.dataprint(data.cves)
# CPEcpe="cpe:/a:microsoft:internet_explorer:8.0.6001:beta"api_response=endpoints_client.cpe_get(cpe)
forcveinapi_response.data:
print(cve)
# Download a Backupindex="initial-access"api_response=endpoints_client.backup_index_get(index)
file_path=f"{index}.zip"withurllib.request.urlopen(api_response.data[0].url) asresponse:
withopen(file_path, "wb") asfile:
file.write(response.read())
### IndicesApi has methods for each indexindices_client=vulncheck_sdk.IndicesApi(api_client)
# Add query parameters to filter what you needapi_response=indices_client.index_vulncheck_nvd2_get(cve="CVE-2019-19781")
print(api_response.data)
Click to View Async Implementation
importasyncioimportosimportaiohttpimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefrun_vulnerability_checks():
# Use 'async with' to manage the ApiClient connection poolasyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
indices_client=vcaio.IndicesApi(api_client)
# --- PURL Search ---# 'await' the coroutine to get resultspurl_response=awaitendpoints_client.purl_get("pkg:hex/coherence@0.1.2")
ifpurl_response.data:
print(f"PURL CVEs: {purl_response.data.cves}")
# --- CPE Search ---cpe="cpe:/a:microsoft:internet_explorer:8.0.6001:beta"# 'await' the coroutine to get resultscpe_response=awaitendpoints_client.cpe_get(cpe)
print(f"CPE Results for {cpe}:")
forcveincpe_response.data:
print(f" - {cve}")
# --- Index Query (NVD2) ---# 'await' the coroutine to get resultsnvd_response=awaitindices_client.index_vulncheck_nvd2_get(
cve="CVE-2019-19781"
)
print(f"NVD2 Data: {nvd_response.data}")
# --- Download Backup (Async) ---index_name="initial-access"# 'await' the coroutine to get resultsbackup_response=awaitendpoints_client.backup_index_get(index_name)
ifbackup_response.data:
download_url=backup_response.data[0].urlfile_path=f"{index_name}.zip"print(f"Downloading backup from {download_url}...")
# Use aiohttp (already in your environment) for async downloadasyncwithaiohttp.ClientSession() assession:
asyncwithsession.get(download_url) asresp:
ifresp.status==200:
# 'await' the coroutine to get resultscontent=awaitresp.read()
withopen(file_path, "wb") asf:
f.write(content)
print(f"Saved backup to {file_path}")
if__name__=="__main__":
# Entry point to start the event loopasyncio.run(run_vulnerability_checks())

Examples

Advisory

List all advisory feeds and query advisories filtered by feed

importvulncheck_sdkfromvulncheck_sdk.models.search_v4_advisory_return_valueimportSearchV4AdvisoryReturnValuefromvulncheck_sdk.models.search_v4_list_feed_return_valueimportSearchV4ListFeedReturnValueimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
advisory_client=vulncheck_sdk.AdvisoryApi(api_client)
# List all available advisory feeds (/v4/advisory)feeds: SearchV4ListFeedReturnValue=advisory_client.v4_list_advisory_feeds()
print("Available feeds:")
forfeedinfeeds.data:
print(f"name: {feed.name}")
feed="wolfi"# Query advisories filtered by feed=wolfi (/v4/advisory?feed=wolfi)advisories: SearchV4AdvisoryReturnValue=advisory_client.v4_query_advisories(name=feed)
print(f"{feed.capitalize()} advisories (page 1): {len(advisories.data)} results")
foradvisoryinadvisories.data:
print(f"cve: {advisory.cve_metadata.cve_id}")
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaiofromvulncheck_sdk.aio.models.search_v4_advisory_return_valueimportSearchV4AdvisoryReturnValuefromvulncheck_sdk.aio.models.search_v4_list_feed_return_valueimportSearchV4ListFeedReturnValueTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefmain():
asyncwithvcaio.ApiClient(configuration) asapi_client:
advisory_client=vcaio.AdvisoryApi(api_client)
# List all available advisory feeds (/v4/advisory)feeds: SearchV4ListFeedReturnValue=awaitadvisory_client.v4_list_advisory_feeds()
print("Available feeds:")
forfeedinfeeds.data:
print(f"name: {feed.name}")
feed="wolfi"# Query advisories filtered by feed=wolfi (/v4/advisory?feed=wolfi)advisories: SearchV4AdvisoryReturnValue=awaitadvisory_client.v4_query_advisories(name=feed)
print(f"{feed.capitalize()} advisories (page 1): {len(advisories.data)} results")
foradvisoryinadvisories.data:
print(f"cve: {advisory.cve_metadata.cve_id}")
if__name__=="__main__":
asyncio.run(main())

Backup

Download the backup for an index

importurllib.requestimportvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
endpoints_client=vulncheck_sdk.EndpointsApi(api_client)
index="initial-access"api_response=endpoints_client.backup_index_get(index)
file_path=f"{index}.zip"withurllib.request.urlopen(api_response.data[0].url) asresponse:
withopen(file_path, "wb") asfile:
file.write(response.read())
Click to View Async Implementation
importasyncioimportosimporturllib.requestimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENdefdownload_sync(url, file_path):
""" Standard synchronous download using urllib.request. This runs in a separate thread to avoid blocking the event loop. """withurllib.request.urlopen(url) asresponse:
withopen(file_path, "wb") asfile:
file.write(response.read())
asyncdefmain():
# Use 'async with' to manage the connection life-cycleasyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
index="initial-access"# 'await' the coroutine to get the actual response dataapi_response=awaitendpoints_client.backup_index_get(index)
ifnotapi_response.data:
print("No backup URL found.")
returndownload_url=api_response.data[0].urlfile_path=f"{index}.zip"print(f"Downloading {index} via urllib (offloaded to thread)...")
# Use asyncio.to_thread to run the blocking call safely# 'await' the coroutine to get the actual response dataawaitasyncio.to_thread(download_sync, download_url, file_path)
print(f"Successfully saved to {file_path}")
if__name__=="__main__":
asyncio.run(main())

Backup v4

List available v4 backups and download a backup by feed name

importosimporttempfileimporturllib.requestfromurllib3.util.retryimportRetryimportvulncheck_sdkfromvulncheck_sdk.models.backup_backup_responseimportBackupBackupResponsefromvulncheck_sdk.models.backup_list_backups_responseimportBackupListBackupsResponseTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENconfiguration.retries=Retry(
total=5,
backoff_factor=2,
status_forcelist=[502, 503, 504],
allowed_methods=["GET"],
respect_retry_after_header=True,
)
withvulncheck_sdk.ApiClient(configuration) asapi_client:
backup_client=vulncheck_sdk.BackupApi(api_client)
# List available backups (/v4/backup)available: BackupListBackupsResponse=backup_client.v4_list_backups()
forpotential_backupinavailable.data:
print(f"Found backup: {potential_backup.name}")
# Get backup for the wolfi feed (/v4/backup/wolfi)feed="wolfi"response: BackupBackupResponse=backup_client.v4_get_backup_by_name(feed)
print(response.to_json())
print(f"Downloading {feed} backup")
withtempfile.TemporaryDirectory() astmpdir:
file_path=os.path.join(tmpdir, f"{feed}.zip")
withurllib.request.urlopen(response.url_mrap) asr:
withopen(file_path, "wb") asf:
f.write(r.read())
print(f"Successfully saved to {file_path}")
Click to View Async Implementation
importasyncioimportosimporttempfileimporturllib.requestimportvulncheck_sdk.aioasvcaiofromvulncheck_sdk.aio.models.backup_backup_responseimportBackupBackupResponsefromvulncheck_sdk.aio.models.backup_list_backups_responseimport (
BackupListBackupsResponse,
)
TOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENconfiguration.retries=5defdownload_sync(url, file_path):
""" Standard synchronous download using urllib.request. This runs in a separate thread to avoid blocking the event loop. """withurllib.request.urlopen(url) asresponse:
withopen(file_path, "wb") asfile:
file.write(response.read())
asyncdefmain():
asyncwithvcaio.ApiClient(configuration) asapi_client:
backup_client=vcaio.BackupApi(api_client)
# List available backups (/v4/backup)available: BackupListBackupsResponse=awaitbackup_client.v4_list_backups()
forpotential_backupinavailable.data:
print(f"Found backup: {potential_backup.name}")
# Get backup for the wolfi feed (/v4/backup/wolfi)feed="wolfi"response: BackupBackupResponse=awaitbackup_client.v4_get_backup_by_name(feed)
print(response.to_json())
print(f"Downloading {feed} backup via urllib (offloaded to thread)...")
withtempfile.TemporaryDirectory() astmpdir:
file_path=os.path.join(tmpdir, f"{feed}.zip")
awaitasyncio.to_thread(download_sync, response.url_mrap, file_path)
print(f"Successfully saved to {file_path}")
if__name__=="__main__":
asyncio.run(main())

CPE

Get all CPE's related to a CVE

importvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
endpoints_client=vulncheck_sdk.EndpointsApi(api_client)
cpe="cpe:/a:microsoft:internet_explorer:8.0.6001:beta"api_response=endpoints_client.cpe_get(cpe)
forcveinapi_response.data:
print(cve)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefget_cpe_vulnerabilities():
# 'async with' to manage the connection life-cycleasyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
cpe="cpe:/a:microsoft:internet_explorer:8.0.6001:beta"# 'await' the coroutine to get the actual response dataapi_response=awaitendpoints_client.cpe_get(cpe)
# Iterate through the resultsifapi_response.data:
forcveinapi_response.data:
print(cve)
else:
print(f"No vulnerabilities found for CPE: {cpe}")
if__name__=="__main__":
# Run the main async entry pointasyncio.run(get_cpe_vulnerabilities())

Index

Query VulnCheck-NVD2 for CVE-2019-19781

importvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
indices_client=vulncheck_sdk.IndicesApi(api_client)
api_response=indices_client.index_vulncheck_nvd2_get(cve="CVE-2019-19781")
print(api_response.data)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefget_cve_details():
# Use 'async with' for the ApiClientasyncwithvcaio.ApiClient(configuration) asapi_client:
indices_client=vcaio.IndicesApi(api_client)
# 'await' the API callapi_response=awaitindices_client.index_vulncheck_nvd2_get(
cve="CVE-2019-19781"
)
# Access and print the dataifapi_response.data:
print(api_response.data)
else:
print("No data found for the specified CVE.")
if__name__=="__main__":
# Start the async event loopasyncio.run(get_cve_details())

Indices

Get all available indices

importvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
endpoints_client=vulncheck_sdk.EndpointsApi(api_client)
api_response=endpoints_client.index_get()
forindexinapi_response.data:
print(index.name)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdeflist_indices():
# Use 'async with' to manage the connection life-cycleasyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
# 'await' the coroutine to get the actual responseapi_response=awaitendpoints_client.index_get()
# Iterate through the resultsifapi_response.data:
print(f"{'Index Name':<30} | {'Description'}")
print("-"*50)
forindexinapi_response.data:
print(f"{index.name:<30}")
else:
print("No indices found.")
if__name__=="__main__":
# 4. Entry point to run the asynchronous event loopasyncio.run(list_indices())

Pagination

Paginate over results for a query to VulnCheck-KEV using cursor

importvulncheck_sdkimportosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
indices_client=vulncheck_sdk.IndicesApi(api_client)
api_response=indices_client.index_vulncheck_kev_get(
start_cursor="true",
# `limit` increases the size of each page, making it faster# to download large datasetslimit=300,
)
print(api_response.data)
whileapi_response.meta.next_cursorisnotNone:
api_response=indices_client.index_vulncheck_kev_get(
cursor=api_response.meta.next_cursor
)
print(api_response.data)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaio# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdeffetch_kev_data():
# Use 'async with' to properly manage the lifecycle of the async clientasyncwithvcaio.ApiClient(configuration) asapi_client:
indices_client=vcaio.IndicesApi(api_client)
# 'await' the coroutine to get the actual response dataapi_response=awaitindices_client.index_vulncheck_kev_get(
start_cursor="true", limit=300
)
print(f"Fetched {len(api_response.data)} records...")
# Process initial data# (e.g., save to a list or database)# Pagination loopwhileapi_response.metaandapi_response.meta.next_cursor:
print(f"Fetching next page: {api_response.meta.next_cursor}")
# 'await' the coroutine to get the actual response dataapi_response=awaitindices_client.index_vulncheck_kev_get(
cursor=api_response.meta.next_cursor, limit=300
)
ifapi_response.data:
print(f"Fetched {len(api_response.data)} records...")
else:
breakif__name__=="__main__":
# Entry point to run the async event loopasyncio.run(fetch_kev_data())

PURL

Get the CVE's for a given PURL

importvulncheck_sdkfromvulncheck_sdk.models.v3controllers_purl_response_dataimport (
V3controllersPurlResponseData,
)
importosTOKEN=os.environ["VULNCHECK_API_TOKEN"]
configuration=vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] =TOKENwithvulncheck_sdk.ApiClient(configuration) asapi_client:
endpoints_client=vulncheck_sdk.EndpointsApi(api_client)
purl="pkg:hex/coherence@0.1.2"api_response=endpoints_client.purl_get(purl)
data: V3controllersPurlResponseData=api_response.dataprint(data.cves)
Click to View Async Implementation
importasyncioimportosimportvulncheck_sdk.aioasvcaiofromvulncheck_sdk.aio.models.v3controllers_purl_response_dataimport (
V3controllersPurlResponseData,
)
# ConfigurationTOKEN=os.environ.get("VULNCHECK_API_TOKEN")
configuration=vcaio.Configuration()
configuration.api_key["Bearer"] =TOKENasyncdefget_data(client, purl: str):
# Await the client call directlyapi_response=awaitclient.purl_get(purl)
# Access the data attribute from the response objectreturnapi_response.dataasyncdefmain():
asyncwithvcaio.ApiClient(configuration) asapi_client:
endpoints_client=vcaio.EndpointsApi(api_client)
purl="pkg:hex/coherence@0.1.2"# 'await' the async function calldata: V3controllersPurlResponseData=awaitget_data(endpoints_client, purl)
ifdataanddata.cves:
print(f"Found {len(data.cves)} CVEs:")
forcveindata.cves:
print(f"- {cve}")
else:
print("No CVEs found or data is empty.")
if__name__=="__main__":
asyncio.run(main())

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please create an issue.

Sponsorship

Development of this project is sponsored by VulnCheck learn more about us!

License

Apache License 2.0. Please see License File for more information.

About

A generated Python SDK from VulnCheck's OpenAPI specification

Topics

Resources

Contributing

Stars

14 stars

Watchers

2 watching

Forks

Releases

Used by

Contributors

Languages