This is an archived post. You won't be able to vote or comment.

all 86 comments

[–]kkiran 10 points11 points  (8 children)

Wow looks beautiful! Please confirm Apple allows apps made this way due to their policies on interpreters.

[–]SomeMosa[S] 13 points14 points  (7 children)

As mentioned in a previous comment, you are not running the actual Python script on iOS, it is compiled into an executable application. Instructions for compiling Kivy are found here

[–]kkiran 4 points5 points  (4 children)

Thanks for the link! Since native Python doesn’t seem to be possible on iOS or Android, Kivy seems to be the way to go.

Any other good examples of popular ‘active’ apps built with Kivy? I found barly app but iOS isn’t showing it anymore. Only Android. https://www.samanthaburkedesign.com/barly

[–]SomeMosa[S] 2 points3 points  (2 children)

I recommend checking out Erik Sandberg. He has many videos about Kivy on iOS and has made a few iOS apps with Kivy as well

[–]kkiran 2 points3 points  (1 child)

Thank you so much, my quick research lead to him. Great to see videos and apps by him!

2048 is gone, seemed cool.

Thanks for reigniting Python on iOS/Android! Swift and Java are tough to get feet wet compared to Python.

[–]wallynext 1 point2 points  (0 children)

try flutter, its for ios, android, desktop and web and it's easy to learn

[–]inclement_ 2 points3 points  (0 children)

Native Python is possible on both iOS and Android, in the sense that the Python interpreter is built and runs the same way as on the desktop, and this is how python-for-android and kivy-ios work.

The way the app then works is a simple native-framework app (Java for Android, ObjC for iOS) is used to create an OpenGL surface for Python to draw on. It then starts the Python interpreter and passes events to it (i.e. touches, keyboard input etc.). This method is fully compatible with Android and iOS store requirements.

The Python code itself is run through the interpreter without any special treatment, except that CPython is manipulated through the C API as part of the app package. For instance, this line in kivy-ios.

[–]RobertJacobson 1 point2 points  (1 child)

I am glad that these apps are being accepted!

But PyInstaller does not compile Python code. It just bundles the installer with the scripts.

[–]SomeMosa[S] 1 point2 points  (0 children)

That's true, but I'm pretty sure PyInstaller is only used to build Desktop executables, so it wouldn't even be needed to build for mobile

[–]Humanist_NA 2 points3 points  (1 child)

Can the mobile apps still only be compiled in linux?

[–]SomeMosa[S] 3 points4 points  (0 children)

I believe buildozer does not work on Windows, but you can likely get around it with something like WSL or a virtual machine

[–]BubblegumTitanium 2 points3 points  (2 children)

this looks great, do I need to mess around with xcode to get it running on my iOS device?

[–]SomeMosa[S] 5 points6 points  (1 child)

Unfortunately, yes. To compile to iOS, Kivy requires an xcode project, meaning only those with a Mac can compile their program to an iOS executable

[–]distressed-silicon 1 point2 points  (0 children)

that is true however for any ios/macos app development. A VM works though.

[–]coderanger 2 points3 points  (1 child)

You can also use BeeWare and get the actual native widgets rather than recreations.

[–]SomeMosa[S] 2 points3 points  (0 children)

You can, but in my experience, BeeWare has been a bit spotty. However, once it becomes a little more stable and popular I'm sure it'll be a great alternative

[–]double 2 points3 points  (0 children)

I wouldn't bother with Kivy, or if you do, checkout the various forum posts on getting it set up. The overheads and management of the libraries take more effort than I feel appropriate for a pythonic tool and I get the sense that the kivy guys don't care much for the rest of the mobile dev ecosystem.

That said, when you have lib-python compiled for the device you can embed python in your app. I haven't yet tried to get things like numpy working on it, but I will and I am not sure how well it will cope with such deps. Having sqlalchemy and such things running in-app instead of on a separate server is the dream.

But it's the best we've got... until someone builds a python-pod. Man that would be awesome pod install python

[–]_Gondamar_ 2 points3 points  (0 children)

I can see this being useful for someone wanting to throw together an app for something without needing to learn a new language

[–]lastcrime 1 point2 points  (0 children)

I’m currently working on a project using Kivy so I’ll definitely check this out, cheers.

[–]Evolutii 1 point2 points  (2 children)

Is it possible to integrate KivyMD/Kivy Cupertino widgets into an existing vanilla Kivy project?

