Skip to main content

Cross-platform, file handler using native pickers and security models.

Project description

xfilepy


Cross-platform, file handler using native pickers and security models.

Provides overloads for creating file handlers via native file pickers and saving/loading persistent access grants. Supported platforms are Android, iOS, and Desktop (Windows, macOS, Linux, BSDs). On all platforms you can choose files outside your app's sandbox using the native file picker without asking the user for broad filesystem permissions. Access to the chosen files is mediated by platform-specific security models (e.g., SAF on Android, security-scoped bookmarks on iOS, xdg-desktop-portal (if available) on linux). This allows your app to write to the files later without re-prompting the user, even across app restarts.

Usage

See API Documentation for full details. Here is a brief example:

import asyncio

from xfilepy import FileHandler, UserCancelledError

# Open via native picker
try:  # The user may cancel the picker, so we catch that exception
    fh = asyncio.run(FileHandler.create_via_picker())
    with fh.open() as f:
        data = f.read()
        print(data)
except UserCancelledError:
    print("User cancelled the file picker.")

# Save via native "Save as…"
fh = asyncio.run(FileHandler.create_via_save_dialog())
with fh.open(mode="w", encoding="utf-8") as f:
    f.write("Hello, world!")

# Serialize back to store in your settings
persist = fh.to_uri_string()
if persist is None:
    raise RuntimeError("This file handler cannot be persisted.")

# Rehydrate a previously granted URI/bookmark
fh = FileHandler.from_uri_string(persist, require_write=True)
with fh.open(mode="a") as f:
    f.write("Appended line.")

# Best-effort metadata, useful for cache invalidation
stat = fh.stat()
print(stat.display_name, stat.size, stat.mtime_ns)

FileHandler.stat() returns metadata when the platform/provider exposes it. Fields such as size and mtime_ns may be None, especially for document providers on mobile. If you need a reliable content fingerprint, hash the stream returned by open("rb").

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

xfilepy-0.5.1.tar.gz (28.2 kB view details)

Uploaded Source

Built Distribution

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

xfilepy-0.5.1-py3-none-any.whl (32.5 kB view details)

Uploaded Python 3

File details

Details for the file xfilepy-0.5.1.tar.gz.

File metadata

  • Download URL: xfilepy-0.5.1.tar.gz
  • Upload date:
  • Size: 28.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Alpine Linux","version":"3.23.4","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for xfilepy-0.5.1.tar.gz
Algorithm Hash digest
SHA256 aab05657e01f65411a015bcde23beccab260b04e778a577da547285566bb70ff
MD5 957a9cb351f40f68f986222a9f59af7b
BLAKE2b-256 5bae4ebfec7a668aec0df9f8db93eab930f121c85c21ce9ed62d3a9ab141f864

See more details on using hashes here.

File details

Details for the file xfilepy-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: xfilepy-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 32.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Alpine Linux","version":"3.23.4","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for xfilepy-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6ff5b2557ed57025619697ffd7a826a0b918e298a6959e6aa63d2c6ba60ec071
MD5 4bc06b9e74542bc974358900b271eafa
BLAKE2b-256 442a39e738de80ec6daec933c405b27267afd58b2fe7b8c6335f2d47a6c9fac8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page