Skip to main content

Flaxon Mobile

Flaxon Logo

PyPI version License: MIT Code style: ruff

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.

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.1.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

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

flaxon_mobile-0.1.1-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file flaxon_mobile-0.1.1.tar.gz.

File metadata

  • Download URL: flaxon_mobile-0.1.1.tar.gz
  • Upload date:
  • Size: 21.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.3

File hashes

Hashes for flaxon_mobile-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1a2e41e03100285535adb0c2da9e9812436205f3996ba8d4a83f22bae831d160
MD5 981b2483f42eea88c6d9ef76eb96f2f0
BLAKE2b-256 4ae32b91faae3c637b5d7990d2e133b68b410bf9525ff90c94c77f751378599d

See more details on using hashes here.

File details

Details for the file flaxon_mobile-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: flaxon_mobile-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.3

File hashes

Hashes for flaxon_mobile-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fae84501236db5e890dea9f074b6ae39027f48f47bad37fd5487a88f6b988a36
MD5 78617f961da91e8e23adf973a7a7e980
BLAKE2b-256 2e80f4b141a296f85093d5a86a6d05a7d8c6774c5065293e0d7188ee1957c6ef

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page