Flaxon Mobile
Mobile integration plugin for Flaxon framework with push notifications, device management, and Android native bridge.
Table of Contents
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
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
# 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
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
@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
@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
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)
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.
Metadata
Release files for flaxon-mobile 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| flaxon_mobile-0.1.1.tar.gz | 21.4 kB | Without provenance | Details for flaxon_mobile-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flaxon_mobile-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for flaxon_mobile-0.1.1-py3-none-any.whl |
Total release size: 38.7 kB
Release files / flaxon_mobile-0.1.1.tar.gz
| Download URL | flaxon_mobile-0.1.1.tar.gz |
|---|---|
| Size | 21.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1a2e41e03100285535adb0c2da9e9812436205f3996ba8d4a83f22bae831d160
|
|
BLAKE2b-256 checksum How to use checksums |
4ae32b91faae3c637b5d7990d2e133b68b410bf9525ff90c94c77f751378599d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.3
|
Release files / flaxon_mobile-0.1.1-py3-none-any.whl
| Download URL | flaxon_mobile-0.1.1-py3-none-any.whl |
|---|---|
| Size | 17.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fae84501236db5e890dea9f074b6ae39027f48f47bad37fd5487a88f6b988a36
|
|
BLAKE2b-256 checksum How to use checksums |
2e80f4b141a296f85093d5a86a6d05a7d8c6774c5065293e0d7188ee1957c6ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.3
|
Security for flaxon-mobile 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.