Skip to main content

OPSWAT MetaDefender Cloud Python SDK

Project description

MetaDefender Python SDK

PyPI version License: MIT

Python SDK for MetaDefender Cloud - file scanning, threat detection, and CDR with 20+ anti-malware engines.

Versions

  • API version: 4.0
  • SDK version: 1.0.0

About the API

MetaDefender SDK provides an interface for interacting with MetaDefender Cloud and Core services. It enables file analysis with 20+ anti-malware engines, Deep Content Disarm and Reconstruction (CDR), sandbox analysis, and more.

Key Features of MetaDefender Cloud

  • File Analysis – Scan files using 20+ anti-malware engines
  • Deep CDR – Supports sanitization of 100+ file types
  • Sandbox Analysis – Detects unknown and targeted attacks through dynamic analysis

Maintainer: publish to Test PyPI

Build and upload with a Test PyPI API token (non-interactive):

python -m pip install build twine && python -m build
export TWINE_USERNAME=__token__
export TWINE_PASSWORD=pypi-your-testpypi-token
twine upload --repository-url https://test.pypi.org/legacy/ dist/*

See docs/PUBLISHING.md for details and production PyPI.

Table of Contents

Setup & Configuration

Supported Python Versions

This SDK is compatible with the following versions:

  • Python 3.9 or higher
  • pip package manager

Installation

Install the SDK using pip:

pip install mcl-platform-sdk

Requirements: Python 3.9 or higher

Import name: After install, import the SDK as mcl_platform_sdk:

from mcl_platform_sdk import ApiClient
from mcl_platform_sdk.api.file_scanning_api import FileScanningApi

Authentication

Set your API key as an environment variable:

export METADEFENDER_APIKEY="YOUR_API_KEY_HERE"

The SDK automatically reads from METADEFENDER_APIKEY. Alternatively, pass it directly:

from mcl_platform_sdk import ApiClient

config = ApiClient(api_key="YOUR_API_KEY")

The ApiClient automatically reads the API key from the METADEFENDER_APIKEY environment variable.

Optional parameters (headers options bag)

All SDK methods keep only required path/body parameters in the function signature. All optional request parameters (both HTTP headers and query parameters) are passed via:

  • headers: Optional[Dict[str, Any]] = None

Example:

fs_api.analyze_file(file=data, headers={"filename": "test.pdf", "rule": "sanitize"})

Basic Usage

from mcl_platform_sdk import ApiClient
from mcl_platform_sdk.api.file_scanning_api import FileScanningApi

# Initialize client - reads METADEFENDER_APIKEY automatically
client = ApiClient()
fs_api = FileScanningApi(client)

# Upload and scan file
with open('test.pdf', 'rb') as f:
    upload = fs_api.analyze_file(
        file=f.read(),
        headers={
            "filename": "test.pdf",
            "rule": "sanitize",
        }
    )

# Poll for results with automatic timeout (configured via headers)
try:
    result = fs_api.get_file_analysis(
        upload.data_id,
        headers={
            "timeout": 60,
            "poll_interval": 2,  # seconds (optional)
        },
    )
    print('Scan result:', result.scan_results.scan_all_result_a)
except TimeoutError:
    print('Scan failed to complete in 60 seconds')

API Services

File Scanning

from mcl_platform_sdk.api.file_scanning_api import FileScanningApi

fs_api = FileScanningApi(client)

# Upload file
with open('file.pdf', 'rb') as f:
    upload = fs_api.analyze_file(
        file=f.read(),
        headers={
            "filename": "file.pdf",
            "rule": "sanitize",  # Options: multiscan, sanitize, cdr, unarchive, dlp
        }
    )

# Poll for scan completion (recommended)
try:
    result = fs_api.get_file_analysis(upload.data_id, headers={"timeout": 60})
    print('Scan completed:', result.scan_results.scan_all_result_a)
except TimeoutError:
    print('Scan failed to complete in 60 seconds')

Data Sanitization (CDR)