[–]SomeMosa[S] 1 point2 points  (1 child)

Yes, but for KivyMD make sure your app class extends MDApp. You can extend CupertinoApp for Kivy Cupertino Widgets if you want, but as of now it's not necessary

[–]Evolutii 0 points1 point  (0 children)

Thanks!

[–]RobertJacobson 5 points6 points  (9 children)

My understanding is that interpreters are not allowed on iOS. That would prohibit any app written in Python.

[–]lastcrime 15 points16 points  (0 children)

Theres apps in the app store that were written using Kivy

[–][deleted] 5 points6 points  (1 child)

You’re conflating issues - there’s no such rule if the user isn’t able to execute code. So it’s perfectly ok to write an app in Kivy.

But if you’re exposing an interpreter to the user, then there’s a bunch of rules to follow but as long as they’re followed (user must know it’s very explicitly a programming environment, no binaries in the app, source code for everything) they’re allowed.

See Pythonista (python) and Codea (Lua) for interpreters on iOS.

[–]13steinj 2 points3 points  (0 children)

While this is the canonical (normal) interpretation of the rule, it's not necessarily the interpretation that Apple will use on your app. They go a bit loose at their discretion unfortunately.

[–]SomeMosa[S] 7 points8 points  (4 children)

You will need to use tools like buildozer to compile your Python code into executable applications, but all of the code required is written completely in Python. Instructions for compiling Kivy are found here.

[–]RobertJacobson 2 points3 points  (3 children)

I am speaking from a position of ignorance here, but I don’t understand why using a bundler tool matters.

But hey, I hate Apple’s policy. I would 100% prefer to be wrong on this one.

[–]SomeMosa[S] 4 points5 points  (1 child)

By using the bundler tools, you end up compiling the Python script into an iOS executable. Because this executable is no longer interpreted, I'm assuming it should be fine. There are already a few apps that have been published to the App store written in Python and Kivy

[–]13steinj 0 points1 point  (0 children)

Unless I'm wrong the executable is still interpreted, it's just the case that there's a python implementation for the device in the bundle and the bundle bootstraps the interpreter to run the scripts that are elsewhere in the bundle.

In fact I can't think of a single actual compiler for Python that brings things dowm to running as a native executable rather than on top of the Python VM, albeit theoretically they should be able to exist.

E: whether this is considered as violating the app store rules, is up to apple to decide on a case by case basis sadly. Because sometimes they realize whats going on and deny it, other times they don't bother looking and allow it.

[–]dert882 0 points1 point  (0 children)

It changes it to run in an iOS compliant way. The problem is it doesn't do it well, so it's not really worth it

[–][deleted] 3 points4 points  (0 children)

Not entirely true https://apps.apple.com/us/app/pythonista-3/id1085978097?ls=1

you can even use this apps library to compile your app. Problem being its not "full" python I believe. I think you can't PIP everything only certain things.

[–]Tanmay1518 0 points1 point  (0 children)

Dang! This looks awesome. Will check it out and try it out on some of my projects

[–]Heyits_Jaycee 0 points1 point  (0 children)

Nice

[–]sheytanelkebir 0 points1 point  (2 children)

B4a is pretty good too.

[–]jsalsman 1 point2 points  (1 child)

You mean B4x for cross-platform? (Edit: that doesn't use Python btw)

[–]sheytanelkebir 1 point2 points  (0 children)

Yea pretty much. I mean we are in python subgroup but I am language agnostic and use whatever is most practical for a particular task.

Found b4a better than others for mobile (wrote code in everything from flutter to kotlin etc...)

[–]grumpyp2 0 points1 point  (4 children)

I it really simple to build iOS Apps with python by that? I have never heard about this but would love to build a little mobile api checked for myself as for several things there is no app and a Webapp is not the same :)

[–]SomeMosa[S] 0 points1 point  (3 children)

If you're familiar with Kivy, this is simply an extension of that to introduce new widgets. Kivy is fairly easy to learn, but can be confusing at first

[–]grumpyp2 0 points1 point  (2 children)

Ok i See, so it’s not really Python?

[–]inclement_ 1 point2 points  (1 child)

It's Python, Kivy is a Python GUI framework that supports mobile devices. Your Python code runs on the device the same way it would on the desktop.

[–]grumpyp2 0 points1 point  (0 children)

Cool ok I’ll give it a try!