Metadata-Version: 2.1
Name: detectant-sdk
Version: 1.0.0
Summary: 
License: MIT
Keywords: malware,security,file-scanning
Requires-Python: >=3.10,<4.0
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: OS Independent
Classifier: Operating System :: POSIX
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Provides-Extra: aiohttp
Requires-Dist: aiohttp (>=3.14.1,<4) ; (python_version >= "3.10") and (extra == "aiohttp")
Requires-Dist: httpx (>=0.21.2)
Requires-Dist: httpx-aiohttp (>=0.1.8,<0.2.0) ; (python_version >= "3.10") and (extra == "aiohttp")
Requires-Dist: pydantic (>=1.9.2)
Requires-Dist: pydantic-core (>=2.18.2,<3.0.0)
Requires-Dist: typing_extensions (>=4.0.0)
Project-URL: Documentation, https://docs.detectant.com/sdks/python
Project-URL: Homepage, https://www.detectant.com
Project-URL: Repository, https://github.com/Detectant/python-sdk
Description-Content-Type: text/markdown

<p align="center">
  <img src="https://www.detectant.com/images/detectant-github-banner.png" alt="Detectant" width="100%">
</p>

# 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"])
```

By default, requests are sent to `https://api.detectant.com`.

## 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.

### Supported file inputs

The SDK accepts open binary files, bytes, strings, and tuples containing a filename, content, content type, and optional headers.

```python
# An open binary file
with open("./invoice.pdf", "rb") as file:
    detectant.scan(file=("invoice.pdf", file, "application/pdf"))

# Bytes already in memory
result = detectant.scan(
    file=("invoice.pdf", file_bytes, "application/pdf"),
)
```

## 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:
    if item.scan is not None:
        print(item.filename, item.scan.verdict)
    else:
        print(item.filename, item.error)
```

One file can fail without preventing the other files in the batch from being scanned.

## Async client

```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"),
    )
```

## Configuration

Increase the timeout for large files or change the default retry count when needed:

```python
detectant = Detectant(
    api_key=os.environ["DETECTANT_API_KEY"],
    timeout=120,
    max_retries=3,
)
```

See the [Detectant documentation](https://docs.detectant.com/sdks/python) for the complete guide.

