3

create an app with python and then I can create a mobile app with it to run on iPhone or more?

1
  • 1
    What do you mean, what do you want to do with python, is it the app itself, or Is it the backend API you wanna build in python? Commented Jun 8, 2022 at 6:10

3 Answers 3

1

You can use replit (an online ide) to write code online, or use the replit app, but I'm not sure if there is an app for ios

Sign up to request clarification or add additional context in comments.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
0

Mobile development

Python doesn’t have built-in mobile development capabilities, but there are packages you can use to create mobile applications, like Kivy, PyQt, or even Beeware’s Toga library.

  • Kivy - Open source Python library for rapid development of applications that make use of innovative user interfaces, such as multi-touch apps. Kivy does not attempt to use native controls or widgets. All of its widgets are custom-drawn. This means that Kivy applications will look the same across all platforms. However, it also means that your app’s look and feel will differ from your user’s native applications. This could be a benefit or a drawback, depending on your audience.
  • PyQt - is a set of Python bindings for The Qt Company's Qt application framework and runs on all platforms supported by Qt including Windows, macOS, Linux, iOS and Android. PyQt6 supports Qt v6, PyQt5 supports Qt v5 and PyQt4 supports Qt v4. The bindings are implemented as a set of Python modules and contain over 1,000 classes.
  • Toga - is a Python native, OS native, cross platform GUI toolkit. Toga consists of a library of base components with a shared interface to simplify platform-agnostic GUI development.

References

  1. Build a Mobile Application With the Kivy Python Framework
  2. What is PyQt?
  3. Toga

1 Comment

PyQt is NOT official!!! Also it's GPL'd, also deploying to iOS is extremely hacky!
0

Some people apparently has already mentioned Toga (see https://toga.beeware.org), the GUI framework, however I'd like to go a bit more in-depth into how all this stuff works. Also, just to add, Briefcase (https://briefcase.beeware.org) is the packaging tool that turns a Python codebase into an Xcode project, installing all dependencies in the process.

So... how is Python running on iOS in the first place? Well, Python is written in C and uses autoconf, so it's possible to compile it for iOS with a bunch of additional handling -- with things like platform identification and more annoyingly, packaging Python properly so it could be distributed through the app store. This includes using Apple's "framework" directory structure and not installing any platform-specific tools, and making each binary extension module a separate "framework" in Apple's sense. And of course, the whole lot of C APIs that Apple has helpfully disabled. References: https://docs.python.org/3/using/ios.html and the whole thread of PRs is at https://github.com/python/cpython/issues/114099 -- this part of functionality is made possible with Python 3.13 officially, and has been maintained in https://github.com/beeware/Python-Apple-support/ and -patched branches of https://github.com/freakboy3742/cpython/ before. CPython still lacks some infrastructure for iOS builds and has not added tvOS/watchOS/visionOS yet so these two repositories serve these purposes as more things gets integrated into official CPython.

Now you would have Python running on iOS, but you'd need a way to access objc APIs. Rubicon Obj-C (https://rubicon.beeware.org/) is a shim that does exactly that, created by the BeeWare project as well. Since the Objective-C runtime is all C underneath it, and Python provides ctypes to call C functions, Rubicon Objective-C thus works by calling the appropriate C functions to send the appropriate messages using the Objective-C runtime, thus being able to access all native Objective-C APIs.

To start this Python code that does all the interesting stuff, however, the Python C API is used. The template that Briefcase uses to roll out Xcode projects with Python code is found at https://github.com/beeware/briefcase-iOS-Xcode-template and consists of a bulky part of initialization as seen in the main Objective-C file.

Toga's iOS backend uses Rubicon Objective-C to access the native Objective-C classes to make a UIApplication, UIWindow, UIViews, and all the native controls.

A really good conference talk by Dr. Russell Keith-Magee, founder of Toga, explains how this all works not only on iOS as I described above but also on Android.

I'm putting this info here just in case you're curious or if you'd like to try to embed Python and access the raw Objective-C APIs by yourself. Toga, however, is getting more mature almost every day, and besides simply wrapping the iOS APIs as described above, it is significantly more Pythonic and it abstracts away all the small cross-platform differences of apps on multiple platforms, so if you write a Toga app you can also deploy it on Windows (Winforms), Linux (GTK+), macOS (Cocoa), Android -- although some functionality may not be fully available.


DISCLOSURE

I have contributed to (but am not affiliated with) this project and therefore may be biased, however I have ensured that all my statements above are truthful in terms of the current state of the project. I am NOT AFFILIATED with the BeeWare project; just trying to spread some news of it.


EDIT and if you want to interact with the Python runtime in Swift you may utilize PythonKit: https://github.com/pvieito/PythonKit -- this is not related to BeeWare nor official CPython which were projects I have been talking about earlier.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.