How can a python code be integrated with Ionic 4

My team is working on Ionic 4 to build an offline mobile app. My task is to work on a python OCR code where an image should be taken as input and text in the image should be sent as output on click of a button in the app.

I’ve worked on the python code and would like to know how this code can be integrated with the Ionic framework.

1 Like

This is not going to be easy.

Android apps can rely on Java being around. iOS apps can rely on Swift and/or Objective-C. That was kind of a PITA, which is why PhoneGap was born in the first place. PhoneGap apps can rely on JavaScript and a browser environment, and for stuff that needs to be closer to the metal, one has to write a plugin that again is going to have to have different implementations for Android and iOS.

So “Python” was nowhere in that last paragraph, which means there isn’t (AFAIK) a cross-platform way to write Python in mobile apps. PhoneGap turned into Cordova, which now in Ionic-land is being subsumed by Capacitor. So the first thing I would ask myself if I were you is:

Do I absolutely, positively, need this to be in Python, or can I rewrite it in TypeScript?

If there’s a chance to reimplement it in TypeScript, I would absolutely go that route, because it will be futureproof and much more lightweight to deploy and work with.

If there isn’t, you’re going to need to try to figure out how to embed a Python runtime environment and interact with it via Capacitor. Cursory Googling came across this project for Android; I have no clue whether anything remotely similar exists for iOS.

2 Likes

Is it in 2024 possible to use Python in Ionic App?