Skip to main content

Zero-dependency Python SDK for the Scanii content security API

Project description

scanii-python

Python SDK for the Scanii content security API.

Installation

pip install scanii-python

Distribution name is scanii-python; import as from scanii import ScaniiClient.

SDK Principles

  1. Light. Zero runtime dependencies, stdlib only.
  2. Up to date. Always current with the latest Scanii API.
  3. Integration-only. Wraps the REST API — retries, concurrency, and batching are the caller's responsibility.

Quickstart

from scanii import ScaniiClient, ScaniiTarget

client = ScaniiClient(key="your-key", secret="your-secret", target=ScaniiTarget.US1)
result = client.process_file("./document.pdf")
print(result.findings)  # [] when clean

Streaming

Pass any IO-like object (anything with read(n) -> bytes) to process() directly — no temp file needed:

import io

# Scan bytes already in memory
result = client.process(io.BytesIO(my_bytes), filename="upload.bin")

# Scan content from an open file handle
with open("./large.pdf", "rb") as f:
    result = client.process(f, filename="large.pdf")

API Reference

Constructor

ScaniiClient(
    *,
    key: str | None = None,
    secret: str | None = None,
    token: str | None = None,
    target: ScaniiTarget,
    timeout: float = 60.0,
)

Supply either key + secret (HTTP Basic Auth) or token (auth-token authentication). Mixing both raises ValueError. target is required — see Regional Endpoints.

File scanning

Method Description
process(content, filename, content_type=None, metadata=None, callback=None) Synchronous scan of an IO-like object
process_file(path, metadata=None, callback=None) Synchronous scan of a file on disk
process_async(content, filename, content_type=None, metadata=None, callback=None) Async-on-server scan of an IO-like object; returns ScaniiPendingResult
process_async_file(path, metadata=None, callback=None) Async-on-server scan of a file on disk; returns ScaniiPendingResult
retrieve(id) Retrieve a previous scan result
fetch(url, metadata=None, callback=None) Server-side async fetch-and-scan of a remote URL

v2.2 preview methods

Method Description
retrieve_trace(id) (v2.2 preview) Retrieve processing event trace; returns None on 404
process_from_url(location, callback=None, metadata=None) (v2.2 preview) Synchronous scan of a remote URL via POST /files

Auth tokens

Method Description
create_auth_token(timeout_seconds) Mint a short-lived token
retrieve_auth_token(id) Inspect a token
delete_auth_token(id) Revoke a token

Health check

Method Description
ping() Returns True when the API is reachable with valid credentials

Regional Endpoints

Choose a regional target explicitly. Six regional constants are available: US1, EU1, EU2, AP1, AP2, CA1. Latency-based routing (AUTO in other Scanii SDKs) is intentionally not provided — chain-of-custody and data-residency compliance require an explicit regional choice. For local testing against scanii-cli, construct a target with an arbitrary URL: ScaniiTarget("http://localhost:4000").

Constant URL Location
ScaniiTarget.US1 https://api-us1.scanii.com Virginia, USA
ScaniiTarget.EU1 https://api-eu1.scanii.com Dublin, Ireland
ScaniiTarget.EU2 https://api-eu2.scanii.com London, United Kingdom
ScaniiTarget.AP1 https://api-ap1.scanii.com Sydney, Australia
ScaniiTarget.AP2 https://api-ap2.scanii.com Singapore
ScaniiTarget.CA1 https://api-ca1.scanii.com Montreal, Canada
client = ScaniiClient(key="your-key", secret="your-secret", target=ScaniiTarget.EU1)

Error Handling

from scanii import ScaniiClient, ScaniiTarget, ScaniiError, ScaniiAuthError, ScaniiRateLimitError
import time

client = ScaniiClient(key="your-key", secret="your-secret", target=ScaniiTarget.US1)

try:
    result = client.process_file("./document.pdf")
except ScaniiAuthError:
    print("Invalid credentials")
except ScaniiRateLimitError as e:
    if e.retry_after:
        time.sleep(e.retry_after)
except ScaniiError as e:
    print(f"API error {e.status_code}: {e}")

Network-level failures (urllib.error.URLError) propagate unwrapped — retries are the caller's responsibility per SDK Principle 3.

Local Testing with scanii-cli

All integration tests run against a locally-hosted scanii-cli mock server — no real credentials needed.

docker run -d --name scanii-cli -p 4000:4000 ghcr.io/scanii/scanii-cli:latest server

# Run tests
pip install -e ".[dev]"
pytest
client = ScaniiClient(key="key", secret="secret", target=ScaniiTarget("http://localhost:4000"))
result = client.ping()  # True

Contributing

Pull requests welcome. Please open an issue first for substantial changes.

License

Apache 2.0 — see LICENSE.

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

scanii_python-1.0.0.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

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

scanii_python-1.0.0-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: scanii_python-1.0.0.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for scanii_python-1.0.0.tar.gz
Algorithm Hash digest
SHA256 39840e1fda9088ca979fb08864c4eecfc5f1940c47b826ed8a188b232b65a116
MD5 e35f05aee640b3b22a6566b3de259608
BLAKE2b-256 2b735c485ada8c1274ea3d09034ca5ff0143848b4cf91d991195e84574a2a827

See more details on using hashes here.

Provenance

The following attestation bundles were made for scanii_python-1.0.0.tar.gz:

Publisher: release.yml on scanii/scanii-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: scanii_python-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for scanii_python-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c52f35403b9346df1c254fff02428f2679483c12461a531a40a794d9c8461017
MD5 dd61bcc561633cf31604139b2d6fedc8
BLAKE2b-256 d8b78b11c23c2b5072ff9cc71ca9612f5120a09be4ead752ee3d3ca194bb5da6

See more details on using hashes here.

Provenance

The following attestation bundles were made for scanii_python-1.0.0-py3-none-any.whl:

Publisher: release.yml on scanii/scanii-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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