packages

Sharing

Shows the system share sheet so users can send content to other apps. Share.share takes files, links and a message, like React Native's Share. Sharing.shareAsync shares one local file, like expo-sharing.

  • pyxpo-sharing
  • v0.1.0a1
  • Native: Swift + Kotlin
  • Like expo-sharing and React Native Share

Install

Install the package into the same environment as pyxpo.

$pip install pyxpo-sharing

Add sharing to modules in your app config, then import it in your code.

pyproject.toml
[tool.pyxpo]
modules = ["sharing"]
python
from pyxpo_sharing import Share, Sharing

This module has native code. After you add it, run pyxpo run or pyxpo build again so it is compiled into the app. Hot reload alone is not enough.

Platforms

iOSUIActivityViewController
AndroidIntent chooser with a FileProvider
Desktop previewNeeds a simulator or device

Quick start

app/index.py
from pyxpo_sharing import Share

async def share_photo(uri):
    res = await Share.share({"url": uri, "message": "Look at this"})
    return res["action"]   # "sharedAction" or "dismissedAction"

Permissions

pyxpo adds these to Info.plist and AndroidManifest.xml for you when the module is listed.

iOSNone.
AndroidNone. The module declares its own FileProvider.

API reference

Share

await Share.share(content, options=None)→ {"action"}

content is {"url": ...} or {"urls": [...]}, with an optional "message". Local paths are shared as files. http and https links are added to the message. options: {"dialogTitle"} (Android).

Sharing

snake_case names also work: share_async, is_available_async.

await Sharing.isAvailableAsync()→ bool

True when the module is linked.

await Sharing.shareAsync(url, options=None)→ None

Shares one local file. A web link raises ValueError. options: mimeType, dialogTitle (Android).

Examples

Share several files

Send all edited photos in one share sheet.

python
from pyxpo_sharing import Share

async def share_all(uris):
    await Share.share({"urls": uris, "message": "Edited with my app"},
                      {"dialogTitle": "Send photos"})

Share a generated file

Write a file, then hand it to another app.

python
from pyxpo_file_system import File, Paths
from pyxpo_sharing import Sharing

async def export_csv(rows):
    f = File(Paths.cache, "export.csv")
    f.write("\n".join(",".join(map(str, r)) for r in rows))
    if await Sharing.isAvailableAsync():
        await Sharing.shareAsync(f.uri, {"mimeType": "text/csv"})

Good to know

  • Android always reports "sharedAction", because the system does not say whether the user finished.
  • On Android, files are shared from the app's cache and files folders.