Let's set up a Fable.Python project from scratch and get our first F# code running as Python.
You'll need:
- .NET SDK (6.0 or later)
- Python 3.12+ (Fable targets Python 3.12 or higher)
Create a new directory and initialize an F# project:
mkdir my-fable-python
cd my-fable-python
# Create F# console app
dotnet new console -lang F#
# Set up local tools and install Fable 5 (alpha)
dotnet new tool-manifest
dotnet tool install fable --version 5.0.0-alpha.20
# Add Fable.Core package
dotnet add package Fable.Core --version 5.0.0-beta.4Fable-generated Python code requires the fable-library runtime:
pip install "fable-library==5.0.0a20"Note: Version pinning matters. The fable-library version must match
your Fable compiler version. PyPI uses 5.0.0a20 format instead of 5.0.0-alpha.20.
Replace the contents of Program.fs with:
printfn "Hello from Fable.Python!"
let square x = x * x
let numbers = [1; 2; 3; 4; 5]
let squares = numbers |> List.map square
printfn "Squares: %A" squaresTranspile to Python:
dotnet fable --lang pythonThis creates Program.py in your project directory. Run it:
python3 Program.pyYou should see:
Hello from Fable.Python!
Squares: [1; 4; 9; 16; 25]
For development, use watch mode to automatically recompile on changes:
dotnet fable watch --lang pythonNow any changes to your F# files will instantly produce updated Python output.
After setup, your project looks like this:
my-fable-python/
├── Program.fs # Your F# source code
├── Program.py # Generated Python (don't edit!)
├── my-fable-python.fsproj
├── fable_modules/ # Fable runtime modules
└── .config/
└── dotnet-tools.json
Now that you have a working setup, let's explore how to interact with Python libraries in the next chapter on Bindings.