Official Fourbyfour SDK for Python
Project description
fourbyfour
Official Python SDK for Fourbyfour - Revenue workflows on autopilot.
Installation
pip install fourbyfour
Setup
1. Get your credentials
Get your API key and Project ID from fourbyfour.dev.
2. Configure environment variables
# .env
FOURBYFOUR_API_KEY=sk_live_...
FOURBYFOUR_PROJECT_ID=proj_...
3. Initialize the SDK
Add the SDK initialization in your app:
FastAPI (app/lib/fourbyfour.py):
import os
from fourbyfour import saas
fbf = saas(
api_key=os.environ["FOURBYFOUR_API_KEY"],
project_id=os.environ["FOURBYFOUR_PROJECT_ID"]
)
Django (myapp/fourbyfour.py):
import os
from fourbyfour import saas
fbf = saas(
api_key=os.environ["FOURBYFOUR_API_KEY"],
project_id=os.environ["FOURBYFOUR_PROJECT_ID"]
)
Flask (app/fourbyfour.py):
import os
from fourbyfour import saas
fbf = saas(
api_key=os.environ["FOURBYFOUR_API_KEY"],
project_id=os.environ["FOURBYFOUR_PROJECT_ID"]
)
4. Track your first event
from app.lib.fourbyfour import fbf
# In your payment handler, API route, or service
fbf.track("payment.failed", {
"user_id": user.id,
"amount": invoice.amount,
"currency": "USD",
"plan": subscription.plan,
"subscription_id": subscription.id,
"billing_cycle": "monthly"
})
Verticals
Choose the client that matches your business:
from fourbyfour import saas, ecommerce, fintech, edtech, games, apps
# SaaS - trials, subscriptions, usage
fbf = saas(api_key="...", project_id="...")
# E-commerce - carts, orders, shipping
fbf = ecommerce(api_key="...", project_id="...")
# Fintech - transactions, payments, KYC
fbf = fintech(api_key="...", project_id="...")
# EdTech - courses, lessons, certificates
fbf = edtech(api_key="...", project_id="...")
# Games - levels, achievements, streaks
fbf = games(api_key="...", project_id="...")
# Apps - trials, subscriptions, milestones
fbf = apps(api_key="...", project_id="...")
Common Events
SaaS
# Trial lifecycle
fbf.track("trial.started", {"user_id": "u_123", "plan": "Pro", "trial_days": 14})
fbf.track("trial.ending", {"user_id": "u_123", "plan": "Pro", "days_remaining": 3})
# Subscriptions
fbf.track("subscription.canceled", {"user_id": "u_123", "plan": "Pro", "reason": "too_expensive"})
fbf.track("subscription.upgraded", {"user_id": "u_123", "from_plan": "Starter", "to_plan": "Pro"})
# Usage
fbf.track("usage.threshold", {"user_id": "u_123", "metric": "api_calls", "current": 9500, "limit": 10000})
# Payment
fbf.track("payment.failed", {"user_id": "u_123", "amount": 99.0, "currency": "USD", "plan": "Pro"})
E-commerce
fbf.track("cart.abandoned", {
"user_id": "u_123",
"cart_id": "cart_456",
"items": [{"product_id": "prod_1", "name": "Shirt", "quantity": 2, "price": 29.99}],
"total_value": 59.98
})
fbf.track("order.placed", {"user_id": "u_123", "order_id": "ord_789", "total_value": 150.0})
fbf.track("order.shipped", {"user_id": "u_123", "order_id": "ord_789", "tracking_number": "TRK123"})
User Context
Send user context to help optimize delivery timing and channels:
fbf.notify({
"user_id": "u_123",
"timezone": "Asia/Kolkata",
"tier": "premium",
"preferred_channel": "email"
})
Type Hints
Full type hint support with all events:
from fourbyfour import saas, SaaSClient, TrackResult
fbf: SaaSClient = saas(api_key="...", project_id="...")
result: TrackResult = fbf.track("trial.started", {
"user_id": "u_123",
"plan": "Pro",
"trial_days": 14
})
Error Handling
from fourbyfour import saas, FourbyfourError, AuthenticationError, RateLimitError
fbf = saas(api_key="...", project_id="...")
try:
fbf.track("payment.failed", {"user_id": "u_123", "amount": 99.0})
except AuthenticationError:
print("Invalid API key")
except RateLimitError:
print("Rate limit exceeded, retry later")
except FourbyfourError as e:
print(f"API error: {e}")
Documentation
See fourbyfour.dev/docs for full documentation.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fourbyfour-0.1.4.tar.gz.
File metadata
- Download URL: fourbyfour-0.1.4.tar.gz
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a7283b0a76fa0aed8450e32ab7cabb7d87334855c675f13aae8736b6b395bf2
|
|
| MD5 |
c50ced3927d4b0b3e0af7fdd6b3fe269
|
|
| BLAKE2b-256 |
35dfe5d55cbba4b1a910f78bbdab2586bedd8f20bb701c273e3c36a6c1384a81
|
File details
Details for the file fourbyfour-0.1.4-py3-none-any.whl.
File metadata
- Download URL: fourbyfour-0.1.4-py3-none-any.whl
- Upload date:
- Size: 21.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8082eee850a399283024cc71b3b08246aec399ef44bf3368217f5c3467c3c631
|
|
| MD5 |
3547953d1d2fc6fdb4ab4bbf9e8dfc0b
|
|
| BLAKE2b-256 |
b64ffaa804c3bab15ec53e8df02414f827f16107d01c238c03c45c3f5b28f779
|