Nova Flow OS
KDE Developer Platform
KDE Developer Platform
  • KDE Developer Platform
    • Getting started
      • Building KDE software
        • KDE software
        • Where to find the development team
        • Learning more
        • Choose what to work on
        • Source code cross-referencing
        • Installing build dependencies
        • Set up a development environment
        • Building KDE software with kdesrc-build
        • Basic troubleshooting
        • Tips and tricks
        • IDE Configuration
          • Setting up an IDE for KDE development
          • Visual Studio Code
          • Qt Creator
          • Kate
          • KDevelop
          • CLion
          • Sublime Text
        • Building KDE software manually
        • Building KDE software with distrobox and podman
      • Kirigami
        • KDE is ours
        • Setting up and getting started
        • Explaining pages
        • Layouts, ListViews, and Cards
        • Adding actions
        • Adding a dialog
        • Using separate files
        • Next steps
        • Colors and themes in Kirigami
        • Typography
        • Actions based components
        • Page rows and page stacks
        • Scrollable pages and list views
        • Cards
        • Drawers
        • Chips
        • Dialog types
        • Controls and interactive elements
        • Form layouts
        • Inline messages
        • Action toolbars
        • Progress bars and indicators
        • List views
        • Understanding CMakeLists
        • Figuring out main.cpp
        • Connect logic to your QML user interface
        • Connect models to your QML user interface
        • About page
        • Introduction to Kirigami Addons
        • FormCard About pages
        • Form delegates in your settings pages
      • KXmlGui
        • Getting started with KXmlGui
        • Hello World!
        • Creating the main window
        • Using actions
        • Saving and loading
        • Command line interface
      • Python with Kirigami
        • Apps with QML and Python
        • Your first Python + Kirigami application
        • Creating a Python package
        • Creating a Flatpak
      • Common programming mistakes
      • Adding a new KDE project
    • Features
      • Icons
      • Configuration
        • The KConfig Framework
        • Introduction to KConfig
        • Using KConfig XT
        • KDE Frameworks 6 porting guide
        • Settings module (KCM) development
        • KConfigDialog
      • D-Bus
        • What is D-Bus practically useful for?
        • Introduction to D-Bus
        • Accessing D-Bus interfaces
        • Intermediate D-Bus
        • Creating D-Bus interfaces
        • Using custom types with D-Bus
        • D-Bus autostart services
      • Create your own mouse cursor theme
      • Session management
      • Archives
      • Desktop file
      • KAuth
        • Privilege Escalation
        • Using actions in your applications
      • KIdleTime
      • Akonadi: personal information management
        • Debugging Akonadi Resources
        • Using Akonadi in applications
      • Concurrent programming
      • Solid
      • Sonnet
    • Plasma themes and plugins
      • Getting started
      • Plasma Widget tutorial
        • How to create a plasmoid
        • Setup
        • Porting Plasmoids to KF6
        • Testing
        • QML
        • Plasma's QML API
        • Widget Properties
        • Configuration
        • Translations / i18n
        • Examples
        • C++ API
      • KWin Effects
      • Plasma Desktop scripting
        • Javascript Interaction With Plasma Shells
        • Templates
        • Examples
        • API documentation
        • Configuration keys
      • Plasma Style tutorial
        • Creating a Plasma Style quickstart
        • Understanding Plasma Styles
        • SVG elements and Inkscape
        • Background SVG format
        • System and accent colors
        • Theme elements reference
        • Porting themes to Plasma 5
        • Porting themes to Plasma 6
      • Aurorae window decorations
      • KWin scripting tutorial
        • Quick start
        • KWin scripting API
      • Wallpapers
      • Plasma comic
        • Tutorial
        • Testing and debugging
        • Examples
      • Create a custom Window Switcher
      • KRunner C++ Plugin
        • Basic Anatomy of a Runner
        • KRunner metadata format
    • Applications
      • Creating sensor faces
      • Dolphin
        • Creating Dolphin service menus
      • Kate
        • Kate plugin tutorial
      • KMines
        • Making a KMines theme
      • Writing tests
        • Appium automation testing
    • Packaging
      • Android
        • KDE on Android
        • Building applications for Android
        • Packaging and publishing applications for Android
        • Publishing on Google Play
          • Introduction
          • Packaging your app
          • Adding your app to Google Play
          • Publishing your app
          • Releasing new versions of old apps
        • Porting applications to Android
          • Basic porting
          • Making applications run well on Android
          • Metadata
      • Windows
        • Packaging and publishing applications for Windows
        • Publish your app in the Microsoft Store
          • Packaging your app for the Microsoft Store
          • Submitting your app to the Microsoft Store
      • Plasma Mobile
        • KDE on mobile devices
        • Porting a new device to Plasma Mobile
        • KDE Telephony stack
          • General Overview
          • Kernel layer
          • System daemons
            • General overview
            • Developing Telephony functionality
            • ModemManager Telephony functions
          • Session daemons
          • QML declarative plugin layer
          • KDE application layer
        • Execute applications
      • Distributing KDE software as Flatpak
        • Your first Flatpak
        • Extending your package
        • Nightly Flatpaks and Flathub
        • Testing your Flatpak
    • System administration
      • Shell scripting with KDE dialogs
      • Kiosk: Simple configuration management for large deployment
        • Abstract
        • Introduction to Kiosk
        • Kiosk keys
    • Contribute to the documentation
    • About
      • Readme
      • License
        • Creative Commons Attribution-ShareAlike 4.0 International
        • GNU General Public License 3.0 or later
