Skip to navigation

Python SDK

Detectant

Detectant Python SDK

Detectant is a malware scanning API with support for Python

Scan files for malware from synchronous or asynchronous Python applications.

Install

pip install detectant-sdk

Set your API key in the environment:

export DETECTANT_API_KEY="your-api-key"

Create a client

import os
from detectant import Detectant
detectant = Detectant(api_key=os.environ["DETECTANT_API_KEY"])

Scan one file

with open("./invoice.pdf", "rb") as file:
result = detectant.scan(file=("invoice.pdf", file, "application/pdf"))
print(result.verdict, result.detections)

The call completes after the file has been analyzed and returns its scan result.

Scan a batch

Upload between 1 and 20 files. Results are returned in the same order as the inputs.

with open("./invoice.pdf", "rb") as invoice, open("./archive.zip", "rb") as archive:
batch = detectant.scan_batch(files=[
("invoice.pdf", invoice, "application/pdf"),
("archive.zip", archive, "application/zip"),
])
for item in batch.results:
print(item.filename, item.scan.verdict if item.scan else item.error)

Async client

Use AsyncDetectant in an async application:

import os
from detectant import AsyncDetectant
detectant = AsyncDetectant(api_key=os.environ["DETECTANT_API_KEY"])
with open("./invoice.pdf", "rb") as file:
result = await detectant.scan(file=("invoice.pdf", file, "application/pdf"))

Requests retry transient failures twice by default. Configure timeout and max_retries when creating the client.

Source

The SDK is generated with Fern and maintained at Detectant/python-sdk.