Can I write native iPhone apps using Python?

IphonePythonCocoa Touch

Iphone Problem Overview


Using PyObjC, you can use Python to write Cocoa applications for OS X. Can I write native iPhone apps using Python and if so, how?

Iphone Solutions


Solution 1 - Iphone

You can use PyObjC on the iPhone as well, due to the excellent work by Jay Freeman (saurik). See iPhone Applications in Python.

Note that this requires a jailbroken iPhone at the moment.

Solution 2 - Iphone

Not currently, currently the only languages available to access the iPhone SDK are C/C++, Objective C and Swift.

There is no technical reason why this could not change in the future but I wouldn't hold your breath for this happening in the short term.

That said, Objective-C and Swift really are not too scary...

>#2016 edit Javascript with NativeScript framework is available to use now.

Solution 3 - Iphone

It seems this is now something developers are allowed to do: the iOS Developer Agreement was changed yesterday and appears to have been ammended in a such a way as to make embedding a Python interpretter in your application legal:

SECTION 3.3.2 — INTERPRETERS

Old: > > 3.3.2 An Application may not itself install or launch other executable > code by any means, including without > limitation through the use of a > plug-in architecture, calling other > frameworks, other APIs or otherwise. > Unless otherwise approved by Apple in > writing, no interpreted code may be > downloaded or used in an Application > except for code that is interpreted > and run by Apple’s Documented APIs and > built-in interpreter(s). > Notwithstanding the foregoing, with > Apple’s prior written consent, an > Application may use embedded > interpreted code in a limited way if > such use is solely for providing minor > features or functionality that are > consistent with the intended and > advertised purpose of the Application.

New:

> 3.3.2 An Application may not download or install executable code. > Interpreted code may only be used in > an Application if all scripts, code > and interpreters are packaged in the > Application and not downloaded. The > only exception to the foregoing is > scripts and code downloaded and run by > Apple’s built-in WebKit framework.

Solution 4 - Iphone

Yes you can. You write your code in tinypy (which is restricted Python), then use tinypy to convert it to C++, and finally compile this with XCode into a native iPhone app. Phil Hassey has published a game called Elephants! using this approach. Here are more details,

http://www.philhassey.com/blog/2009/12/23/elephants-is-free-on-the-app-store/

Solution 5 - Iphone

Yes, nowadays you can develop apps for iOS in Python.

There are two frameworks that you may want to checkout: Kivy and PyMob.

Please consider the answers to this question too, as they are more up-to-date than this one.

Solution 6 - Iphone

An update to the iOS Developer Agreement means that you can use whatever you like, as long as you meet the developer guidelines. Section 3.3.1, which restricted what developers could use for iOS development, has been entirely removed.

Source: http://daringfireball.net/2010/09/app_store_guidelines

Solution 7 - Iphone

Pythonista has an Export to Xcode feature that allows you to export your Python scripts as Xcode projects that build standalone iOS apps.

https://github.com/ColdGrub1384/Pyto is also worth looking into.

Solution 8 - Iphone

The iPhone SDK agreement is also rather vague about whether you're even allowed to run scripting languages (outside of a WebView's Javascript). My reading is that it is OK - as long as none of the scripts you execute are downloaded from the network (so pre-installed and user-edited scripts seem to be OK).

IANAL etc etc.

Solution 9 - Iphone

BeeWare is an open source framework for authoring native iOS & Android apps.

Solution 10 - Iphone

2019 Update:

While Python-iOS development is relatively immature and likely will prevent (afaik) your app from having native UI and functionality that could be achieved in an Apple-supported development language, Apple now seems to allow embedding Python interpreters in Native Swift/Obj-C apps.

This supports importing Python libraries and running Python scripts (even with supplied command-line arguments) directly from your Native Swift/Obj-C code.

My company is actually wrapping our infrastructure (originally written in Python) in a native iOS application! It works very well and communication between the parts can be easily achieved via a client-server model.

Here is a nice library by Beeware with a cookiecutter template if you want to try and run Python scripts in your iOS app: https://github.com/beeware/Python-Apple-support/tree/3.6.

Solution 11 - Iphone

Technically, as long as the interpreted code ISN'T downloaded (excluding JavaScript), the app may be approved. Rhomobiles "Rhodes" framework does just that, bundling mobile Ruby, a lightweight version of Rails, and your app for distribution via the app-store. Because both the interpreter and the interpreted code are packaged into the final application - Apple doesn't find it objectionable.

http://rhomobile.com/products/rhodes/

Even after the latest apple press release - rhodes apps (mobile ruby) are still viable on the app-store. I'd find it hard to believe that tinyPy or pyObjC wouldn't find a place if there is a willing developer community.

Solution 12 - Iphone

You can do this with PyObjC, with a jailbroken phone of course. But if you want to get it into the App Store, they will not allow it because it "interprets code." However, you may be able to use Shed Skin, although I'm not aware of anyone doing this. I can't think of any good reason to do this though, as you lose dynamic typing, and might as well use ObjC.

Solution 13 - Iphone

The only significant "external" language for iPhone development that I'm aware of with semi-significant support in terms of frameworks and compatibility is MonoTouch, a C#/.NET environment for developing on the iPhone.

Solution 14 - Iphone

I think it was not possible earlier but I recently heard about PyMob, which seems interesting because the apps are written in Python and the final outputs are native source codes in various platforms (Obj-C for iOS, Java for Android etc). This is certainly quite unique. This webpage explains it in more detail.

I haven't given it a shot yet, but will take a look soon.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondavidmyttonView Question on Stackoverflow
Solution 1 - IphonegavrieView Answer on Stackoverflow
Solution 2 - IphoneDave VerwerView Answer on Stackoverflow
Solution 3 - IphonejkpView Answer on Stackoverflow
Solution 4 - IphoneAsim JalisView Answer on Stackoverflow
Solution 5 - IphoneFilipe CorreiaView Answer on Stackoverflow
Solution 6 - IphoneGordon ChristieView Answer on Stackoverflow
Solution 7 - IphonecclaussView Answer on Stackoverflow
Solution 8 - IphoneschwaView Answer on Stackoverflow
Solution 9 - IphonemichaelView Answer on Stackoverflow
Solution 10 - IphoneRakeeb HossainView Answer on Stackoverflow
Solution 11 - IphoneMichael McCrackenView Answer on Stackoverflow
Solution 12 - IphoneZifreView Answer on Stackoverflow
Solution 13 - IphoneMikeView Answer on Stackoverflow
Solution 14 - IphoneJohn M.View Answer on Stackoverflow