Mobile integration plugin for Flaxon with Android + iOS support
Project description
Flaxon Mobile
Mobile integration plugin for Flaxon framework with push notifications, device management, and Android native bridge.
Features
- 📱 Device Registration — Register and manage mobile devices
- 🔔 Push Notifications — Firebase Cloud Messaging (FCM) integration
- 📡 Mobile Middleware — Auto-detect mobile clients from headers
- 🤖 Android Native Bridge — On-device Python execution via Chaquopy
- 👤 Device Management — Track devices per user
- 🚀 Pre-built Routes —
/api/mobile/register,/api/mobile/devices, etc. - 🎯 Platform Detection — Auto-detect Android/iOS clients
- 🔐 Decorators —
@mobile_required,@platform_required
Installation
# Basic installation
pip install flaxon-mobile
# With FCM support
pip install flaxon-mobile[fcm]
# With Android native support
pip install flaxon-mobile[android]
# With all features
pip install flaxon-mobile[all]
Quick Start
python
from flaxon import Flaxon
from flaxon_mobile import FlaxonMobilePlugin
app = Flaxon("my-app")
# Load plugin
app.plugins.load_plugin(FlaxonMobilePlugin(
fcm_api_key=os.environ.get("FCM_API_KEY"),
enable_device_middleware=True,
))
# Mobile endpoint
@app.get("/api/hello")
async def hello(request):
mobile_info = request.scope.get("mobile_device", {})
return {
"message": "Hello from Flaxon!",
"is_mobile": mobile_info.get("is_mobile", False),
"platform": mobile_info.get("platform", "unknown"),
}
Configuration
Environment Variables
bash
# FCM API Key
FCM_API_KEY=your-firebase-api-key
# Device settings
MOBILE_DEVICE_EXPIRY_DAYS=30
MOBILE_MAX_DEVICES_PER_USER=5
# Platform settings
MOBILE_SUPPORTED_PLATFORMS=android,ios
With Flaxon Config
python
app = Flaxon("my-app", config={
"FCM_API_KEY": os.environ.get("FCM_API_KEY"),
"MOBILE_DEVICE_EXPIRY_DAYS": 60,
"MOBILE_MAX_DEVICES_PER_USER": 3,
})
plugin = FlaxonMobilePlugin.from_config(app.config)
app.plugins.load_plugin(plugin)
Usage Examples
Device Registration
python
@app.post("/api/mobile/register")
async def register_device(request):
data = await request.json()
device = await app.state.mobile.device_manager.register_device(
user_id=request.user.id,
device_id=data["device_id"],
fcm_token=data["fcm_token"],
platform=data.get("platform", "android"),
app_version=data.get("app_version"),
os_version=data.get("os_version"),
)
return {"success": True, "device": device}
Send Push Notification
python
@app.post("/api/notify")
async def notify(request):
data = await request.json()
success = await app.state.mobile.send_push(
device_id=data["device_id"],
title=data["title"],
body=data["body"],
data={"type": "notification", "timestamp": str(time.time())}
)
return {"success": success}
Mobile-Only Endpoint
python
from flaxon_mobile import mobile_required
@app.get("/api/mobile-only")
@mobile_required
async def mobile_only_endpoint(request):
device_info = request.mobile_device
return {
"message": "This is a mobile-only endpoint",
"device": device_info.to_dict(),
}
Android Native Bridge (On-Device)
python
from flaxon_mobile import AndroidBridge
# Running inside Android app via Chaquopy
android = AndroidBridge()
if android.is_android:
# Get device info
info = android.get_device_info()
print(f"Running on {info['manufacturer']} {info['model']}")
# Show native toast
android.show_toast("Python code running on Android!")
Pre-built Routes
Route Method Description
/api/mobile/register POST Register device
/api/mobile/unregister POST Unregister device
/api/mobile/devices GET Get user devices
/api/mobile/push-token POST Update FCM token
/api/mobile/health GET Mobile service health
Security Best Practices
✅ Always validate device registration
✅ Rate limit device registration endpoints
✅ Encrypt FCM tokens in transit
✅ Rotate FCM API keys regularly
✅ Implement device expiry and cleanup
✅ Authenticate push notification sends
✅ Use HTTPS for all API calls
Roadmap
Version Features
0.1.0 Basic plugin, device registration, middleware
0.2.0 Push notifications (FCM)
0.3.0 Android native bridge (Chaquopy)
0.4.0 iOS support (APNs)
0.5.0 Device management, analytics
0.6.0 Offline sync support
License
MIT License - See LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
flaxon_mobile-0.1.0.tar.gz
(20.6 kB
view details)
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 flaxon_mobile-0.1.0.tar.gz.
File metadata
- Download URL: flaxon_mobile-0.1.0.tar.gz
- Upload date:
- Size: 20.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82c193b0d7acd9f56c07ee39a6994d364d1b075a70a418bc41681d06cd074bf1
|
|
| MD5 |
464e8828e47606a5d7e4f33567424fb3
|
|
| BLAKE2b-256 |
3b17ccff37112856b6e3733b9fcea24538b33f4cc7dbda126963fdbe350d95df
|
File details
Details for the file flaxon_mobile-0.1.0-py3-none-any.whl.
File metadata
- Download URL: flaxon_mobile-0.1.0-py3-none-any.whl
- Upload date:
- Size: 16.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5cd8842f33a92eb19ee55877b3e7797f4d904a0da96212eb0d51018bec4a9f0e
|
|
| MD5 |
e664f6613ee8bfbb16d89f66f59f2d48
|
|
| BLAKE2b-256 |
34cecb667ee26e8756f416e20bea328205b7822a8e28e9923086d2fb25bc5274
|