Skip to main content

Official Deflect 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, VerdictRequest

client = Deflect(DeflectOptions(api_key="YOUR_KEY", action_id="YOUR_ACTION"))
verdict = client.get_verdict(VerdictRequest(
    token=user_session_token,
    # Optional Identity Enrichment
    id="user_123",  # Required for access control
    email="user@example.com",  # Optional email
    phone_number="+14155552671"  # Optional phone number
))
if verdict.get("verdict", {}).get("can_pass"):
    # allow
    ...
else:
    # block
    ...

Quick Start (Async)

import asyncio
from deflect import AsyncDeflect, DeflectOptions, VerdictRequest

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

asyncio.run(main())

Intelligence APIs

Email Intelligence

from deflect import Deflect, DeflectOptions

client = Deflect(DeflectOptions(api_key="YOUR_KEY", action_id="YOUR_ACTION"))
result = client.email_intelligence("user@example.com")

if result.get("success"):
    data = result.get("data", {})
    print(f"Valid: {data.get('is_valid')}")
    print(f"Trusted: {data.get('is_trusted')}")
    print(f"Trust Score: {data.get('trust_score')}")
    print(f"Has Aliasing: {data.get('has_aliasing')}")
    print(f"Normalized: {data.get('normalized_email')}")

Phone Intelligence

from deflect import Deflect, DeflectOptions

client = Deflect(DeflectOptions(api_key="YOUR_KEY", action_id="YOUR_ACTION"))
result = client.phone_intelligence("+14155552671")

if result.get("success"):
    data = result.get("data", {})
    print(f"Valid: {data.get('is_valid')}")
    print(f"Country: {data.get('country_name')}")
    print(f"Carrier: {data.get('carrier')}")
    print(f"Line Type: {data.get('line_type')}")
    print(f"Risk Score: {data.get('risk_score')}")
    print(f"Is Spam: {data.get('is_spam')}")

IP Intelligence

from deflect import Deflect, DeflectOptions

client = Deflect(DeflectOptions(api_key="YOUR_KEY", action_id="YOUR_ACTION"))
result = client.ip_intelligence("8.8.8.8")

if result.get("success"):
    data = result.get("data", {})
    print(f"Is VPN: {data.get('is_vpn')}")
    print(f"Is Proxy: {data.get('is_datacenter_proxy')}")
    print(f"Is Threat: {data.get('is_threat')}")
    print(f"Location: {data.get('city')}, {data.get('country')}")
    print(f"ISP: {data.get('isp')}")

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

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.1.tar.gz (7.1 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.1-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: deflect-0.1.1.tar.gz
  • Upload date:
  • Size: 7.1 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.1.tar.gz
Algorithm Hash digest
SHA256 96f13fea8a7da4b3183c71c220c02991191fe6b81bc215f52005afa398a2a754
MD5 f612fa131778ba6b21932bcbdee8d2f0
BLAKE2b-256 b9955089915334710c496fb01b3bd2bd9ca13d522a9fcc97c51f40324b46829a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: deflect-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 60f81f0efe246df01f75026216e172a75c733da497450569c5dc28e48034245d
MD5 58d5b889d57c6c369dcc22a92eb1e74d
BLAKE2b-256 a282100b59522e55d166a730c803d74311346fce02e9b47764ece879e501834e

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