Powered by GitBook
On this page
  1. KDE Developer Platform
  2. Getting started
  3. Python with Kirigami

Creating a Flatpak

Ship your app easily to users.

PreviousCreating a Python packageNextCommon programming mistakes

Last updated 8 months ago

We can also take care of distributing our PyQt application. Although the is probably the standard way to distribute a Python package, should be more user friendly for Linux users than using command line tools such as pip.

Flatpaks are built locally using flatpak-builder. The tool checks out the source code and any of its custom dependencies, then builds it against a runtime (a collection of libraries shared between flatpaks). Since we already took care of the source code, all we need is to write a single file, the flatpak manifest, which describes everything needed to build the package.

Create a new flatpak manifest file simplemdviewer/org.kde.simplemdviewer.json:

{
    "id": "org.kde.simplemdviewer",
    "runtime": "org.kde.Platform",
    "runtime-version": "6.7",
    "sdk": "org.kde.Sdk",
    "base": "io.qt.PySide.BaseApp",
    "base-version": "6.7",
    "command": "simplemdviewer",
    "finish-args": [
    "--share=ipc",
    "--socket=fallback-x11",
    "--socket=wayland",
    "--device=dri",
    "--socket=pulseaudio"
    ],
    "modules": [
        "python3-markdown.json",
        {
            "name": "simplemdviewer",
            "buildsystem" : "simple",
            "build-commands" : [
                "python3 setup.py build",
                "python3 setup.py install --prefix=/app --root=/"
            ],
            "sources": [
                {
                    "type": "archive",
                    "path": "dist/org.kde.simplemdviewer-0.1.tar.gz"
                }
            ]
        }
    ],
    "cleanup-commands": [
        "/app/cleanup-BaseApp.sh"
    ]
}

Note

The Flatpak manifest for PySide uses the version 6.7 for the runtime and the base app, as opposed to PyQt which uses the version 6.6. The reason for this is that PySide Flatpak base app is only available from the version 6.7 and upwards.

This file reads that we use the markdown module and the build info is provided by the python3-markdown.json manifest file. We are going to create this manifest automatically using flatpak-pip-generator.

#From within the simplemdviewer/ directory
wget https://raw.githubusercontent.com/flatpak/flatpak-builder-tools/master/pip/flatpak-pip-generator --directory-prefix env/bin

The generator has a single dependency to run, requirements-parser. After installing it in the virtual environment, the tool can be run:

python3 -m pip install requirements-parser
python3 env/bin/flatpak-pip-generator markdown

You should see a new python3-markdown.json inside simplemdviewer/ now.

Install org.kde.Sdk and org.kde.Platform, version 6.6, from Flathub:

flatpak install org.kde.Platform/x86_64/6.6 org.kde.Sdk/x86_64/6.6
flatpak install com.riverbankcomputing.PyQt.BaseApp/x86-64/6.6

To attempt a first build of the flatpak, run:

flatpak-builder --verbose --force-clean flatpak-build-dir org.kde.simplemdviewer.json

Tip You can add the flag `--install-deps-from flathub` to flatpak-builder to make it download the Sdk, Platform and Baseapp for you instead of installing them manually.

If you installed Flathub as a user repository, you will need to add the --user flag to install the runtime. Otherwise you might see the error "Flatpak system operation Deploy not allowed for user".

Test the flatpak build:

flatpak-builder --run flatpak-build-dir org.kde.simplemdviewer.json simplemdviewer

Build a distributable nightly flatpak bundle:

flatpak-builder flatpak-build-dir --repo=simplemdviewer-master --force-clean --ccache org.kde.simplemdviewer.json
flatpak build-bundle simplemdviewer-master simplemdviewer.flatpak org.kde.simplemdviewer

Other improvements you can make to your application:

  • Consider making it an official [KDE Application]({{< ref "add-project" >}}), building [Flatpak nightlies using KDE infrastructure]({{< ref "docs/packaging/flatpak/publishing" >}}).

Happy hacking.

Download , and save it into the simplemdviewer/env/bin/ directory:

We are using the , which provides Qt dependencies like QtQuick and KDE frameworks like Kirigami, so you will need the Software Development Kit (Sdk) runtime to build the app locally, and the Platform runtime to run it. More than that, the KDE Runtime is based on the general , which provides Python. You can read more about runtimes in the .

We are using the , which contains an already built and ready-to-use PyQt we can quickly add on top of the KDE Runtime, so we need to install it as well.

For a PyQt Flatpak application, we are using the , which contains an already built and ready-to-use PyQt we can quickly add on top of the KDE Runtime, so we need to install it as well. Alternatively, you can use the , which provides a similar ready-to-use PySide6 environment.

Now we can either distribute the simplemdviewer.flatpak directly to the users, or submit the application to a flatpak repository, like the most popular repository, . See the .

Signing the source archive with a .

Providing copyright and licensing information for each file with .

Learn more about building flatpak apps with our [Flatpak Tutorial]({{< ref "flatpak" >}}) and the .

Follow the to refine the presentation of your application on Flathub.

Python Package Index (PyPI)
Flatpak
flatpak-pip-generator
KDE Runtime
Freedesktop Runtime
Flatpak Runtime Documentation
PyQt Baseapp
PyQt Baseapp
PySide Baseapp
Flathub
App Submission Guidelines
detached signature
REUSE
official documentation
Flathub Quality Guidelines