Python Interop with Swift 4+

The file is still available from the old mailing list archive. Download it from there:
https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20171204/042029.html

2 Likes

Apple does not provide Python 3 framework. Will Python3.framework be available in the future?

I doubt anyone from Apple can comment on future plans here.

Is anyone able to make this work on Linux?

Hi Chris,

I have one more example of an interoperability layer to dynamic language, to Perl. Reading your code, it was very fun to find that API and implementations are very similar. What’s more, Swift language limitations making providing clean API hard are the same:

The last one is the most annoying, especially when passing Swift function as a callback subroutine to Perl (it is harder then calling Perl subroutine because number of arguments usually greater then number of returned values and they are more diverse).

Nonetheless it is a pleasure to see that Swift moves in the right direction. Generic subscripts, dynamic members and callables are the things I was missing for during creation of this interoperability library.

If you are interested in the Perl interop library, its documentation and source code can be found here: https://my-mail-ru.github.io/swiftperl/index.html
It can be run on macOS or Linux without a lot of magic. Usage examples can be found in tests and documentation, and (may be outdated a little) here: https://github.com/my-mail-ru/swiftperl-Coro/blob/master/Sources/PerlCoro/Coro.swift
Hope this helps you with your Python interop a little.

2 Likes

Hi Max,

Check out this thread: Swift/Python interop library, Xcode 9.3b3 edition

@pvieito wrapped it up into a SwiftPM package and I believe that works on linux (but haven’t tried it).

-Chris

2 Likes

Hi Aleksey,

This is super cool, I’m really excited that you’re pushing on Perl interoperability. I agree that computed subscripts and properties can’t come fast enough :-)

Your docs look really great, and this layer looks well done. One random question for you in this example:

Perl: my @response = (200, ["Content-Type" => "application/json"], ["{}"]);
Swift: let response: PerlArray = [200, ["Content-Type", "application/json"], ["{}"]]

Wouldn’t the second line be more naturally done with dictionary literal syntax?

let response: PerlArray = [200, ["Content-Type": "application/json"], ["{}"]]

It seems like your implementation would support that, maybe it’s just a dox bug.

In any case, great work!

-Chris

Perl: my @response = (200, ["Content-Type" => "application/json"], ["{}"]);
Swift: let response: PerlArray = [200, ["Content-Type", "application/json"], ["{}"]]

Wouldn’t the second line be more naturally done with dictionary literal syntax?

Second element of the outer array is an array reference, not a hash reference. This structure is defined by PSGI standard and allows to pass multiple HTTP headers with the same name. Agree, this example is quite ambiguous.

Dictionary literal syntax is supported for hashes and hash references, for example:

Perl: my @users = [ { id => 1, name => "Bob" }, { id => 2, name => "John" } ];
Swift: let users: PerlArray = [ [ "id": 1, "name": "Bob"], [ "id": 2, "name": "John"] ]
1 Like

Yes, I think that this is a doc bug. This is what I’m getting at:

BEFORE: let response: PerlArray = [200, ["Content-Type", "application/json"], ["{}"]]
AFTER : let response: PerlArray = [200, ["Content-Type": "application/json"], ["{}"]]

-Chris

Terms of Service

Privacy Policy

Cookie Policy