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

1import os
2from detectant import Detectant
3
4detectant = Detectant(api_key=os.environ["DETECTANT_API_KEY"])

Scan one file

1with open("./invoice.pdf", "rb") as file:
2 result = detectant.scan(file=("invoice.pdf", file, "application/pdf"))
3
4print(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.

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

Async client

Use AsyncDetectant in an async application:

1import os
2from detectant import AsyncDetectant
3
4detectant = AsyncDetectant(api_key=os.environ["DETECTANT_API_KEY"])
5
6with open("./invoice.pdf", "rb") as file:
7 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.