Skip to main content

Stop fraud with one line of code

Project description

Truslyo Python SDK

Stop fraud with one line of code.

Installation

pip install trusylo

Quick Start

Basic Usage

from trusylo import TruslyoClient

client = TruslyoClient(api_key="sk_live_abc123")

result = client.check(
    token="eyJ...",  # Token from Truslyo.js
    email="user@example.com",
    ip_address="192.168.1.1"
)

if result.should_block():
    raise Exception("Fraud detected!")

Flask Decorator

from flask import Flask, request
from trusylo import trusylo_protect

app = Flask(__name__)

@app.post("/signup")
@trusylo_protect(api_key="sk_live_abc123")
def signup():
    # Your code here
    return {"success": True}

FastAPI Middleware

from fastapi import FastAPI
from trusylo import TruslyoMiddleware

app = FastAPI()

app.add_middleware(
    TruslyoMiddleware,
    api_key="sk_live_abc123",
    protected_routes=["/signup", "/checkout"]
)

Django Middleware

# settings.py
MIDDLEWARE = [
    'trusylo.middleware.DjangoTruslyoMiddleware',
    # ... other middleware
]

TRUSLYO_API_KEY = "sk_live_abc123"
TRUSLYO_PROTECTED_ROUTES = ["/signup", "/checkout"]

Features

  • One-line protection - Decorator-based fraud detection
  • Framework support - Flask, FastAPI, Django, Starlette
  • Automatic enrichment - IP intelligence, email validation
  • Configurable blocking - Control when to block vs review
  • Fail-safe - Configurable fail-open behavior
  • Type hints - Full type annotation support

API Reference

TruslyoClient

client = TruslyoClient(
    api_key="sk_live_abc123",
    base_url="https://api.trusylo.com",  # Optional
    timeout=5  # Optional, seconds
)

FraudCheckResult

result = client.check(token="...")

# Decision methods
result.should_block()    # True if fraud detected
result.should_review()   # True if manual review needed
result.is_approved()     # True if approved

# Properties
result.decision          # "approve", "block", or "review"
result.risk_score        # 0.0 to 1.0
result.reasons           # List of reasons
result.fraud_patterns    # Detected fraud patterns
result.session_id        # Session identifier

Configuration

Decorator Options

@trusylo_protect(
    api_key="sk_live_abc123",
    block_on_fraud=True,      # Block when fraud detected
    block_on_review=False,    # Don't block reviews
    fail_open=True,           # Continue if API fails
    custom_handler=my_handler # Custom callback
)

Custom Handler

def my_fraud_handler(result, request):
    if result.should_block():
        # Log to your system
        logger.warning(f"Fraud blocked: {result.get_summary()}")
        # Send alert
        send_alert(result)

@app.post("/signup")
@trusylo_protect(
    api_key="sk_live_abc123",
    custom_handler=my_fraud_handler
)
def signup():
    return {"success": True}

Error Handling

from trusylo import (
    TruslyoError,
    FraudDetectedError,
    InvalidTokenError,
    APIError,
    RateLimitError
)

try:
    result = client.check(token="...")
except InvalidTokenError:
    return {"error": "Invalid or expired token"}
except RateLimitError:
    return {"error": "Rate limit exceeded"}
except APIError as e:
    return {"error": f"API error: {str(e)}"}

Requirements

  • Python 3.7+
  • requests >= 2.25.0

License

MIT License

Support


#### **`LICENSE`** (MIT License)

MIT License

Copyright (c) 2024 Truslyo

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


#### **`MANIFEST.in`**

include README.md include LICENSE recursive-include trusylo *.py

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

trusylo-1.0.3.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

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

trusylo-1.0.3-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file trusylo-1.0.3.tar.gz.

File metadata

  • Download URL: trusylo-1.0.3.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for trusylo-1.0.3.tar.gz
Algorithm Hash digest
SHA256 0a977ec9b2432c9be4585c74ccead78fd4a447eba0aa09a8a6b46664db898487
MD5 851a813c32aa5194a4a69accbb2c5b2c
BLAKE2b-256 db88c174bb706b08f98940daf4b45ff7bebaa7e77ad5387eb3ab9b1a8c74bdae

See more details on using hashes here.

File details

Details for the file trusylo-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: trusylo-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for trusylo-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 387fd05e856f7b2233c2ffa3597e98347e98f59a7c95049f621d7047374d061c
MD5 c184d95844839db3d1c43866bf9c5e3e
BLAKE2b-256 d0afba70bd0fc4290cf8461fa6a271adda294b2e94c4b991ebdd63a0b78e40cc

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