How to execute external Python script with a program coded in Haxe?
Question: I have a Haxe program and I need to retrieve data from Wordnik API. Here are
the list of supported platform in Wordnik:
<http://developer.wordnik.com/#!/libraries>

I have no experience in all of these languages supported by Wordnik. However,
I think Python is the most feasible way to connect Wordnik API into my Haxe
program because Python is a scripting language and can be executed from
terminal command.

Perhaps, something like Haxe program execute the Python WITH some parameters.
Then the Python script retrieve data from Wordnik and then compile it into a
JSON or .txt file. Finally return back to Haxe program to parse the JSON or
.txt file. I am not sure how this thing can work, hence I am looking for
guidance here :).


Answer: One thing to look out for is using the [Python 3
version](https://github.com/wordnik/wordnik-python3) of the library, instead
of the [Python 2.7 one](https://github.com/wordnik/wordnik-python) which is
linked to on that overview page. Haxe's Python target [only supports version 3
or higher](https://github.com/HaxeFoundation/haxe/issues/4195).

There shouldn't be a need for a Python program serving as an interface between
Haxe and the Wordnik API - you could write
[externs](http://haxe.org/manual/lf-externs.html) describing the interface to
just use it directly from Haxe. An `extern` for a very simple class,
[`wordnik.models.Label`](https://github.com/wordnik/wordnik-
python3/blob/master/wordnik/models/Label.py), could look like this:

    
    
    package wordnik.models;
    
    @:pythonImport("wordnik.models.Label", "Label")
    extern class Label
    {
        public var text:String;
        public var type:String;
    
        public function new() 
        {
        }
    }
    

With that, you can then use the API from Haxe:

    
    
    package;
    
    import python.Lib;
    import wordnik.models.Label;
    
    class Main 
    {
        static function main() 
        {
            var label = new Label();
            label.text = "Test";
            trace(label.text);
        }
    }
    

You can find a lot of examples of Python externs in [the Haxe standard
library](https://github.com/HaxeFoundation/haxe/tree/development/std/python/lib).
It also has wrappers for things that are a bit more complex to express, like
[`KwArgs`](https://github.com/HaxeFoundation/haxe/blob/development/std/python/KwArgs.hx).

