Fable-Py
We are going to compile F# to Python! Seriously
Letโs get started, create an empty folder and an empty F# script file (app.fsx),
as usual you need dotnet-sdk installed and vscode + ionide (or rider or visual studio).
mkdir test-fable-py cd test-fable-py touch app.fsxcode .
Install Fable-Python
dotnet new tool-manifest // this will install it as a local tooldotnet tool install fable-py --version 4.0.0-alpha-032
now that you are set, you can fill up your script with some F# code that will be compiled to python by fable, e.g. I used the sample from the docs.
And letโs invoke the fable-python compiler!!!! ๐ ๐
Our Beautiful Python Code
WebApp (Flask)
This app uses python flask and F# Feliz.ViewEngine for HTML view rendering, which will be translated by fable to standard python..
Now we can run our fable-py command, to see the compiled python code.
Compiled to Python becomes, adjusted a bit for โprettyโ print:
Awesome! Now letโs run our app in python!
Note: to run the Flask server, the script needs to be named app.fsx, so it will compile to app.py and be recognized by Flask.
Flask Server
python3 -m pip install flask
I will install flask, and run it with
python3 -m flask run
And this is the output on the browser