Privy is an open-source fraud detection and risk scoring API service inspired by SignupGate.
It provides real-time risk assessment for user signups, email validation, IP reputation checking, and abuse detection to help protect your applications from fraudulent users.
- π‘οΈ Real-time Risk Scoring β Instant fraud detection with configurable scoring
- π§ Email Validation β Disposable email detection (10,000+ domains) and pattern analysis
- π IP Intelligence β VPN, Tor, proxy detection with geolocation analysis
- π Geolocation Analysis β High-risk country detection and ISP analysis
- π API Key Management β Secure authentication with per-organization API keys
- β‘ Rate Limiting β Token bucket rate limiting with Redis backend
- π Analytics & Logging β Comprehensive check logging and analytics
- π« Custom Blacklists β Organization-specific IP, email, and domain blocking
- π Background Processing β Async data ingestion with Celery workers
- π€ Automated Data Updates β Automatic updates of fraud detection databases
- π Detailed Reporting β Risk explanations and actionable recommendations
Built with:
- β‘ FastAPI β High-performance async Python API framework
- π PostgreSQL β Primary database for persistent data
- π΄ Redis β Caching, rate limiting, and fast lookups
- π¦ SQLModel β Modern ORM with Pydantic integration
- π Alembic β Database migration management
- πΏ Celery β Distributed task queue for background jobs
- π³ Docker β Containerized deployment
backend/
βββ app/
β βββ __init__.py
β βββ main.py # FastAPI application entry point
β βββ config.py # Configuration and environment variables
β βββ db.py # Database connection and session management
β βββ models.py # SQLModel database models
β βββ crud.py # Database CRUD operations
β βββ api/
β β βββ deps.py # API dependencies (auth, validation)
β β βββ routes.py # API route handlers
β βββ services/
β β βββ scoring.py # Risk scoring algorithms
β β βββ rate_limiter.py # Rate limiting implementation
β βββ workers/
β βββ celery_app.py # Celery configuration
β βββ tasks.py # Background task definitions
βββ migrations/ # Alembic database migrations
βββ tests/ # Test suite
βββ requirements.txt # Python dependencies
βββ alembic.ini # Alembic configuration
βββ docker-compose.yml # Development environment
βββ Dockerfile # Container definition
βββ .env # Environment variables
git clone https://github.com/akshaynstack/privy.git
cd privy/backend# Copy environment template
cp .env.template .env
# Edit .env with your configuration
# Start all services
docker-compose up --build# Create virtual environment
python -m venv .venv
source .venv/bin/activate # Linux/Mac
.venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txt
# Setup environment variables
cp .env.template .env
# Edit .env with your database and Redis URLs
# Run database migrations
alembic upgrade head
# Start the API server
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
# In separate terminals, start Redis and Celery worker:
redis-server
celery -A app.workers.celery_app.celery_app worker --loglevel=info# Test the API
curl -X POST "http://localhost:8000/v1/check" \
-H "X-API-Key: your-api-key" \
-H "Content-Type: application/json" \
-d '{"email": "test@example.com", "ip": "1.2.3.4"}'Base URL: http://localhost:8000
POST /v1/checkPerform real-time fraud detection check
Headers:
X-API-Key: {key_id}.{secret}(required)Content-Type: application/json
Request Body:
{
"email": "user@example.com",
"ip": "192.168.1.1",
"user_agent": "Mozilla/5.0...",
"metadata": {
"custom_field": "value"
}
}Response:
{
"success": true,
"data": {
"risk_score": 25,
"risk_level": "low",
"reasons": ["disposable_email"]
}
}- none (0-29): Safe to proceed
- low (30-59): Monitor closely
- medium (60-79): Challenge user (CAPTCHA, 2FA)
- high (80-100): Block or manual review
- Default: 60 requests per minute per API key
- Burst: Up to 60 tokens in bucket
- Refill: 1 token per second
401- Invalid or missing API key429- Rate limit exceeded422- Invalid request payload500- Internal server error
- Multi-tenant organization support
- Email-based authentication
- Automatic UUID generation
- API key scoping
- Custom blacklist management
- Usage analytics
- Secure key generation with public ID + secret
- bcrypt hashed secrets
- Revocation support
- Complete request logging
- Risk score tracking
- JSON metadata storage
- IP addresses, email domains, ISPs, ASNs
- Organization-specific rules
- Reason tracking
- β Disposable email detection (10,000+ domains)
- β Domain reputation scoring
- β Custom domain blacklists
- π Real-time email validation
- β VPN/Proxy detection
- β Tor exit node identification
- β Geolocation analysis
- β ISP reputation scoring
- π Multiple signups from same IP detection
- β Rate limiting per API key
- β Request pattern analysis
- π Device fingerprinting
- π Time-based anomaly detection
- β Organization blacklists
- β Configurable scoring weights
- π Machine learning integration
- π Custom webhook triggers
Legend: β Implemented | π Planned
- β Core fraud detection API
- β Basic email and IP checks
- β Rate limiting and API keys
- β Docker deployment
- π Web dashboard for analytics
- π Advanced ML-based scoring
- π Webhook notifications
- π Bulk data ingestion APIs
- π Device fingerprinting
- π Behavioral analytics
- π Enterprise SSO integration
- π Custom rule engine UI
# Database
DATABASE_URL=postgresql+asyncpg://user:pass@localhost:5432/privy
DATABASE_URL_SYNC=postgresql://user:pass@localhost:5432/privy
# Redis
REDIS_URL=redis://localhost:6379
# Celery
CELERY_BROKER=redis://localhost:6379/0
CELERY_BACKEND=redis://localhost:6379/1
# API
API_HOST=0.0.0.0
API_PORT=8000
DEBUG=true
# Optional: External data sources
DISPOSABLE_EMAIL_URL=https://raw.githubusercontent.com/disposable/disposable-email-domains/master/domains.txtCustomize risk scoring weights in app/services/scoring.py:
WEIGHTS = {
"disposable_email": 70,
"vpn_ip": 60,
"tor_exit": 80,
"bad_isp": 40,
"multiple_from_ip": 30,
"custom_blacklist": 100,
}# Run all tests
pytest
# Run with coverage
pytest --cov=app tests/
# Run specific test file
pytest tests/test_scoring.py -v# Build production image
docker build -t privy-api .
# Run with production settings
docker run -p 8000:8000 --env-file .env.prod privy-api- Set up PostgreSQL and Redis
- Configure production environment variables
- Run database migrations:
alembic upgrade head - Start API server:
gunicorn app.main:app -w 4 -k uvicorn.workers.UvicornWorker - Start Celery worker:
celery -A app.workers.celery_app.celery_app worker
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Please read our Code of Conduct and Security Policy.
This project is licensed under the MIT License - see the LICENSE file for details.
If you find this project useful, please consider:
- β Starring the repository
- π Reporting bugs and issues
- π‘ Suggesting new features
- π€ Contributing code improvements
- π’ Sharing with others who might benefit
For support:
- π Check the documentation and setup guide
- π Report bugs via GitHub Issues
- π¬ Join discussions in GitHub Discussions
- π Report security issues via our Security Policy
Built with β€οΈ for developers who want to protect their applications from fraud.