Bridging Python Packages to Swift


(Muhammad Tahir Vali) #1

Hey everyone,

I lack the experience the rest of the people in this list probably have
being an undergraduate student but I would love to participate in this
language because I see its potential.

With that being said, one of the biggest advantages python has is its
immersive number of packages that is appealing to anyone that writes
scripts. Swift is evolving into a scripting language as well but it lacks
the libraries python has.

I suppose its worth bridging python packages with swift until Swift is
grown up to take over the world :smiley:

Can anyone help me figure out how thats done ?

···

--
Best Regards,

Muhammad T. Vali


(Chéyo Jiménez) #2

Hi Muhammad,

I am not an expert either but here is what I would do if I were you.

Go look at xamarin/ mono open source project to see how they bind objc and Java libraries to c#. Once you understand that then you would need a version of python (cpython or another typed Python version) that you are able to expose to swift (probably using llvm). I believe there are a bunch of projects that expose libraries like .net, c++ to python but I am not familiar with projects going the other way around.

Another way could be to figure out a way to expose the python script to c. (Python to c source to source translation possibly ). Swift is able to import c code but it is not pretty; you would have to build a nice wrapper around it using swift.

Needless to say, I think that is a lot of work that people just won't do. If I needed a python library in swift, I would just rewrite it in swift.

There are probably other ways. Good luck.

···

On Jul 2, 2016, at 12:17 PM, Muhammad Tahir Vali via swift-dev <swift-dev@swift.org> wrote:

Hey everyone,

I lack the experience the rest of the people in this list probably have being an undergraduate student but I would love to participate in this language because I see its potential.

With that being said, one of the biggest advantages python has is its immersive number of packages that is appealing to anyone that writes scripts. Swift is evolving into a scripting language as well but it lacks the libraries python has.

I suppose its worth bridging python packages with swift until Swift is grown up to take over the world :smiley:

Can anyone help me figure out how thats done ?

--
Best Regards,

Muhammad T. Vali
_______________________________________________
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev


(Brent Royal-Gordon) #3

I lack the experience the rest of the people in this list probably have being an undergraduate student but I would love to participate in this language because I see its potential.

With that being said, one of the biggest advantages python has is its immersive number of packages that is appealing to anyone that writes scripts. Swift is evolving into a scripting language as well but it lacks the libraries python has.

I suppose its worth bridging python packages with swift until Swift is grown up to take over the world :smiley:

Can anyone help me figure out how thats done ?

I'm no Pythonista, but this is where I'd start: <https://docs.python.org/3/extending/index.html> Swift and Python can both call into C, so pretty much any bridge between the two is going to start by using Python's C API to embed a Python interpreter in a Swift library.

···

--
Brent Royal-Gordon
Architechies