Repository navigation
Introducing flet-media-library — A Full Media Library Service Extension for Flet
#6872
fazi-gondal
started this conversation in
General
Replies: 1 comment 1 reply
|
Answered in the first post in issues tab 😅 |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi @FeodorFitsner @ndonkoHenri @xzripper
I have built and published
flet-media-library, an open-source Flet service extension for accessing and managing the device media library from Python.GitHub: https://github.com/fazi-gondal/Flet-media-library
PyPI: https://pypi.org/project/flet-media-library/
Latest version:
1.1.2License: MIT
Platforms: Android and iOS
Flet:
>=1.0.0The goal is simple: provide Flet applications with a reusable, production-oriented API for working with device photos, videos, audio, albums, permissions, thumbnails and media-management operations.
Why this package?
Flet applications can already build the UI and application logic in Python, but mobile applications frequently need native platform integrations.
Accessing the device media library is a good example.
A typical application may need to:
Instead of implementing these pieces separately in every Flet application,
flet-media-libraryprovides them through one Python service.Architecture at a high level
The package is implemented as a Flet service extension.
The cross-platform media-library functionality is powered primarily by Flutter's
photo_manager.Where
photo_managerdoes not provide the required functionality, the package adds native Android Kotlin implementations.Cross-platform functionality
photo_manageris used for:Custom Android functionality
Native Kotlin handles:
This hybrid approach allows the package to provide functionality that would otherwise require applications to implement their own native plugins.
Features
1. Photos, videos and audio
The API treats the device media library as a unified source while still allowing applications to work with specific media types:
2. Per-type permissions
Applications can request only the media types they actually need:
Permission states are exposed independently:
Possible states include:
The permission model is particularly important on Android 13+, where image, video and audio permissions are granular.
Android permission support
The package supports the modern Android media permission model.
Android 6–12
with the permission limited to API 32 and below.
Android 13+
Android 14+
for selected/limited visual media access.
The package deliberately does not require:
The goal is to use the least amount of permission necessary for media operations.
iOS permission support
The package integrates with PhotoKit and supports:
Applications can call:
when additional selected-media access is required.
Album and folder browsing
Applications can retrieve albums:
Albums can represent collections such as:
Each
MediaAlbumprovides information such as:Media queries
The package provides paginated media queries:
Supported filters include:
Supported sorting includes:
Pagination provides:
This makes the API suitable for gallery applications that cannot load the entire media library at once.
Media metadata
Each
MediaAssetprovides:This gives applications enough information to build gallery, media-manager, downloader and editor interfaces without immediately opening the original files.
Thumbnail support
There are two thumbnail approaches.
Base64 thumbnail
This is convenient for simple Flet UI usage:
File-path thumbnail
For larger galleries:
The plugin stores the generated JPEG in its local cache and returns the filesystem path.
This avoids repeatedly transferring large Base64 strings across the Python/Flutter boundary.
For gallery grids and scrolling media browsers, this can significantly reduce unnecessary bridge traffic.
Saving images
Images can be saved directly into public media storage:
Supported public destinations include:
The implementation uses
photo_manager.Saving videos
Videos can be saved directly to public video storage:
Supported destinations include:
Saving audio
Audio saving is one of the areas where the package extends beyond the functionality provided by
photo_manager.On Android this uses the native:
API.
Audio can therefore be indexed directly into the public:
directory.
This feature is currently Android-only.
Calling it on unsupported platforms raises
UnsupportedError.Rename media
Android applications can rename assets:
This uses the Android MediaStore rather than requiring unrestricted filesystem access.
On newer Android versions, the system may require user confirmation when modifying media that the application does not own.
Move media
Android 10+ supports moving assets using MediaStore relative paths:
For example:
This is implemented through:
rather than unrestricted filesystem access.
Delete media
Single asset:
Multiple assets:
The underlying platform confirmation behavior is respected.
Copy media
The package also exposes:
However, platform support differs because modern Android scoped storage restricts arbitrary duplication.
The API therefore reports unsupported operations rather than pretending the operation is universally available.
Real-time media change notifications
Applications can subscribe to media-library changes:
Applications can use this for:
When finished:
Capability discovery
Instead of forcing applications to maintain their own Android/iOS feature matrix, the package exposes:
Capabilities include:
For example:
This makes platform-specific UI and behavior easier to implement.
Typed exceptions
The package provides structured exceptions:
Applications can therefore handle expected platform and permission failures without relying on parsing error strings.
Cache management
Thumbnail/file caches can be cleared:
This is useful for applications that need to control temporary storage usage.
Installation
Install from PyPI:
or:
For a project using
pyproject.toml:Basic example
Demo application
The repository includes a full demo application designed to exercise the package on real Android hardware.
The demo includes:
Gallery
Playback
Capture
File management
Testing
The demo also contains an automated smoke-test flow for the package's core APIs.
A pre-built Android APK is available from GitHub Releases:
https://github.com/fazi-gondal/Flet-media-library/releases
This makes it possible to test the package without setting up the complete Flutter/Android development environment first.
Building a Flet application
For Android:
For iOS:
Local development
The project is open source and contributions are welcome.
The repository also contains the full demo application under:
Dependencies and ecosystem
The project builds on several parts of the Flet/Flutter ecosystem:
The package itself is MIT licensed.
Who can use it?
This package can be useful for many types of Flet applications:
For example, a Flet video downloader can download a video to temporary storage and then simply call:
A recording application can similarly save recordings directly into:
without implementing its own MediaStore integration.
What I would like from the Flet community
I would especially appreciate feedback from people building mobile applications with Flet.
Some areas I would like to explore with the community:
If you are building a Flet application that needs access to photos, videos or audio, I would also be interested in hearing what APIs you currently have to implement yourself.
Links
Source:
https://github.com/fazi-gondal/Flet-media-library
PyPI:
https://pypi.org/project/flet-media-library/
Releases / Demo APK:
https://github.com/fazi-gondal/Flet-media-library/releases
Issues:
https://github.com/fazi-gondal/Flet-media-library/issues
License: MIT
Feedback and discussion
If you have tried the package, please share:
The goal is to make
flet-media-librarya useful reusable building block for Flet mobile applications rather than having every project solve device-media integration independently.All reactions