Skip to main content

Official Deflect Bot Protection SDK for Python

Project description

Deflect Python SDK

Early Python SDK for the Deflect Bot Protection API (experimental).

Installation

Install PyPi package:

pip install deflect

Quick Start (Sync)

from deflect import Deflect, DeflectOptions

client = Deflect(DeflectOptions(api_key="YOUR_KEY", action_id="YOUR_ACTION"))
verdict = client.get_verdict(user_session_token)
if verdict.get("verdict", {}).get("can_pass"):
    # allow
    ...
else:
    # block
    ...

Quick Start (Async)

import asyncio
from deflect import AsyncDeflect, DeflectOptions

async def main():
    client = AsyncDeflect(DeflectOptions(api_key="YOUR_KEY", action_id="YOUR_ACTION"))
    verdict = await client.get_verdict(user_session_token)
    print(verdict)

asyncio.run(main())

Configuration

DeflectOptions:

  • api_key (str, required)
  • action_id (str, required)
  • base_url (str, default https://api.deflect.bot)
  • timeout (float seconds, default 4.0)
  • max_retries (int, default 2)
  • client / async_client (inject custom httpx client instances)

Errors

Raises DeflectError with attributes:

  • status (int | None)
  • body (parsed JSON or None)

Testing

pytest -q

Roadmap

  • Optional exponential backoff
  • Type refinements when API spec expands
  • Streaming / additional endpoints

License

MIT

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

deflect-0.1.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

deflect-0.1.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file deflect-0.1.0.tar.gz.

File metadata

  • Download URL: deflect-0.1.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for deflect-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f670ac469e3387efdbfcefe447775a759e6eaff79886e9a8a466cfb9d971ac6c
MD5 e53fa108b2f58ee962fa4ecc5123a8b9
BLAKE2b-256 64a88df410ca98eb1aee955d92d20ef17d1bfcff18923451d36eb52ea6c2c63b

See more details on using hashes here.

File details

Details for the file deflect-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: deflect-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for deflect-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 14af92ef70619eb188b7557ea08ed80f14c17219b01b147d98e6304e5148d439
MD5 7e5cafd559e795e4f38d7697ca317c99
BLAKE2b-256 d2be831d350ed86da32a511fd8dc229cf8576aa9f1be4806e9c5e3da577eceaf

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