from mcl_platform_sdk.api.data_sanitization_cdr_api import DataSanitizationCDRApi

cdr_api = DataSanitizationCDRApi(client)

# Get sanitized file URL
sanitized = cdr_api.file_sanitized(data_id)
print('Download URL:', sanitized.sanitized_file_path)

# Cleanup
cdr_api.file_converted_data_id_delete(data_id)

Hash Lookups

from mcl_platform_sdk.api.hash_lookups_api import HashLookupsApi

hash_api = HashLookupsApi(client)
result = hash_api.hash_lookup('640CCA22FBF439406BA200EEFB9C52BE87BC97D6')
print('Hash lookup result:', result)

Reputation Service

from mcl_platform_sdk.api.reputation_service_api import ReputationServiceApi

rep_api = ReputationServiceApi(client)

# Check IP, domain, or URL reputation
ip_rep = rep_api.i_p_lookup(observable_ip='198.15.127.171')
domain_rep = rep_api.domain_lookup(observable_domain='example.com')
url_rep = rep_api.url_lookup(observable_url='http://suspicious-url.com')

Dynamic Analysis (Sandbox)

from mcl_platform_sdk.api.dynamic_analysis_api import DynamicAnalysisApi

sandbox_api = DynamicAnalysisApi(client)
sandbox_res = sandbox_api.sandbox_lookup(sandbox_id)
print('Verdict:', sandbox_res.final_verdict)

API Key Management

from mcl_platform_sdk.api.apikey_api import ApikeyApi

apikey_api = ApikeyApi(client)

# Get API key info
info = apikey_api.get_api_key()
print('Nickname:', info.nickname)

# Check limits
limits = apikey_api.apikey_limits()
remaining = apikey_api.apikey_limits_status_get()
history = apikey_api.apikey_scan_history_get()

Error Handling

from mcl_platform_sdk.rest import ApiException

try:
    result = fs_api.get_file_analysis(data_id)
except ApiException as e:
    print('Status:', e.status)
    print('Details:', e.body)
except TimeoutError as e:
    print('Timeout:', e)
except Exception as e:
    print('Error:', e)

Example Workflow

The SDK includes a comprehensive example script. After installation:

# Set your API key
export METADEFENDER_APIKEY="YOUR_API_KEY"

# Run the example workflow
python -m exemples.exemple_all_workflows

The example demonstrates:

  • API key validation
  • File upload and scanning
  • Polling for results
  • Sanitized file retrieval
  • Hash lookups
  • IP/Domain/URL reputation checks

For maintainers: build and publish

To build the package and publish to PyPI, see docs/PUBLISHING.md for the full build and deploy process.

To regenerate the client from OpenAPI Generator, use packageName=mcl_platform_sdk . See docs/REGENERATING_CLIENT.md.

License

MIT License - see LICENSE.md for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcl_platform_sdk-1.0.0.tar.gz (162.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcl_platform_sdk-1.0.0-py3-none-any.whl (658.4 kB view details)

Uploaded Python 3

File details

Details for the file mcl_platform_sdk-1.0.0.tar.gz.

File metadata

  • Download URL: mcl_platform_sdk-1.0.0.tar.gz
  • Upload date:
  • Size: 162.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for mcl_platform_sdk-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ede079d7acc710bef172e7963edb60bc6a3b8d56fbc62d0a6fa023214e6948a5
MD5 65d95f333d60ab4043ec48bb625c1c27
BLAKE2b-256 9d507688f7727ab32a21575819c43578b1c69730845430fc0e450306b13f9339

See more details on using hashes here.

File details

Details for the file mcl_platform_sdk-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mcl_platform_sdk-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cb22fcc95815365aa733a6b5da86c44130a4cc58b5c3bd8d3c2504d36c9da7ab
MD5 70351263afeb6fa4cfd4588e707efccb
BLAKE2b-256 e1bdd700244192ee9f03980e703f9d699f8e2f4795f64d4580f1d1269c879765

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page