> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.detectant.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.detectant.com/_mcp/server.

![Detectant](https://www.detectant.com/images/detectant-github-banner.png)

# Detectant Python SDK

[Detectant is a malware scanning API with support for Python](https://www.detectant.com)

Scan files for malware from synchronous or asynchronous Python applications.

## Install

```bash
pip install detectant-sdk
```

Set your API key in the environment:

```bash
export DETECTANT_API_KEY="your-api-key"
```

## Create a client

```python
import os
from detectant import Detectant

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

## Scan one file

```python
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.

```python
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:

```python
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](https://github.com/Detectant/python-sdk).